graph
The DGM Graph module contains tools for creating graphs that describe the excitation wave propagation in the heart. The DGM Graph is a core part of the DGM toolchain.
This min graph class features:
- A default graph builder which creates connections between all nodes
- Edge weights which are the difference between the source and target scalars (usually delta LAT)
- Filtering of connections based on properties
- Merging graphs
- Calculating various graph measures
Other features:
- A graph class which creates connections based on a voronoi neighborhood
- A graph class which uses correlations and delays as weights
- A class for converting between DGM graphs and networkit graphs
CorrelationGraph
Bases: Graph
Create a graph with delays instead of DelataLAT for weights
correlations
property
delay_cv_max = None
instance-attribute
delay_cv_min = None
instance-attribute
delay_selection = CvDelaySelection
instance-attribute
delay_selections = {'cvdelayselection': CvDelaySelection, 'mindelayselection': MinDelaySelection}
instance-attribute
delays
property
filters = copy.deepcopy(Graph.filters)
class-attribute
instance-attribute
max_correlation = None
instance-attribute
min_correlation = None
instance-attribute
min_peak_distance = None
instance-attribute
sampling_frequency = None
instance-attribute
__init__(coords, scalars, indices=None)
reset_propeties()
set_correlation_range(min_correlation, max_correlation)
set_delay_cv_max(delay_cv_max)
set_delay_cv_min(delay_cv_min)
set_delay_cv_range(delay_cv_min, delay_cv_max)
set_delay_selection(selection)
Sets the delay selection parameter. A delay selector selects a single delay and correlation value for each edge based on the value of said delay.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
selection
|
Type[DelaySelector] | DelaySelector | str
|
a selector class |
required |
Returns:
Type | Description |
---|---|
Self
|
self |
set_max_correlation(max_correlation)
set_min_correlation(min_correlation)
set_min_peak_distance(min_peak_distance)
set_sampling_frequency(sampling_frequency)
Graph
Bases: PropertyMixin
A class representing a DGM graph.
A graph consists of two main attributes:
- nodes: a node in the graph consists of coordinates and a scalar value
- edges: the edges of a node define the connections between nodes.
adjacency_matrix = None
instance-attribute
coords
property
cv_max = None
instance-attribute
cv_min = None
instance-attribute
degree = None
instance-attribute
degree_diff = None
instance-attribute
edges = None
instance-attribute
filters = {}
class-attribute
instance-attribute
in_degree = None
instance-attribute
max_delta_lat = None
instance-attribute
max_edge_length = None
instance-attribute
maximal_clique_sizes = None
instance-attribute
min_delta_lat = None
instance-attribute
min_edge_length = None
instance-attribute
nodes = Nodes(coords, scalars, indices)
instance-attribute
nodes_number
property
The number of nodes inside the graph
out_degree = None
instance-attribute
period = None
instance-attribute
scalars
property
sources
property
Sources are the coordinates of the starting points of the edges.
Returns:
Type | Description |
---|---|
ndarray
|
ndarray[N, 3]: Arrays of coordinates for each graph edge start. |
strong_components = None
instance-attribute
targets
property
Targets are the coordinates of the end points of the edges.
Returns:
Type | Description |
---|---|
ndarray
|
ndarray[N, 3]: Arrays of coordinates for each graph edge end. |
vectors
property
Calculate vectors (arrows) based on the directed graph's edges.
Returns:
Type | Description |
---|---|
ndarray
|
ndarray[N, 3]: Arrays of vectors for each graph's edge. |
weak_components = None
instance-attribute
__init__(coords, scalars, indices=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coords
|
ndarray
|
3D coordinates of the nodes. |
required |
scalars
|
ndarray
|
3D (LAT) scalars of the nodes. |
required |
indices
|
ndarray
|
Indices for each node. Defaults to None. |
None
|
add_filter(filter)
classmethod
Manually register a filter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter
|
GraphFilter
|
Filter name. |
required |
add_mask(name, mask)
Add new boolean mask of specific property.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the mask to add. |
required |
mask
|
ndarray[bool]
|
Boolean mask to add. |
required |
apply_filter(*filter_)
Apply filter(s) to the graph. Available filters can be found in Graph.filters
.
You can pass either a single filter, a list of filters or multiple filters passed
as separate arguments. A filter van be a string registered in Graph.filters`,
or a filter class inheriting from GraphFilter. Combining both is also possible.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filter_
|
(str | list[str] | GraphFilter, list[GraphFilter])
|
The filter(s) to apply. |
()
|
Returns:
Type | Description |
---|---|
Self
|
self |
apply_filters(*filter_)
apply_period()
Apply the period of the graph to connect nodes with LAT x and lat x + period with each other.
Returns:
Type | Description |
---|---|
Self
|
self |
get_adjacency_matrix()
Generate and return the adjacency matrix of the graph.
The adjacency matrix is a square 2D NumPy array of shape (nodes_number, nodes_number) that represents the connections between nodes in a graph. Each entry (i, j) in the matrix is a boolean value:
True
indicates there is an edge from nodei
to nodej
.False
indicates no edge exists from nodei
to nodej
.
For example, if there are 3 nodes and edges connecting:
- Node 0 to Node 1
- Node 1 to Node 2
- Node 2 to Node 0
The adjacency matrix would look like this:
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: A 2D boolean NumPy array of shape (nodes_number, nodes_number), representing the adjacency matrix of the graph. |
get_connections_by_nodes(nodes_ids)
Returns the edge indices that connect to the nodes defined by node_ids. You can pass either a single ID or a list of IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes_ids
|
(ndarray[int], int)
|
Node index/indices. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray[int, int]: edge indices |
get_degree()
Calculates the degree of the graph The total degree is, for each node in the graph, the number of directed edges going in and out of that node.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the degree of the graph |
get_degree_diff()
Calculates the degree difference of the graph. i.e. the difference between the in degree and out degree, or the difference between the number of directed edges going in and out of each node
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the degree difference |
get_edges_mask(edges_ids)
get all connections defined by edge_ids You can pass either a single edge or a list of edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges_ids
|
ndarray[int, int]
|
Edge index/indices. |
required |
Returns:
Type | Description |
---|---|
ndarray[bool]
|
np.ndarray[bool]: edge mask |
get_in_degree()
Calculates the in degree of the graph. The in degree is, for each node in the graph, the number of directed edges going into that node.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the in degree of the graph |
get_maximal_clique_sizes()
A graph measure calculating clique sizes of all maximal cliques in a graph. A maximal clique is a subset of vertices in a graph that forms a clique (where every pair of vertices is directly connected) and cannot be extended by including any additional vertices.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the maximal clique sizes |
get_nodes_mask(nodes_ids)
Returns a boolean mask that when applied to the graph's edges would result in only the edges that are connected to the node(s) defined by the given node_ids. You can pass either a single ID or a list of IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes_ids
|
(ndarray[int], int)
|
Node index/indices. |
required |
Returns:
Type | Description |
---|---|
ndarray[bool]
|
np.ndarray[bool]: Boolean mask for the edges |
get_out_degree()
Calculates the out degree of the graph. The out degree is, for each node in the graph, the number of directed edges going into that node.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the out degree of the graph |
get_strong_components()
Calculates the sizes of the strongly connected graph components. A connected component is a subset of a graph's vertices where each pair of vertices is connected by a path; it is called strongly connected if the paths respect edge direction
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the strongly connected components sizes |
get_weak_components()
Calculates the sizes of the weakly connected graph components. A connected component is a subset of a graph's vertices where each pair of vertices is connected by a path; it is called weakly connected if edge direction is ignored.
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: the weakly connected components sizes |
mask_connections_by_edges(edges_ids, mask_name='edge_mask')
Remove all connections defined by edge_ids You can pass either a single edge or a list of edges.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edges_ids
|
(ndarray[int], int)
|
Edge index/indices. |
required |
mask_name
|
str
|
Name of the mask. |
'edge_mask'
|
mask_connections_by_nodes(nodes_ids, mask_name='node_mask')
Remove all connections that connect to the nodes defined by node_ids. You can pass either a single ID or a list of IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nodes_ids
|
(ndarray[int], int)
|
Node index/indices. |
required |
mask_name
|
str
|
Name of the mask. |
'node_mask'
|
merge(graphs, mode='or', compare_scalars=True)
Merge graphs into one graph. If no merging order is set, the merging will be performed in the order of the graphs appearance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graphs
|
list
|
List of graph objects. |
required |
mode
|
str
|
'or' or 'and'. In mode 'or', all edges of both graphs are combined, in mode 'and', only edges that appear in both graphs are kept. |
'or'
|
compare_scalars
|
bool
|
if True, only edges connecting to nodes with the same scalar value in both graphs are merged |
True
|
Returns:
Type | Description |
---|---|
Self
|
self |
remove_mask(name)
Remove a boolean mask by name. A new mask is constructed by taking the bitwise and between all remaining masks
Returns:
Type | Description |
---|---|
Self
|
self |
reset_measures()
Resets the measures of the graph. This can be useful when these have been previously calculated, but after calculation, the graph properties were changed.
Returns:
Type | Description |
---|---|
Self
|
self |
reset_properties()
Reset all graph properties.
Returns:
Type | Description |
---|---|
Self
|
self |
set_cv_max(cv_max)
set_cv_min(cv_min)
set_cv_range(cv_min, cv_max)
set_delta_lat_range(min_delta_lat, max_delta_lat)
set_edge_length_range(min_edge_length, max_edge_length)
set_max_delta_lat(max_delta_lat)
set_max_edge_length(max_edge_length)
set_min_delta_lat(min_delta_lat)
set_min_edge_length(min_edge_length)
set_period(period)
to_df()
NKGraph
Base class for networkit-based graph algorithms.
const_weights = None
instance-attribute
dgm_graph = dgm_graph
instance-attribute
directed = False
instance-attribute
nk_graph = None
instance-attribute
weighted = False
instance-attribute
__init__(dgm_graph)
build()
Build networkit graph based on dgm graph.
set_const_weights(const_weights)
Sets a constant weight for each edge in the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
const_weights
|
number
|
Constant weights. |
required |
set_directed()
Sets if the networkkit graph is directed.
set_number_of_threads(number_of_threads)
Set number of threads used by Networkit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
number_of_threads
|
int
|
Number of threads. |
required |
set_weighted()
Sets if the networkkit graph can have edge weights not equal to 1.
VoronoiGraph
Bases: Graph
triangles = triangles
instance-attribute
vertices = vertices
instance-attribute
__init__(coords, scalars, vertices, triangles, indices=None)
from_surface_poly(coords, scalars, surface_poly, indices=None)
classmethod
Create a VoronoiGraph from a surface polygon.