graph_filters#
Graph filters for ClearMap
# make some atomic filters artery = GraphFilter(g, ‘vertex’, ‘is_artery’, True) small = GraphFilter(g, ‘vertex’, ‘radius’, (0, 4)) vein = GraphFilter(g, ‘vertex’, ‘is_vein’, True) some_edge_prop_filter = GraphFilter(g, ‘edge’, ‘some_edge_prop’, True)
# Boolean equation: (artery & small) | ~(vein) cap_network = (artery & small) | ~vein & some_edge_prop_filter
mask = cap_network.as_mask(‘vertex’) # one property read per leaf; single traversal
- class CombinedFilter(left, right, op)[source]#
Bases:
BaseFilter
- class GraphFilter(graph, filter_type='', property_name='', property_value=None)[source]#
Bases:
BaseFilterA class to filter vertices or edges of a graph based on a property. The filter can be combined with other filters or masks using logical operators to chain multiple filters together.
If combining with a mask, the filter type is ignored. However, masks must be of the same size (which implies the same graph and the same type). If combined with another filter object, the right filter will be cast to the type (vertex/edge) of the left operand when combined with another filter.
You can combine filters using the following operators (think of them as set operations): - & (and): Intersection of two filters - | (or): Union of two filters - + (or): Union of two filters (same as |)
- combine_with(other, operator)[source]#
Combine this filter with another filter or a mask using the specified operator. If combined with a mask, return a mask. If combined with another filter, return a CombinedGraphFilter object.
- Parameters:
other (GraphFilter or np.ndarray) – The other filter or mask to combine with.
operator (str or callable) – The operator to use for combining the filters or masks. Can be ‘and’ or ‘or’. If a callable is provided, it should take two boolean arrays and return a boolean array.
Returns
- np.ndarray or CombinedGraphFilter
If combined with a mask, returns a boolean mask. If combined with another filter returns a CombinedGraphFilter object.