mapmaker.utils.graph module

mapmaker.utils.graph.smooth_edges(G: Graph, end_nodes: list | set | None = None, edge_nodes_attribute: str = 'edge-nodes') MultiDiGraph[source]

Return a networkx.MultiGraph copy of G with all degree 2 nodes removed.

Each edge of the resulting graph has an OrderedDict attribute, whose name is given by edge_nodes_attribute, containing nodes and their attributes for all nodes removed from the original edge.

mapmaker.utils.graph.get_connected_subgraph(G, nodes)[source]

Find the subgraph G’ induced on G, that 1) contain all nodes in a set of nodes V’, and 2) is a connected component.

See: https://stackoverflow.com/questions/58076592/python-networkx-connect-subgraph-with-a-loose-node

Given a graph G=(V,E), and a vertex set V’, find the V’’, that 1) is a superset of V’, and 2) when used to induce a subgraph on G forms a connected component.

Arguments:

Gnetworkx.Graph object

The full graph.

nodesiterable

The chosen vertex set.

Returns:

G_primenetworkx.Graph object

The subgraph of G fullfilling criteria 1) and 2).

mapmaker.utils.graph.connected_paths(G: Graph) dict[tuple[str, str], Any][source]