Apply edge filters
Full example code: examples/graph/graph_filters.py
Properties
Before we can apply filters, we need to define the properties based on which we want to filter out connections. You can get a full overview of possible propert from the __setters__ property.
[
'set_period',
'set_cv_min',
'set_cv_max',
'set_cv_range',
'set_min_edge_length',
'set_max_edge_length',
'set_edge_length_range',
'set_min_delta_lat',
'set_max_delta_lat',
'set_delta_lat_range'
]
We will use these setters to set the maximum allowed edge length, conduction velocity range and period of our data.
Apply filters
To see which filters are present, you can call __filters__ on the Graph class.
Note
Filter tags are case and underscore insensitive. For example cvfilter, CvFilter, CV_filter will all work.
ith our properties set, we can apply filters to remove any edge that doens't meet our requirements. Implicitly we start from all possible edges and remove those we don't want.
If you want to explicitly create all edges first, you can do so by calling the apply_filter() method without any argument.
Syntax
We support 3 different ways of setting properties and applying filters:
- Verbose setter methods
- Chained setter methods
- Dictionary
Or any combinations of the above.
# Verbose methods
graph = Graph(coords, scalars)
graph.set_max_edge_length(1)
graph.set_cv_min(0.02)
graph.set_cv_max(0.04)
graph.set_period(240)
graph.apply_filter('EdgeLengthFilter')
graph.apply_filter('CvFilter')
# Chained methods
graph = (
Graph(coords, scalars)
.set_max_edge_length(1)
.set_cv_min(0.02)
.set_cv_max(0.04)
.set_period(240)
.apply_filter('EdgeLengthFilter')
.apply_filter('CvFilter')
)
# Dictionaries
properties = {
'set_max_edge_length': 1,
'cv_min': 0.02,
'cv_max': 0.04,
'period': 240
}
filters = [
'EdgeLengthFilter',
'CvFilter'
]
graph = Graph(coords, scalars)
graph.set_properties(properties)
graph.apply_filter(filters)
# Or
graph = (
Graph(coords, scalars)
.set_properties(properties)
.apply_filter(filters)
)