oopnet.graph package¶
Submodules¶
oopnet.graph.graph module¶
- class oopnet.graph.graph.DiGraph(network: Network, weight: str | pd.Series = 'length', default: float = 1e-05, switch_direction: bool = True)¶
Bases:
object
Generates a directed NetworkX DiGraph from an OOPNET network.
Note
NetworkX DiGraphs don’t support parallel edges pointing the same direction between two Nodes. Only one of the parallel edges will be present in the Graph object in this case. To allow for parallel pipes, use
oopnet.graph.MultiDiGraph
instead.- Parameters:
network – OOPNET network object
weight – name of pipe property as a string which is used as weight or a pandas Series with link IDs as index and weights as values.
default – When set, the default value is returned as weight for objects that don’t have the defined weight attribute or that are missing in the weight pandas Series. Without it, an exception is raised for those objects.
switch_direction – If a Link’s weight is <0 and switch_direction is True, the Links start and end nodes will be switched.
- Returns:
NetworkX DiGraph object containing all nodes and links in the passed Network.
Examples
The following will create a DiGraph with link lengths as edge weights (filename needs to be a valid EPANET input file): >>> network = Network(filename) >>> g = DiGraph(network, ‘length’) Using a simulation result as link weight: >>> rpt = Run(network) >>> flow = Flow(rpt) >>> g = DiGraph(network, flow)
- class oopnet.graph.graph.Graph(network: Network, weight: str | pd.Series = 'length', default: float = 1e-05, switch_direction: bool = True)¶
Bases:
object
Generates an undirected NetworkX Graph from an OOPNET network.
Note
NetworkX Graphs don’t support parallel edges between two Nodes. Only one of the parallel edges will be present in the Graph object. To allow for parallel pipes, use
oopnet.graph.MultiGraph
instead.- Parameters:
network – OOPNET network object
weight – name of pipe property as a string which is used as weight or a pandas Series with link IDs as index and weights as values.
default – When set, the default value is returned as weight for objects that don’t have the defined weight attribute or that are missing in the weight pandas Series. Without it, an exception is raised for those objects.
switch_direction – If a Link’s weight is <0 and switch_direction is True, the Links start and end nodes will be switched.
- Returns:
NetworkX Graph object containing all nodes and links in the passed Network.
Examples
The following will create a Graph with link lengths as edge weights (filename needs to be a valid EPANET input file): >>> network = Network(filename) >>> g = Graph(network, ‘length’) Using a simulation result as link weight: >>> rpt = Run(network) >>> flow = Flow(rpt) >>> g = Graph(network, flow)
- class oopnet.graph.graph.MultiDiGraph(network: Network, weight: str | pd.Series = 'length', default: float = 1e-05, switch_direction: bool = True)¶
Bases:
object
Generates a directed NetworkX MultiGraph from an OOPNET network.
- Parameters:
network – OOPNET network object
weight – name of pipe property as a string which is used as weight or a pandas Series with link IDs as index and weights as values.
default – When set, the default value is returned as weight for objects that don’t have the defined weight attribute or that are missing in the weight pandas Series. Without it, an exception is raised for those objects.
switch_direction – If a Link’s weight is <0 and switch_direction is True, the Links start and end nodes will be switched.
- Returns:
NetworkX MultiGraph object containing all nodes and links in the passed Network.
Examples
The following will create a MultiGraph with link lengths as edge weights (filename needs to be a valid EPANET input file): >>> network = Network(filename) >>> g = MultiDiGraph(network, ‘length’) Using a simulation result as link weight: >>> rpt = Run(network) >>> flow = Flow(rpt) >>> g = MultiGraph(network, flow)
- class oopnet.graph.graph.MultiGraph(network: Network, weight: str | pd.Series = 'length', default: float = 1e-05, switch_direction: bool = True)¶
Bases:
object
Generates an undirected NetworkX MultiGraph from an OOPNET network.
- Parameters:
network – OOPNET network object
weight – name of pipe property as a string which is used as weight or a pandas Series with link IDs as index and weights as values.
default – When set, the default value is returned as weight for objects that don’t have the defined weight attribute or that are missing in the weight pandas Series. Without it, an exception is raised for those objects.
switch_direction – If a Link’s weight is <0 and switch_direction is True, the Links start and end nodes will be switched.
- Returns:
NetworkX MultiGraph object containing all nodes and links in the passed Network.
Examples
The following will create a MultiGraph with link lengths as edge weights (filename needs to be a valid EPANET input file): >>> network = Network(filename) >>> g = MultiGraph(network, ‘length’) Using a simulation result as link weight: >>> rpt = Run(network) >>> flow = Flow(rpt) >>> g = MultiGraph(network, flow)
- oopnet.graph.graph.edgeresult2pandas(graph, result)¶
Transforms edge data retrieved e.g. from edge centric centrality measurements to a Pandas Series compatible with OOPNET.
- Parameters:
graph (
Graph
) – networkx graph objectresult (
dict
) – dictionary with Link IDs as keys
- Return type:
Series
- Returns:
transformed result into a pandas Series
- oopnet.graph.graph.nxedge2onlink_id(graph, edge)¶
Converts an NetworkX edge in a graph to an OOPNET Link ID.
- Parameters:
graph (
Graph
) – NetworkX graphedge (
tuple
[str
,str
]) – NetworkX edge
- Return type:
Union
[str
,list
[str
]]- Returns:
ID of corresponding OOPNET Link
- oopnet.graph.graph.nxlinks2onlinks(graph)¶
Converts NetworkX graph edges to OOPNET Link IDs.
- Parameters:
graph (
Graph
) – NetworkX graph- Return type:
list
[str
]- Returns:
List of OOPNET Link IDs