general_functions#
- avg_streamlines_grid(work_dir, reference_samples, mode='bigvessels', group_name='controls')[source]#
- compute_blood_flow(graph, work_dir, sample_name)[source]#
Return the graph with the flow, velocity and pressure properties added If this has not been computed before, it will be computed and saved to the sample dict
- Parameters:
graph (GraphGt.Graph) – The graph to compute the flow, velocity and pressure from
work_dir (str) – The path to the work directory
sample_name (str) – The name of the sample (used in the file name)
Returns
- graphGraphGt.Graph
The graph with the flow, velocity and pressure properties added
- compute_flow_f_schmid(work_dir, graph, cont, graph_name='correcteduniverse', dest_base_name='same')[source]#
Compute the flow and velocity of the graph using the method published in Schmid F. et al. https://doi.org/10.1371/journal.pcbi.1005392
First, make an igraph version of the graph with the necassary properties Then add: - length (computed from the geometry of the edges) - boundary_cap (True if edge is a boundary capillary) - nkind (node kind, i.e. integer representing the type of node from (0, 1, 2, 3) for (capillaries, arteries, veins, universe) - pBC (pressure boundary conditions)
- Parameters:
work_dir (str) – The path to the work directory
graph (GraphGt.Graph) – The graph to compute the flow and velocity from
cont (str) – The name of the control group
graph_name (str) – The name of the graph file
dest_base_name (str) – The base name of the destination file. If ‘same’, the name will be the same as the graph name
Returns
flow, velocity, pressure : ndarray, ndarray, ndarray
- coordinates_to_edge_vectors(vertex_coordinates, connectivity, normalized=False)[source]#
Get the edge vectors from the coordinates and connectivity. The vectors are computed as the difference between the coordinates of the vertices of the edge.
Warning
If normalized is True, the vectors will be normalized to unit length. If a normalized vector is 0, it will be replaced by a vector of 0s.
- Parameters:
vertex_coordinates (ndarray) – The coordinates of the vertices
connectivity (ndarray) – The connectivity of the graph.
normalized (bool) – Whether to normalize the vectors to unit length or not
Returns
- edge_vectorsndarray
The vectors of the edges
- generalized_radial_planar_orientation(graph, work_dir, min_radius, reference_samples, corrected=True, distance_to_surface=True, mode='arteryvein', average=False, dvlpmt=True, min_dist_to_surface=7, coordinates_name='coordinates', orientation_criterion='distance')[source]#
Use Flow interpolation to compute the orientation of the vessels in the graph. This is based on the local orientation of the arteries
- Parameters:
graph
work_dir
min_radius
reference_samples
corrected
distance_to_surface
mode
average
dvlpmt
min_dist_to_surface
coordinates_name
orientation_criterion
Returns
- get_artery_vein_edge_coords_and_vectors(graph, mode, artery, vein, min_radius, label=None, clean_graph=True, distance_to_surface=None, min_dist_to_surface=2, invert=False, coordinates_name='coordinates', orientation_criterion='distance', return_filter=False)[source]#
- get_edge_vectors(graph, normed=False, orientation_criterion='distance', coordinates_name='coordinates')[source]#
Get the edge vectors and sorted connectivity from the graph. The edges can be oriented based on the criterion so that the vectors will follow this orientation. If no criterion is given (‘’), the edges will not be oriented.
- Parameters:
graph (GraphGt.Graph) – The graph to get the edge vectors from
normed (bool) – Whether to normalize the vectors to unit length or not
orientation_criterion (str) – The criterion to use to orient the edges. Can be either ‘pressure’, ‘distance_to_surface’ or ‘’ (no sorting)
coordinates_name (str) – The coordinates space to use. Typically, ‘coordinates’, ‘coordinates_atlas’, ‘coordinates_scaled’ or ‘coordinates_MRI’
Returns
- get_edge_vectors_spherical(graph, x, y, center, orientation_criterion='distance', normed=False)[source]#
- get_nb_parallel_vessels(edge_color, verbose=True, parallel_threshold=0.7)[source]#
Get the number of parallel vessels from the edge color
- Parameters:
edge_color (ndarray)
parallel_threshold (float) – Threshold to filter out vessels that are not sufficiently parallel to the plane. The default value is 0.7, which means that the vessel must be at least 70% parallel to the plane to be counted as parallel. This is a good empirical value, but it may need to be adjusted for different applications.
verbose (bool) – Whether to print the shape of the array
Returns
- nb_parallelint
The number of parallel vessels
- get_nb_radial_vessels(edge_color, radiality_threshold=0.7)[source]#
Get the number of radial vessels from the edge color
- Parameters:
edge_color (ndarray)
radiality_threshold (float) – Threshold to filter out vessels that are not sufficiently radial to the plane. The default value is 0.7, which means that the vessel must be at least 70% radial to the plane to be counted as radial. This is a good empirical value, but it may need to be adjusted for different applications.
Returns
- nb_radialint
The number of radial vessels
- get_orientation_from_normal_to_surface_global(graph, ref_graph, normal_vector_method='mean', coordinates_name='coordinates')[source]#
Get the orientation of the graph relative to the surface normal.
- Parameters:
graph (GraphGt.Graph) – The graph to get the orientation from
ref_graph
normal_vector_method (str) – The method to use to compute the normal vector to the plane best fitting the vertices. Can be either ‘svd’ or ‘mean’.
coordinates_name (str) –
- The coordinates space to use. Typically, ‘coordinates’, ‘coordinates_atlas’,
’coordinates_scaled’ or ‘coordinates_MRI’
Returns
- get_orientation_from_normal_to_surface_local(graph, region_ids, normal_vector_method='mean', coordinates_name='coordinates')[source]#
Orientation in the cortex relative to the surface normal. (i.e. we fit a plane to the top vertices and the bottom vertices and take the normal to this plane as the top-to-bottom direction). Alternatively, we can use the average method which takes the mean of the top and bottom vertices.
- Parameters:
graph (GraphGt.Graph) – The graph to get the orientation from
region_ids (list) – The list of the ids of the regions to consider.
normal_vector_method (str) – Determines the way to compute the normal vector to the plane best fitting the vertices. Can be either ‘svd’ or ‘mean’. If set to svd, we use Singular Value Decomposition (SVD) to find the normal vector to the plane best fitting the top vertices. If set to mea, we take the average of the top and bottom vertices.
coordinates_name (str) –
- The coordinates space to use. Typically, ‘coordinates’, ‘coordinates_atlas’,
’coordinates_scaled’ or ‘coordinates_MRI’
Returns
radial_orientations, planar_orientations, reference_norms, edge_lengths (all ndarrays)
- get_top_to_bottom_dist(graph, normal_vector_method='svd', coordinates_name='coordinates')[source]#
Get the top to bottom distance of the graph. This can be computed using the minimum distance method or by taking the mean of the top and bottom vertices.
- Parameters:
graph (GraphGt.Graph) – The graph to get the top to bottom distance from
normal_vector_method (str) –
The method to use to compute the top to bottom distance. Can be either ‘svd’ or ‘mean’. If set to ‘svd’, we identify the vertices in the graph that are closer to the surface than a certain threshold (min_dist, which is the minimum distance to the surface plus 1.5). We then calculate the centroid of these vertices and uses Singular Value Decomposition (SVD) to find the normal vector to the plane best fitting these vertices. This normal vector is considered as the top-to-bottom direction.
If set to ‘mean’, the function computes the top-to-bottom distance by taking the mean of the coordinates of the top and bottom vertices in the graph. The top vertices are those with a distance to the surface less than or equal to the minimum distance plus 1, and the bottom vertices are those with a distance to the surface greater than or equal to the maximum distance minus 1. The top-to-bottom direction is then the normalized vector from the mean of the top vertices to the mean of the bottom vertices.
coordinates_name (str) – The coordinates space to use. Typically, ‘coordinates’, ‘coordinates_atlas’, ‘coordinates_scaled’ or ‘coordinates_MRI’
Returns
- graph_to_edge_coords_and_vectors(graph, coordinates_name='coordinates', orientation_criterion='distance')[source]#
Get the coordinates and vectors of the edges of the graph. The edges can be oriented based on the criterion so that the vectors will follow this orientation.
- Parameters:
graph (GraphGt.Graph) – The graph to get the edge coordinates and vectors from
coordinates_name (str) – The coordinates space to use. Typically, ‘coordinates’ or ‘coordinates_atlas’ IT should be an existing vertex property of the graph (that represents the coordinates of the vertices in some space)
orientation_criterion (str) – The criterion to use to orient the edges. Can be either ‘pressure’, ‘distance_to_surface’ or ‘’ (no sorting)
Returns
- load_graph(work_dir, group_name)[source]#
Loads the graph from the given work directory and control. Tries to load the default corrected graph, if it does not exist, tries to load the default graph.
- sort_connectivity_based_on_vertex_property(graph, orientation_criterion, reversed=False)[source]#
For each edge, sort the vertices based on the criterion. i.e. get the edges direction based on the criterion, which can be either ‘pressure’, ‘distance_to_surface’ or ‘’ (no sorting)
- Parameters:
graph
orientation_criterion (str) – The criterion to use to sort the edges. Can be either ‘pressure’, ‘distance_to_surface’ or ‘’ (no sorting)
Returns
- structure_specific_radius_filter(graph, artery_vein, label=None, specific_structures=((1006, 3), (463, 6)))[source]#
This function reworks the graph so that the radius criterion is applied differently depending on the structure (here, cerebellum and hippocampus)
- Parameters:
graph
artery_vein
label
specific_structures
Returns