astrovascpy.utils¶
Functions
|
|
|
Convert a networkx graph to a vasculature graph. |
|
Convert a vasculatureAPI graph to a networkx graph (mostly for plotting purposes). |
|
Convert spectral data to temporal data. |
|
Create a box to compute metrics inside. |
|
Get the largest nodes of degree 1 for input in the largest connected components. |
|
Creates an input speed v(t) according to the model: |
|
Convert a numpy array dtype into IDS_DTYPE. |
|
Convert iterable / wrap scalar into list (strings are considered scalar). |
|
Given an edge described by node_id, find the neighbors edges. |
|
Given an edge described by section_id and segment_id, find the neighbors edges. |
|
Helper function for fitting a sine signal. |
|
Get degree 1 nodes that are larger than min_radius. |
|
Get largest nodes of degree 1 for input in the largest connected components. |
|
Get local neighbours. |
|
Get subset of graph as connected component from a starting node, using random walk. |
|
Check if v is any iterable (strings are considered scalar and CircuitNode/EdgeId also). |
|
|
|
|
|
|
|
Return a subgraph with to_keep_labels. |
|
Return a new graph with only the largest CC. |
|
|
Classes
|
Wrapper on top of a vascpy.PointVasculator providing additional graph-related capabilities |
|
A simple mpi memory profiler class |
A simple mpi timer class |
- class astrovascpy.utils.Graph(*args, **kwargs)¶
Bases:
PointVasculature
Wrapper on top of a vascpy.PointVasculator providing additional graph-related capabilities
Concerns: This class is part of the public API. Any change of signature or functional behavior may be done thoroughly.
- property cc_mask¶
ids (numpy.array) of the main connected component.
Computation is made once, next calls for this property will returned the cached result.
- Type:
Returns
- property degrees¶
degrees (numpy.array) of each node
Computation is made once, next calls for this property will returned the cached result.
- Type:
Returns
- classmethod from_point_vasculature(point_vasculature)¶
Instantiate a Graph from a PointVasculature instance
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
- get_main_connected_component()¶
Build a graph with only the largest Connected Component (CC).
Returns: largest CC point graph (Graph)
- astrovascpy.utils.comm()¶
- Returns:
The MPI communicator (mpi4py.MPI.Comm)
- astrovascpy.utils.convert_from_networkx(nx_graph)¶
Convert a networkx graph to a vasculature graph.
- Parameters:
nx_graph (networkx graph) – input networkx graph
- Returns:
graph containing point vasculature skeleton.
- Return type:
- astrovascpy.utils.convert_to_networkx(graph)¶
Convert a vasculatureAPI graph to a networkx graph (mostly for plotting purposes).
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
- Returns:
it returns a graph.
- Return type:
networkx graph
- astrovascpy.utils.convert_to_temporal(data, frequencies, times)¶
Convert spectral data to temporal data.
- astrovascpy.utils.create_box(graph)¶
Create a box to compute metrics inside.
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
- Returns:
edge index to filter edges.
- Return type:
pandas.Series
- astrovascpy.utils.create_entry_largest_nodes(graph: Graph, params: VasculatureParams)¶
Get the largest nodes of degree 1 for input in the largest connected components.
- Parameters:
graph (Graph) – graph containing point vasculature skeleton.
params (VasculatureParams) – general parameters for vasculature.
- Returns:
(1,) Ids of the largest nodes.
- Return type:
numpy.array
- Raises:
BloodFlowError – if n_nodes <= 0 or if vasc_axis is not 0, 1 or 2.
Concerns: This function is part of the public API. Any change of signature or functional behavior may be done thoroughly.
- astrovascpy.utils.create_input_speed(T, step, A=1, f=1, C=0, read_from_file=None)¶
Creates an input speed v(t) according to the model:
v(t) = A sin( 2 pi f t ) + C
- astrovascpy.utils.ensure_ids(a)¶
Convert a numpy array dtype into IDS_DTYPE.
This function is here due to the https://github.com/numpy/numpy/issues/15084 numpy issue. It is quite unsafe to the use uint64 for the ids due to this problem where : numpy.uint64 + int –> float64 numpy.uint64 += int –> float64
This function needs to be used everywhere node_ids or edge_ids are returned.
- astrovascpy.utils.ensure_list(v)¶
Convert iterable / wrap scalar into list (strings are considered scalar).
- astrovascpy.utils.find_degrees_of_neighbors(graph, node_id)¶
Given an edge described by node_id, find the neighbors edges.
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
node_id (int) – id of the selected node
- Returns:
neighbors_mask to filter edges with 1 node in common with the original edge set: nodes ids of the connected nodes to the node id. numpy.array: list of nodes close to the original node id
- Return type:
pandas.Series
- astrovascpy.utils.find_neighbors(graph, section_id, segment_id)¶
Given an edge described by section_id and segment_id, find the neighbors edges.
- Parameters:
- Returns:
neighbors_mask to filter edges with 1 node in common with the original edge.
- Return type:
pandas.Series
- astrovascpy.utils.fit_sine_model(signal, window=None)¶
Helper function for fitting a sine signal.
Computes the parameters [A,f,C] of the model:
f(t) = A sin( 2 pi f t ) + C
- astrovascpy.utils.get_large_nodes(graph, min_radius=6, depth_ratio=1.0, vasc_axis=1)¶
Get degree 1 nodes that are larger than min_radius.
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
min_radius (float) – minimal radius in µm.
depth_ratio (float) – corresponding to the y-axis (depth of points).
vasculature. (Portion of the)
vasc_axis (int) – axis along which we consider the top/bottom of vasculature.
- Returns:
(ids_largest_nodes,) Ids of the largest nodes. Node ids are sorted according to their diameters.
- Return type:
numpy.array
- Raises:
BloodFlowError – if min_radius <= 0 or if vasc_axis is not 0, 1 or 2.
- astrovascpy.utils.get_largest_nodes(graph, n_nodes=1, depth_ratio=1.0, vasc_axis=1)¶
Get largest nodes of degree 1 for input in the largest connected components.
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
n_nodes (int) – number of nodes to return
depth_ratio (float) – corresponding to the y-axis (depth of points).
vasculature. (Portion of the)
vasc_axis (int) – axis along which we consider the top/bottom of vasculature.
- Returns:
(1,) Ids of the largest nodes.
- Return type:
numpy.array
- Raises:
BloodFlowError – if n_nodes <= 0 or if vasc_axis is not 0, 1 or 2.
- astrovascpy.utils.get_local_neighboors(graph, iterations, starting_nodes_id)¶
Get local neighbours.
- astrovascpy.utils.get_subset(graph, iterations=100, starting_nodes_id=None)¶
Get subset of graph as connected component from a starting node, using random walk.
- astrovascpy.utils.is_iterable(v)¶
Check if v is any iterable (strings are considered scalar and CircuitNode/EdgeId also).
- astrovascpy.utils.mpi()¶
- Returns:
The mpi4py.MPI module
- astrovascpy.utils.rank()¶
- Returns:
MPI rank of the current process (int)
- astrovascpy.utils.rank0()¶
- Returns:
True if the current process has MPI rank 0, False otherwise
- astrovascpy.utils.reduce_graph(graph, to_keep_labels)¶
Return a subgraph with to_keep_labels.
- astrovascpy.utils.reduce_to_largest_cc(graph)¶
Return a new graph with only the largest CC.
- Parameters:
graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.
- Returns:
reduced to the largest cc point graph.
- Return type:
vasculatureAPI.PointVasculature
- astrovascpy.utils.size()¶
- Returns:
The size of the MPI communicator (int)