graph
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
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(points, scalars, indices)
instance-attribute
nodes_number: int
property
The number of nodes inside the graph
out_degree = None
instance-attribute
period = None
instance-attribute
points: np.ndarray
property
scalars: np.ndarray
property
sources: np.ndarray
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: np.ndarray
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: np.ndarray
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__(points, scalars, indices=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points |
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:
Trueindicates there is an edge from nodeito nodej.Falseindicates no edge exists from nodeito 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 |