wntr.metrics.topographic module¶
The wntr.metrics.topographic module contains topographic metrics that are not
available directly with NetworkX. Functions in this module operate on a
NetworkX MultiDiGraph, which can be created by calling G = wn.get_graph()
Contents
Nodes with degree 1 


Bridge links 
Central point dominance 


Spectral gap 
Algebraic connectivity 

Critical ratio of defragmentation 


Valve segmentation 

Valve segment attributes include 1) the number of valves surrounding each valve and (optionally) the increase in segment demand if a given valve is removed and the increase in segment pipe length if a given valve is removed. 
 wntr.metrics.topographic.terminal_nodes(G)[source]¶
Nodes with degree 1
 Parameters
G (networkx MultiDiGraph) – Graph
 Returns
List of terminal nodes
 wntr.metrics.topographic.bridges(G)[source]¶
Bridge links
 Parameters
G (networkx MultiDiGraph) – Graph
 Returns
List of links that are bridges
 wntr.metrics.topographic.central_point_dominance(G)[source]¶
Central point dominance
 Parameters
G (networkx MultiDiGraph) – Graph
 Returns
Central point dominance (float)
 wntr.metrics.topographic.spectral_gap(G)[source]¶
Spectral gap
Difference in the first and second eigenvalue of the adjacency matrix
 Parameters
G (networkx MultiDiGraph) – Graph
 Returns
Spectral gap (float)
 wntr.metrics.topographic.algebraic_connectivity(G)[source]¶
Algebraic connectivity
Second smallest eigenvalue of the normalized Laplacian matrix of a network
 Parameters
G (networkx MultiDiGraph) – Graph
 Returns
Algebraic connectivity (float)
 wntr.metrics.topographic.critical_ratio_defrag(G)[source]¶
Critical ratio of defragmentation
 Parameters
G (networkx MultiDiGraph) – Graph
 Returns
Critical ratio of defragmentation (float)
 wntr.metrics.topographic.valve_segments(G, valve_layer)[source]¶
Valve segmentation
 Parameters
G (networkx MultiDiGraph) – Graph
valve_layer (pandas DataFrame) – Valve layer, defined by node and link pairs (for example, valve 0 is on link A and protects node B). The valve_layer DataFrame is indexed by valve number, with columns named ‘node’ and ‘link’.
 Returns
node_segments (pandas Series) – Segment number for each node, indexed by node name
link_segments (pandas Series) – Segment number for each link, indexed by link name
segment_size (pandas DataFrame) – Number of nodes and links in each segment. The DataFrame is indexed by segment number, with columns named ‘node’ and ‘link’.
 wntr.metrics.topographic.valve_segment_attributes(valve_layer, node_segments, link_segments, demand=None, length=None)[source]¶
Valve segment attributes include 1) the number of valves surrounding each valve and (optionally) the increase in segment demand if a given valve is removed and the increase in segment pipe length if a given valve is removed.
The increase in segment demand is expressed as a fraction of the max segment demand associated with that valve. Likewise, the increase in segment pipe length is expressed as a fraction of the max segment pipe length associated with that valve.
 Parameters
valve_layer (pandas DataFrame) – Valve layer, defined by node and link pairs (for example, valve 0 is on link A and protects node B). The valve_layer DataFrame is indexed by valve number, with columns named ‘node’ and ‘link’.
node_segments (pandas Series) – Segment number for each node, indexed by node name. node_segments can be computed using wntr.metrics.topographic.valve_segments
link_segments (pandas Series) – Segment number for each link, indexed by link name. link_segments can be computed using wntr.metrics.topographic.valve_segments
demands (pandas Series, optional) – Node demand, the average expected node demand can be computed using wntr.metrics.average_expected_demand(wn). Demand from simulation results can also be used.
lengths (pandas Series, optional) – A list of ‘length’ attributes for each link in the network. The output from wn.query_link_attribute(‘length’)
 Returns
pandas DataFrame – Valve segement attributes, indexed by valve number, that contains:
num_surround: number of valves surrounding each valve
demand_increase: increase in segment demand if a given valve is removed, expressed as a fraction
length_increase: increase in segment pipe length if a given valve is removed, expressed as a fraction