vasc_graph_utils#

combine_arteries_and_veins(graph, artery=None, vein=None, mode='arteryvein', min_radius=None)[source]#

Combine the arteries and veins in the graph into a single property

Parameters:
  • graph (Graph) – The graph to combine the arteries and veins of

  • artery (np.array or None) – The artery property of the graph. If None, will be extracted from the graph

  • vein (np.array or None) – The vein property of the graph. If None, will be extracted from the graph

  • mode (str) –

    The mode to use for combining the arteries and veins. Can be one of:
    • ’arteryvein’: simply combine (OR) the artery and vein properties

    • ’bigvessels’: combine the artery and vein properties and add the vessels with a radius above min_radius

  • min_radius (float or None) – The minimum radius to use for the ‘bigvessels’ mode. This is required if mode is ‘bigvessels’.

Returns

The combined artery_vein property (as a numpy array)

edge_to_vertex_property(graph, edge_property, dtype=None)[source]#

Converts graph_property from edge to vertex property

Warning

This function only works for binary properties

Parameters:
  • graph (Graph) – The graph to convert the property from

  • edge_property (str or np.array) – The name of the edge property to convert or the edge property itself

Returns

The vertex property (as a numpy array)

extract_annotated_region(graph, region)[source]#
filter_graph_degrees(graph, min_degree=2, max_degree=4)[source]#

Filter the graph to keep only the edges with a degree between min_degree and max_degree (boundaries are included)

Parameters:
  • graph

  • min_degree (int) – The minimum degree to keep

  • max_degree (int) – The maximum degree to keep

Returns

The filtered graph

get_edges_n_kinds(graph)[source]#

Get the n_kind property (i.e. the integer value representing the type of vessel) for each edge in the graph

Parameters:

graph (Graph) – The graph to get the n_kind property of

Returns

n_kindnp.array

The n_kind property for each edge in the graph

get_sub_graph(graph, region_list)[source]#
get_vertex_coordinates(graph, coordinates_name)[source]#

Get the coordinates from the graph in any space. The coordinates can be in any space, as long as it is a vertex property of the graph. Examples of coordinates spaces are ‘coordinates’, ‘coordinates_atlas’, ‘coordinates_scaled’, ‘coordinates_MRI’ :param graph: The graph to get the coordinates from :type graph: GraphGt.Graph :param coordinates_name: The name of the coordinates space to use. Typically, ‘coordinates’ or ‘coordinates_atlas’ :type coordinates_name: str

Returns

get_vertices_n_kinds(graph)[source]#

Get the n_kind property (i.e. the integer value representing the type of vessel) for each vertex in the graph

Parameters:

graph (Graph) – The graph to get the n_kind property of

Returns

n_kindnp.array

The n_kind property for each vertex in the graph

get_vessel_length(coordinates)[source]#

Get the length of a single vessel from its coordinates

Parameters:

coordinates (ndarray) – The coordinates of the (single) vessel in the format (n_points, 3)

Returns

graph_gt_to_igraph(src_graph)[source]#

Convert graph from GraphGt to igraph format

Warning

This only transfers the properties ‘radius’, ‘diameter’ and ‘nkind’. nkind is the integer value representing the type of vessel (see the n_kinds dictionary for the possible values)

Parameters:

src_graph (GraphGt) – The graph to convert (in GraphGt format)

Returns

The converted graph (in igraph format)

modularity_measure(graph, modules)[source]#

Measure of modularity of a subgraph

Parameters:
  • modules

  • graph

Returns

parallel_get_vessels_lengths(graph, edge_coordinates_name='coordinates', clip_below_unity=True, min_chunk_size=5, n_processes=1)[source]#

Computes the length of each vessel in the graph in parallel. Using the geometry, we extract the coordinates of each vessel and compute the length from that. This is parallelized because pure numpy is impossible because the vessels have different lengths.

Parameters:
  • graph (Graph) – The graph to compute the lengths of

  • edge_coordinates_name (str) – The name of the property containing the coordinates of the vessels. Typically, ‘coordinates’ or ‘coordinates_atlas’

  • clip_below_unity (bool) – If True, clips the length below 1 to 1

  • min_chunk_size (int) – The minimum chunk size to use for parallel processing

  • n_processes (int) – The number of processes to use for the computation

Returns

An array of the lengths of the vessels in the graph

remove_surface(graph, depth)[source]#

Removes the vessels that are within a certain distance from the surface of the brain The filter is done on the ‘distance_to_surface’ property of the vertices. Hence, the depth should be given in the same unit as the property.

Parameters:
  • graph (Graph) – The graph to filter

  • depth (float) – The depth from the surface to remove

Returns

set_artery_vein_if_missing(graph, artery_min_radius=4, vein_min_radius=8)[source]#

Sets the vertex properties for artery and vein if they are missing.

vertex_filter_to_edge_filter(graph, vertex_filter, operator=<ufunc 'logical_and'>)[source]#

Converts a vertex filter to an edge filter

Warning

The operator is essential. Should both vertices follow the filter or either one.

Parameters:
  • graph (Graph) – The graph to convert the filter for

  • vertex_filter (np.array) – The vertex filter to convert

Returns

The edge filter (as a numpy array)

vertex_to_edge_property(graph, graph_property)[source]#

Converts graph_property from vertex to edge property

Warning

This function only works for binary properties

Parameters:
  • graph (Graph) – The graph to convert the property from

  • graph_property (str or np.array) – The name of the vertex property to convert or the vertex property itself

Returns

The edge property (as a numpy array)