operations

operations

Functions

Name Description
add_edges Given a list of edge connections, add them to the network
add_nodes Given a list of node coordinates, add them to the network
drop_nodes_from_am Update adjacency matrix after dropping nodes
join Joins two networks together topologically including new connections
split_edges Inserts an new node between each existing node and joins with new edges
trim_edges Removes given edges from a graph or network
trim_nodes Removes given nodes and any connected edges from a graph or network

add_edges

operations.add_edges(network, new_conns)

Given a list of edge connections, add them to the network

Parameters

Name Type Description Default
network dict A dictionary containing the node and edge attributes as ndarrays required
new_conns ndarray The N-by-2 array of connections betwween existing nodes required

Returns

Name Type Description
network dict The network dictionary with the new edges added to the end. Note that any existing edge attributes are also extended and filled with default values specified in settings.default_values.

add_nodes

operations.add_nodes(network, new_coords)

Given a list of node coordinates, add them to the network

Parameters

Name Type Description Default
network dict A dictionary containing the node and edge attributes as ndarrays required
new_coords ndarray The N-by-3 array of coordinates of the new nodes required

Returns

Name Type Description
network dict The network dictionary with the new nodes added to the end. Note that any existing node attributes are also extended and filled with default values specified in settings.default_values

drop_nodes_from_am

operations.drop_nodes_from_am(am, inds)

Update adjacency matrix after dropping nodes

Parameters

Name Type Description Default
am scipy.sparse matrix The adjacency matrix of the network in COO format. required
inds array_like A list of which nodes indices to drop. Can either be integer indices or a boolean mask with True indicating which locations to drop required

Returns

Name Type Description
am ndarray An updated adjacency matrix with nodes and headless edges removed, and node indices updated accordingly
dropped_edges ndarray A boolean array with True values indicating which edges were rendered headless. This can be used to drop invalid edges from other arrays (i.e. array = array[~dropped_edges]).

join

operations.join(g1, g2, L_max=0.99)

Joins two networks together topologically including new connections

Parameters

Name Type Description Default
g1 dictionary A dictionary containing ‘node.coords’ and ‘edge.conns’. required
g2 dictionary A dictionary containing ‘node.coords’ and ‘edge.conns’ required
L_max float The distance between nodes below which they are joined 0.99

Returns

Name Type Description
network dict A new dictionary containing coords and conns from both net1 and net2, plus new connections between the two input networks.

Notes

The returned network will use the same node and edge prefixes as g1

split_edges

operations.split_edges(network)

Inserts an new node between each existing node and joins with new edges

Parameters

Name Type Description Default
network dict The dictionary containing the network connections and coordinates required

Returns

Name Type Description
result tuple A tuple containing new_conns and optionally new_coords if coords was provided. ============== ======================================================== Value Description ============== ======================================================== new_conns A new adjacency matrix in COO format with new nodes added between each original node. If edge 1 connected nodes 1 and 2, then row 1 of the new sparse adjacency matrix will be [1, Nt + 1], and row Nt + 1 will be [Nt + 1, 2]. new_coords A and updated list of node coordinates with the new nodes appended to the end. The coordinates of the new nodes are taken as the average of the two nodes between which they were inserted. ============== ========================================================

trim_edges

operations.trim_edges(network, inds)

Removes given edges from a graph or network

Parameters

Name Type Description Default
network dictionary A dictionary containing coords, conns and other attributes required
inds array_like The edge indices to be trimmed in the form of a 1D list or boolean mask with True values indicating indices to trim. required

Returns

Name Type Description
network dict The dictionary with all edge arrays trimmed accordingly

trim_nodes

operations.trim_nodes(network, inds)

Removes given nodes and any connected edges from a graph or network

Parameters

Name Type Description Default
network dict A dictionary containing coords, conns and other attributes required
inds array_like The node indices to be trimmed in the form of a 1D list or boolean mask with True values indicating indices to trim. required

Returns

Name Type Description
network dict The dictionary with all nodes arrays trimmed accordingly, all edges trimmed that were connected to the trimmed nodes, and the ‘edge.conns’ array renumbered so edges point to the updated node indices.