Skip to content

Commit

Permalink
add parameter fuse_bus_column to merge_internal_net_and_equivalent_ex…
Browse files Browse the repository at this point in the history
…ternal_net()
  • Loading branch information
SteffenMeinecke committed Nov 6, 2023
1 parent 3544151 commit 652004a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
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
- [ADDED] matplotlib v3.8.0 support (fixed :code:`plotting_colormaps.ipynb`)
- [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()
- [FIXED] :code:`convert_format.py`: update the attributes of the characteristic objects to match the new characteristic


Expand Down
27 changes: 15 additions & 12 deletions pandapower/grid_equivalents/get_equivalent.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@ def get_equivalent(net, eq_type, boundary_buses, internal_buses,


def merge_internal_net_and_equivalent_external_net(
net_eq, net_internal, eq_type, show_computing_time=False,
calc_volt_angles=False, **kwargs):
net_eq, net_internal, fuse_bus_column="auto", show_computing_time=False, **kwargs):
"""
Merges the internal network and the equivalent external network.
It is expected that the boundaries occur in both, equivalent net and
Expand All @@ -340,9 +339,11 @@ def merge_internal_net_and_equivalent_external_net(
**net_internal** - internal area
**eq_type** (str) - equivalent type, such as "rei", "ward" or "xward"
OPTIONAL:
**fuse_bus_column** (str, "auto) - the function expects boundary buses to be in net_eq and
in net_internal. These duplicate buses get fused. To identify these buses, the given column is used. Option "auto" provides backward compatibility which is: use "name_equivalent" if
existing and "name" otherwise
**show_computing_time** (bool, False)
****kwargs** - key word arguments for pp.merge_nets()
Expand All @@ -368,17 +369,19 @@ def merge_internal_net_and_equivalent_external_net(
merged_net = pp.merge_nets(
net_internal, net_eq, validate=kwargs.pop("validate", False),
net2_reindex_log_level=kwargs.pop("net2_reindex_log_level", "debug"), **kwargs)
try:
merged_net.gen.max_p_mw[-len(net_eq.gen.max_p_mw):] = net_eq.gen.max_p_mw.values
merged_net.gen.min_p_mw[-len(net_eq.gen.max_p_mw):] = net_eq.gen.min_p_mw.values
except:
pass

# --- fuse or combine the boundary buses in external and internal nets
busname_col = "name_equivalent" if "name_equivalent" in merged_net.bus.columns.tolist() else "name"
if fuse_bus_column == "auto":
if fuse_bus_column in merged_net.bus.columns:
raise ValueError(
f"{fuse_bus_column=} is ambiguous since the column 'auto' exists in net.bus")
if "name_equivalent" in merged_net.bus.columns:
fuse_bus_column = "name_equivalent"
else:
fuse_bus_column = "name"
for bus in boundary_buses_inclusive_bswitch:
name = merged_net.bus[busname_col].loc[bus]
target_buses = merged_net.bus.index[merged_net.bus[busname_col] == name]
name = merged_net.bus[fuse_bus_column].loc[bus]
target_buses = merged_net.bus.index[merged_net.bus[fuse_bus_column] == name]
if len(target_buses) != 2:
raise ValueError(
"The code expects all boundary buses to occur double. One because "
Expand Down
2 changes: 1 addition & 1 deletion pandapower/toolbox/grid_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def select_subnet(net, buses, include_switch_buses=False, include_results=False,

def merge_nets(net1, net2, validate=True, merge_results=True, tol=1e-9, **kwargs):
"""Function to concatenate two nets into one data structure. The elements keep their indices
unless both nets have the same indices. In that case, net2 elements get reindex. The reindex
unless both nets have the same indices. In that case, net2 elements get reindexed. The reindex
lookup of net2 elements can be retrieved by passing return_net2_reindex_lookup=True.
Parameters
Expand Down

0 comments on commit 652004a

Please sign in to comment.