astrovascpy.utils

Functions

comm()

returns:

The MPI communicator (mpi4py.MPI.Comm)

convert_from_networkx(nx_graph)

Convert a networkx graph to a vasculature graph.

convert_to_networkx(graph)

Convert a vasculatureAPI graph to a networkx graph (mostly for plotting purposes).

convert_to_temporal(data, frequencies, times)

Convert spectral data to temporal data.

create_box(graph)

Create a box to compute metrics inside.

create_entry_largest_nodes(graph, params)

Get the largest nodes of degree 1 for input in the largest connected components.

create_input_speed(T, step[, A, f, C, ...])

Creates an input speed v(t) according to the model:

ensure_ids(a)

Convert a numpy array dtype into IDS_DTYPE.

ensure_list(v)

Convert iterable / wrap scalar into list (strings are considered scalar).

find_degrees_of_neighbors(graph, node_id)

Given an edge described by node_id, find the neighbors edges.

find_neighbors(graph, section_id, segment_id)

Given an edge described by section_id and segment_id, find the neighbors edges.

fit_sine_model(signal[, window])

Helper function for fitting a sine signal.

get_large_nodes(graph[, min_radius, ...])

Get degree 1 nodes that are larger than min_radius.

get_largest_nodes(graph[, n_nodes, ...])

Get largest nodes of degree 1 for input in the largest connected components.

get_local_neighboors(graph, iterations, ...)

Get local neighbours.

get_subset(graph[, iterations, ...])

Get subset of graph as connected component from a starting node, using random walk.

is_iterable(v)

Check if v is any iterable (strings are considered scalar and CircuitNode/EdgeId also).

mpi()

returns:

The mpi4py.MPI module

rank()

returns:

MPI rank of the current process (int)

rank0()

returns:

True if the current process has MPI rank 0, False otherwise

reduce_graph(graph, to_keep_labels)

Return a subgraph with to_keep_labels.

reduce_to_largest_cc(graph)

Return a new graph with only the largest CC.

size()

returns:

The size of the MPI communicator (int)

Classes

Graph(*args, **kwargs)

Wrapper on top of a vascpy.PointVasculator providing additional graph-related capabilities

mpi_mem()

A simple mpi memory profiler class

mpi_timer()

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:

Graph

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

Parameters:
  • T (float) – simulation time

  • step (float) – time step size

  • A (float) – sine amplitude.

  • f (float) – sine frequency.

  • C (float) – offset.

  • read_from_file (path) – path to the data file to read.

Returns:

vector of speed for any time point.

Return type:

numpy.array

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:
  • graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.

  • section_id (int) – id of the corresponding section.

  • segment_id (int) – id of the corresponding segment.

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

Parameters:
  • signal (numpy.array) – sinusoidal signal.

  • window (float) – window for smoothing the signal

Returns:

sine amplitude. f (float): sine frequency. C (float): offset.

Return type:

A (float)

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.

Parameters:
  • graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.

  • iterations (int) – number of iterations.

  • starting_nodes_id (int) – start node id.

Returns:

get local neighbourg of selected nodes ids.

Return type:

numpy.array

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.

Parameters:
  • graph (vasculatureAPI.PointVasculature) – graph containing point vasculature skeleton.

  • iterations (int) – number of iterations.

  • starting_nodes_id (int) – start node id.

Returns:

reduced to the largest cc point graph.

Return type:

Graph

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

class astrovascpy.utils.mpi_mem

Bases: object

A simple mpi memory profiler class

class astrovascpy.utils.mpi_timer

Bases: object

A simple mpi timer class

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)