Skip to content

Commit

Permalink
Merge pull request e2nIEE#2439 from SteffenMeinecke/fix/set_line_coor…
Browse files Browse the repository at this point in the history
…ds_from_node_coords

fix lengths missmatch of output if ignore_zero_length is False in plotting utility function coords_from_node_geodata() and rename ignore_zero_length by ignore_no_geo_diff
  • Loading branch information
KS-HTK authored Nov 19, 2024
2 parents b6edd23 + 2867739 commit 7bda012
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Change Log
- [CHANGED] accelerate distributed slack power flow calculation by using sparse-aware operations in _subnetworks()
- [CHANGED] Trafo Controllers can now be added to elements that are out of service, changed self.nothing_to_do()
- [ADDED] Discrete shunt controller for local voltage regulation with shunt steps
- [ADDED] fix lengths missmatch of output if ignore_zero_length is False in plotting utility function coords_from_node_geodata() and rename ignore_zero_length by ignore_no_geo_diff
- [ADDED] cim2pp converter: Using lxml to parse XML files (better performance)

[2.14.7] - 2024-06-14
Expand Down
2 changes: 1 addition & 1 deletion pandapower/plotting/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def create_line_collection(net: pandapowerNet, lines=None,
node_geodata=net.bus.geo,
table_name="line",
node_name="bus",
ignore_zero_length=True)
ignore_no_geo_diff=True)

line_geodata = line_geodata.combine_first(pd.Series(geos, index=line_index_successful))

Expand Down
30 changes: 17 additions & 13 deletions pandapower/plotting/plotting_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def get_index_array(indices, net_table_indices):


def coords_from_node_geodata(element_indices, from_nodes, to_nodes, node_geodata, table_name,
node_name="Bus", ignore_zero_length=True, node_geodata_to=None):
node_name="Bus", ignore_no_geo_diff=True, node_geodata_to=None):
"""
Auxiliary function to get the node coordinates for a number of branches with respective from
and to nodes. The branch elements for which there is no geodata available are not included in
Expand All @@ -162,9 +162,9 @@ def coords_from_node_geodata(element_indices, from_nodes, to_nodes, node_geodata
:type table_name: str
:param node_name: Name of the node type (only for logging)
:type node_name: str, default "Bus"
:param ignore_zero_length: States if branches should be left out, if their length is zero, i.e. \
:param ignore_no_geo_diff: States if branches should be left out, if their length is zero, i.e. \
from_node_coords = to_node_coords
:type ignore_zero_length: bool, default True
:type ignore_no_geo_diff: bool, default True
:param node_geodata_to: Dataframe containing x and y coordinates of the "to" nodes (optional, default node_geodata)
:type node_geodata_to: pd.DataFrame
:return: Return values are:\
Expand Down Expand Up @@ -192,15 +192,19 @@ def coords_from_node_geodata(element_indices, from_nodes, to_nodes, node_geodata
)

node_geodata = node_geodata.apply(_get_coords_from_geojson)
coords = [f'{{"coordinates": [[{x_from}, {y_from}], [{x_to}, {y_to}]], "type": "LineString"}}'
for [x_from, y_from], [x_to, y_to]
in zip(node_geodata.loc[fb_with_geo[not_nan]],
node_geodata.loc[tb_with_geo[not_nan]])
if not ignore_zero_length or (ignore_zero_length and not (x_from == x_to and y_from == y_to))]
return coords, np.array(element_indices)[in_geo & not_nan]


def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False, ignore_zero_length=True):
coords, no_geo_diff = zip(*[
(f'{{"coordinates": [[{x_from}, {y_from}], [{x_to}, {y_to}]], "type": "LineString"}}',
x_from == x_to and y_from == y_to) for [x_from, y_from], [x_to, y_to] in zip(
node_geodata.loc[fb_with_geo[not_nan]], node_geodata.loc[tb_with_geo[not_nan]])])
# if not ignore_no_geo_diff or (ignore_no_geo_diff and not ())]
coords, no_geo_diff = np.array(coords), np.array(no_geo_diff)
if ignore_no_geo_diff:
return coords, np.array(element_indices)[in_geo & not_nan]
else:
return coords[~no_geo_diff], np.array(element_indices)[in_geo & not_nan][~no_geo_diff]


def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False, ignore_no_geo_diff=True):
"""
Sets coordinates in net.line.geo based on the from_bus and to_bus coordinates
in net.bus.geo
Expand All @@ -227,7 +231,7 @@ def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False, ign
node_geodata=net.bus.geo,
table_name="line",
node_name="bus",
ignore_zero_length=ignore_zero_length)
ignore_no_geo_diff=ignore_no_geo_diff)

net.line.loc[line_index_successful, 'geo'] = geos

Expand Down

0 comments on commit 7bda012

Please sign in to comment.