Skip to content

Commit

Permalink
add limit columns and docs to merge_same_bus_generation_plants()
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffenMeinecke committed Jul 28, 2021
1 parent dc87def commit 7419ad7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
14 changes: 14 additions & 0 deletions pandapower/test/api/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -1359,9 +1359,17 @@ def test_merge_same_bus_generation_plants():

# --- test with case24_ieee_rts
net = nw.case24_ieee_rts()

# manipulate net for different functionality checks
# 1) q_mvar should be summed which is only possible if no gen or ext_grid has the same bus
net.gen.drop(net.gen.index[net.gen.bus == 22], inplace=True)
net.sgen["q_mvar"] = np.arange(net.sgen.shape[0])
# 2) remove limit columns or values to check whether merge_same_bus_generation_plants() can
# handle that
del net.sgen["max_q_mvar"]
net.sgen.min_p_mw.at[1] = np.nan

# prepare expatation values
dupl_buses = [0, 1, 6, 12, 14, 21, 22]
n_plants = sum([net[elm].bus.isin(dupl_buses).sum() for elm in gen_elms])
assert n_plants > len(dupl_buses) # check that in net are plants with same buses
Expand All @@ -1379,6 +1387,12 @@ def test_merge_same_bus_generation_plants():
assert n_plants == expected_no_of_plants
assert np.isclose(net.ext_grid.p_disp_mw.at[0], 95.1*2) # correct value sum (p_disp)
assert np.isclose(net.gen.p_mw.at[0], 10*2 + 76*2) # correct value sum (p_mw)
assert np.isclose(net.gen.min_p_mw.at[0], 16*2 + 15.2) # correct value sum (min_p_mw) (
# 1x 15.2 has been removed above)
assert np.isclose(net.gen.max_p_mw.at[0], 20*2 + 76*2) # correct value sum (max_p_mw)
assert np.isclose(net.gen.min_q_mvar.at[8], -10 - 16*5) # correct value sum (min_q_mvar)
assert np.isclose(net.gen.max_q_mvar.at[8], 16) # correct value sum (max_q_mvar) (
# the sgen max_q_mvar column has been removed above)
idx_sgen22 = net.sgen.index[net.sgen.bus == 22]
assert len(idx_sgen22) == 1
assert np.isclose(net.sgen.q_mvar.at[idx_sgen22[0]], 20 + 21) # correct value sum (q_mvar)
Expand Down
31 changes: 27 additions & 4 deletions pandapower/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -2928,12 +2928,27 @@ def merge_parallel_line(net, idx):
return net


def merge_same_bus_generation_plants(net, gen_elms=["ext_grid", "gen", "sgen"], error=True,
add_info=True):
def merge_same_bus_generation_plants(net, add_info=True, error=True,
gen_elms=["ext_grid", "gen", "sgen"]):
"""
Merge generation plants connected to the same buses so that a maximum of one generation plants
per node remains.
Attention: gen_elms should always be given in order of slack, PV and PQ elements.
ATTENTION:
* gen_elms should always be given in order of slack (1.), PV (2.) and PQ (3.) elements.
INPUT:
**net** - pandapower net
OPTIONAL:
**add_info** (bool, True) - If True, the column 'includes_other_plants' is added to the
elements dataframes. This column informs about which lines are the result of a merge of
generation plants.
**error** (bool, True) - If True, raises an Error, if vm_pu values differ with same buses.
**gen_elms** (list, ["ext_grid", "gen", "sgen"]) - list of elements to be merged by same
buses. Should be in order of slack (1.), PV (2.) and PQ (3.) elements.
"""
if add_info:
for elm in gen_elms:
Expand All @@ -2943,7 +2958,8 @@ def merge_same_bus_generation_plants(net, gen_elms=["ext_grid", "gen", "sgen"],
net[elm]["includes_other_plants"] = False

# --- construct gen_df with all relevant plants data
cols = pd.Index(["bus", "vm_pu", "p_mw", "q_mvar"])
limit_cols = ["min_p_mw", "max_p_mw", "min_q_mvar", "max_q_mvar"]
cols = pd.Index(["bus", "vm_pu", "p_mw", "q_mvar"]+limit_cols)
cols_dict = {elm: cols.intersection(net[elm].columns) for elm in gen_elms}
gen_df = pd.concat([net[elm][cols_dict[elm]] for elm in gen_elms])
gen_df["elm_type"] = np.repeat(gen_elms, [net[elm].shape[0] for elm in gen_elms])
Expand Down Expand Up @@ -2973,6 +2989,13 @@ def merge_same_bus_generation_plants(net, gen_elms=["ext_grid", "gen", "sgen"],
if "q_mvar" in net[uniq_et].columns:
net[uniq_et].at[uniq_idx, "q_mvar"] = gen_df.loc[idxs, "q_mvar"].sum()

# sum limits
for col in limit_cols:
if col in gen_df.columns and not gen_df.loc[idxs, col].isnull().all():
if col not in net[uniq_et].columns:
net[uniq_et][col] = np.nan
net[uniq_et].at[uniq_idx, col] = gen_df.loc[idxs, col].sum()

# drop duplicated elements
for elm in gen_df["elm_type"].loc[idxs[1:]].unique():
dupl_idx_elm = gen_df.loc[gen_df.index.isin(idxs[1:]) &
Expand Down

0 comments on commit 7419ad7

Please sign in to comment.