Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some fixes around the generation of generic coordinates. #2136

Merged
merged 4 commits into from
Jan 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pandapower/plotting/generic_geodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,29 +142,32 @@ def coords_from_igraph(graph, roots, meshed=False, calculate_meshed=False):
return list(zip(*layout.coords))


def coords_from_nxgraph(mg=None):
def coords_from_nxgraph(mg=None, layout_engine='neato'):
"""
Create a list of generic coordinates from a networkx graph layout.

:param mg: The networkx graph on which the coordinates shall be based
:type mg: networkx.Graph
:param layout_engine: GraphViz Layout Engine for layouting a network. See https://graphviz.org/docs/layouts/
:type layout_engine: str
:return: coords - list of coordinates from the graph layout
"""
# workaround for bug in agraph
for u, v in mg.edges(data=False, keys=False):
for u, v in mg.edges(data=False):
if 'key' in mg[int(u)][int(v)]:
del mg[int(u)][int(v)]['key']
if 'key' in mg[int(u)][int(v)][0]:
del mg[int(u)][int(v)][0]['key']
# ToDo: Insert fallback layout for nxgraph
return list(zip(*(list(nx.drawing.nx_agraph.graphviz_layout(mg, prog='neato').values()))))
return list(zip(*(list(nx.drawing.nx_agraph.graphviz_layout(mg, prog=layout_engine).values()))))


def create_generic_coordinates(net, mg=None, library="igraph",
respect_switches=False,
geodata_table="bus_geodata",
buses=None,
overwrite=False):
overwrite=False,
layout_engine='neato'):
"""
This function will add arbitrary geo-coordinates for all buses based on an analysis of branches
and rings. It will remove out of service buses/lines from the net. The coordinates will be
Expand All @@ -174,6 +177,8 @@ def create_generic_coordinates(net, mg=None, library="igraph",
:type net: pandapowerNet
:param mg: Existing networkx multigraph, if available. Convenience to save computation time.
:type mg: networkx.Graph
:param respect_switches: respect switches in a network for generic coordinates
:type respect_switches: bool
:param library: "igraph" to use igraph package or "networkx" to use networkx package
:type library: str
:param geodata_table: table to write the generic geodatas to
Expand All @@ -182,6 +187,8 @@ def create_generic_coordinates(net, mg=None, library="igraph",
:type buses: list
:param overwrite: overwrite existing geodata
:type overwrite: bool
:param layout_engine: GraphViz Layout Engine for layouting a network. See https://graphviz.org/docs/layouts/
:type layout_engine: str
:return: net - pandapower network with added geo coordinates for the buses

:Example:
Expand All @@ -200,7 +207,7 @@ def create_generic_coordinates(net, mg=None, library="igraph",
include_out_of_service=True)
else:
nxg = copy.deepcopy(mg)
coords = coords_from_nxgraph(nxg)
coords = coords_from_nxgraph(nxg, layout_engine=layout_engine)
else:
raise ValueError("Unknown library %s - chose 'igraph' or 'networkx'" % library)
if len(coords):
Expand Down
Loading