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

fix which repairs set_line_geodata if the net doesn't have geodata fo… #2123

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
a6f42a9
fix which repairs set_line_geodata if the net doesn't have geodata fo…
vogt31337 Sep 4, 2023
ff3fe5b
Merge remote-tracking branch 'pp/develop' into feature/repaired_set_l…
KS-HTK Oct 11, 2023
f13d9bf
added line to CHANGELOG.rst
KS-HTK Oct 11, 2023
75501cc
fixed issue in coords_from_node_geodata.
KS-HTK Oct 12, 2023
a419bf9
Merge pull request #1 from KS-HTK/feature/repaired_set_line_geodata
vogt31337 Oct 12, 2023
d640605
Merge branch 'develop' into feature/repaired_set_line_geodata
SteffenMeinecke Nov 29, 2023
71ce6bf
Merge branch 'develop' into feature/repaired_set_line_geodata
SteffenMeinecke Nov 29, 2023
23d1f86
Merge branch 'develop' into feature/repaired_set_line_geodata
rbolgaryn Mar 26, 2024
3120565
Merge branch 'develop' of https://github.com/e2nIEE/pandapower into f…
SteffenMeinecke Jun 3, 2024
0514ac9
Merge branch 'develop' into feature/repaired_set_line_geodata
KS-HTK Jun 4, 2024
4c86a13
tiny fix
SteffenMeinecke Jun 5, 2024
4bc0358
Merge branch 'develop' of https://github.com/e2nIEE/pandapower into f…
SteffenMeinecke Jun 5, 2024
14b6063
Merge branch 'feature/repaired_set_line_geodata' of https://github.co…
SteffenMeinecke Jun 5, 2024
c2ee5fa
Merge branch 'develop' into feature/repaired_set_line_geodata
SteffenMeinecke Jun 6, 2024
3aafb13
Merge branch 'develop' into feature/repaired_set_line_geodata
SteffenMeinecke Jun 11, 2024
eaacef8
fix missing l in isnull()
SteffenMeinecke Jun 11, 2024
9d3429c
avoid pandas FutureWarnings
SteffenMeinecke Jun 11, 2024
5b7ce75
Merge branch 'develop' into feature/repaired_set_line_geodata
KS-HTK Jun 12, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Change Log
- [FIXED] powerfactory2pandapower-converter error if a line has two identical coordinates
- [ADDED] logger messages about the probabilistic load flow calculation (simultaneities) in the powerfactory2pandapower-converter for low voltage loads
- [ADDED] matplotlib v3.8.0 support (fixed :code:`plotting_colormaps.ipynb`)
- [FIXED] bug in plotting_toolbox.py (fixed :code:`coords_from_node_geodata` and :code:`set_line_geodata_from_bus_geodata`)
- [CHANGED] PowerFactory converter - name :code:`for_name` as :code:`equipment` for all elements; also add to line
- [ADDED] option to use a second tap changer for the trafo element
- [CHANGED] parameters of function merge_internal_net_and_equivalent_external_net()
Expand Down
50 changes: 41 additions & 9 deletions pandapower/plotting/plotting_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,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_name="Bus", ignore_zero_length=True, replace_missing_coords=False):
"""
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 @@ -144,6 +144,7 @@ def coords_from_node_geodata(element_indices, from_nodes, to_nodes, node_geodata
:type node_name: str, default "Bus"
:param ignore_zero_length: States if branches should be left out, if their length is zero, i.e.\
from_node_coords = to_node_coords
:param replace_missing_coords: States when no coords are available, they will be replaced with the geometric mean
:type ignore_zero_length: bool, default True
:return: Return values are:\
- coords (list) - list of branch coordinates of shape (N, (2, 2))\
Expand All @@ -154,18 +155,44 @@ def coords_from_node_geodata(element_indices, from_nodes, to_nodes, node_geodata
& np.isin(to_nodes, node_geodata.index.values)
elements_with_geo = np.array(element_indices)[have_geo]
fb_with_geo, tb_with_geo = from_nodes[have_geo], to_nodes[have_geo]
coords = [[(x_from, y_from), (x_to, y_to)] for x_from, y_from, x_to, y_to
in np.concatenate([node_geodata.loc[fb_with_geo, ["x", "y"]].values,
node_geodata.loc[tb_with_geo, ["x", "y"]].values], axis=1)
if not ignore_zero_length or not (x_from == x_to and y_from == y_to)]
elements_without_geo = set(element_indices) - set(elements_with_geo)

if replace_missing_coords:
a = np.log(node_geodata.loc[fb_with_geo, ["x"]])
b = np.log(node_geodata.loc[fb_with_geo, ["y"]])
replacement_x = np.exp(a.mean()).values[0]
replacement_y = np.exp(b.mean()).values[0]
max_i = max(max(from_nodes), max(to_nodes)) + 1

ng = pd.DataFrame(index=range(max_i), columns=node_geodata.columns)
ng.loc[from_nodes[have_geo]] = node_geodata.loc[from_nodes[have_geo]]
ng.loc[to_nodes[have_geo]] = node_geodata.loc[to_nodes[have_geo]]
ng['x'] = ng['x'].fillna(replacement_x)
ng['y'] = ng['y'].fillna(replacement_y)

fb_with_geo = from_nodes
tb_with_geo = to_nodes

logger.warning("Replacing coords for %s" % (len(elements_without_geo)))
elements_with_geo = np.array(element_indices)
else:
ng = node_geodata

coordinates = np.concatenate([ng.loc[fb_with_geo, ["x", "y"]].values, ng.loc[tb_with_geo, ["x", "y"]].values], axis=1)
zero_length = [(not ignore_zero_length or not (x_from == x_to and y_from == y_to))
for x_from, y_from, x_to, y_to in coordinates]
coordinates = coordinates[zero_length]
coords = [[(x_from, y_from), (x_to, y_to)] for x_from, y_from, x_to, y_to in coordinates]

if len(elements_without_geo) > 0:
logger.warning("No coords found for %s %s. %s geodata is missing for those %s!"
% (table_name + "s", elements_without_geo, node_name, table_name + "s"))
return coords, elements_with_geo
if not all(zero_length):
logger.warning(f"Skipping zero length {table_name}s {elements_with_geo[[not b for b in zero_length]]}.")
return coords, elements_with_geo[zero_length]


def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False):
def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False, replace_missing_coords=False, ignore_zero_length=True):
"""
Sets coordinates in net.line_geodata based on the from_bus and to_bus x,y coordinates
in net.bus_geodata
Expand All @@ -174,18 +201,23 @@ def set_line_geodata_from_bus_geodata(net, line_index=None, overwrite=False):
:param overwrite: whether the existing coordinates in net.line_geodata must be overwritten
:return: None
"""
line_index = line_index if line_index is not None else net.line.index
if not line_index:
line_index = net.line.index
if not overwrite:
line_index = np.setdiff1d(line_index, net.line_geodata.index)

coords, line_index_successful = coords_from_node_geodata(element_indices=line_index,
from_nodes=net.line.loc[line_index, 'from_bus'].values,
to_nodes=net.line.loc[line_index, 'to_bus'].values,
node_geodata=net.bus_geodata,
table_name="line_geodata", node_name="bus_geodata")
table_name="line_geodata",
node_name="bus_geodata",
replace_missing_coords=replace_missing_coords,
ignore_zero_length=ignore_zero_length)

net.line_geodata = net.line_geodata.reindex(net.line.index)
net.line_geodata.loc[line_index_successful, 'coords'] = coords
net.line_geodata.dropna(inplace=True) # drop lines without coords

num_failed = len(line_index) - len(line_index_successful)
if num_failed > 0:
Expand Down
Loading