Skip to content

Commit

Permalink
Merge pull request e2nIEE#1529 from dlohmeier/feature/subnet_selection
Browse files Browse the repository at this point in the history
slight changes to subnet selection (small performance improvement)
  • Loading branch information
SteffenMeinecke authored Apr 1, 2022
2 parents 7bde22a + 995f301 commit d52e1ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
7 changes: 7 additions & 0 deletions pandapower/test/api/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ def test_select_subnet():
assert pp.dataframes_equal(net.line, same_net.line)
assert pp.dataframes_equal(net.load, same_net.load)
assert pp.dataframes_equal(net.ext_grid, same_net.ext_grid)
same_net2 = pp.select_subnet(net, net.bus.index, include_results=True,
keep_everything_else=True)
assert pp.nets_equal(net, same_net2)

# Remove everything
empty = pp.select_subnet(net, set())
Expand All @@ -546,6 +549,10 @@ def test_select_subnet():
line_switch_buses = set(net.switch[net.switch.et == 'l'].bus)
subnet = pp.select_subnet(net, from_bus | to_bus | line_switch_buses)
assert net.switch[net.switch.et == 'l'].index.isin(subnet.switch.index).all()
ls = net.switch.loc[net.switch.et == "l"]
subnet = pp.select_subnet(net, list(ls.bus.values)[::2], include_switch_buses=True)
assert net.switch[net.switch.et == 'l'].index.isin(subnet.switch.index).all()
assert net.switch[net.switch.et == 'l'].bus.isin(subnet.bus.index).all()

# This network has switches of type 'b'
net2 = nw.create_cigre_network_lv()
Expand Down
20 changes: 10 additions & 10 deletions pandapower/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1585,14 +1585,14 @@ def select_subnet(net, buses, include_switch_buses=False, include_results=False,
# we add both buses of a connected line, the one selected is not switch.bus

# for all line switches
for _, s in net["switch"].query("et=='l'").iterrows():
for s in net["switch"].query("et=='l'").itertuples():
# get from/to-bus of the connected line
fb = net["line"]["from_bus"].at[s["element"]]
tb = net["line"]["to_bus"].at[s["element"]]
fb = net["line"]["from_bus"].at[s.element]
tb = net["line"]["to_bus"].at[s.element]
# if one bus of the line is selected and its not the switch-bus, add the other bus
if fb in buses and s["bus"] != fb:
if fb in buses and s.bus != fb:
buses.add(tb)
if tb in buses and s["bus"] != tb:
if tb in buses and s.bus != tb:
buses.add(fb)

if keep_everything_else:
Expand All @@ -1603,12 +1603,12 @@ def select_subnet(net, buses, include_switch_buses=False, include_results=False,
p2 = create_empty_network(add_stdtypes=False)
p2["std_types"] = copy.deepcopy(net["std_types"])

net_parameters = ["name", "f_hz"]
for net_parameter in net_parameters:
if net_parameter in net.keys():
p2[net_parameter] = net[net_parameter]
net_parameters = ["name", "f_hz"]
for net_parameter in net_parameters:
if net_parameter in net.keys():
p2[net_parameter] = net[net_parameter]

p2.bus = net.bus.loc[buses]
p2.bus = net.bus.loc[list(buses)]
for elm in pp_elements(bus=False, bus_elements=True, branch_elements=False,
other_elements=False, res_elements=False):
p2[elm] = net[elm][net[elm].bus.isin(buses)]
Expand Down

0 comments on commit d52e1ae

Please sign in to comment.