Skip to content

Commit 02f7fa0

Browse files
committed
Add res_output_3ph for shunt, motor, ward
Signed-off-by: furqan463 <[email protected]>
1 parent 3c4525a commit 02f7fa0

File tree

3 files changed

+73
-13
lines changed

3 files changed

+73
-13
lines changed

src/power_grid_model_io/converters/pandapower_converter.py

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,18 @@ def _create_output_data_3ph(self):
360360
Furthermore, creates a global node lookup table, which stores nodes' voltage magnitude per unit and the voltage
361361
angle in degrees
362362
"""
363-
# TODO create output_data_3ph for remaining components
363+
# TODO create output_data_3ph for trafos3w
364364
# Although Pandapower itself did not implmenet res_shunt_3ph
365365
# Since results are avaiable in PGM output, these should be converted.
366366
self._pp_buses_output_3ph()
367367
self._pp_lines_output_3ph()
368368
self._pp_ext_grids_output_3ph()
369369
self._pp_loads_output_3ph()
370+
self._pp_shunts_output_3ph()
370371
self._pp_trafos_output_3ph()
371372
self._pp_sgens_output_3ph()
373+
self._pp_ward_output_3ph()
374+
self._pp_motor_output_3ph()
372375
self._pp_asym_gens_output_3ph()
373376
self._pp_asym_loads_output_3ph()
374377

@@ -2154,6 +2157,68 @@ def _pp_loads_output_3ph(self):
21542157
pp_component_name="load", load_id_names=load_id_names
21552158
)
21562159

2160+
def _pp_ward_output_3ph(self):
2161+
# TODO: Create Unit tests
2162+
load_id_names = ["ward_const_power_load", "ward_const_impedance_load"]
2163+
if (
2164+
ComponentType.sym_load not in self.pgm_output_data
2165+
or self.pgm_output_data[ComponentType.sym_load].size == 0
2166+
or ("ward", load_id_names[0]) not in self.idx
2167+
):
2168+
return
2169+
2170+
# TODO Find a better way for mapping vm_pu from bus
2171+
# accumulated_loads["vm_pu"] = np.nan
2172+
# Store the results, while assuring that we are not overwriting any data
2173+
assert "res_ward_3ph" not in self.pp_output_data
2174+
self.pp_output_data["res_ward_3ph"] = self._pp_load_result_accumulate(
2175+
pp_component_name="ward", load_id_names=load_id_names
2176+
)
2177+
2178+
def _pp_motor_output_3ph(self):
2179+
# TODO: Create unit tests
2180+
load_id_names = ["motor_load"]
2181+
2182+
assert "res_motor_3ph" not in self.pp_output_data
2183+
2184+
if (
2185+
ComponentType.sym_load not in self.pgm_output_data
2186+
or self.pgm_output_data[ComponentType.sym_load].size == 0
2187+
or ("motor", load_id_names[0]) not in self.idx
2188+
):
2189+
return
2190+
2191+
# Store the results, while assuring that we are not overwriting any data
2192+
assert "res_motor" not in self.pp_output_data
2193+
self.pp_output_data["res_motor_3ph"] = self._pp_load_result_accumulate(
2194+
pp_component_name="motor", load_id_names=load_id_names
2195+
)
2196+
2197+
def _pp_shunts_output_3ph(self):
2198+
"""
2199+
This function converts a power-grid-model Shunt output array to a Shunt Dataframe of PandaPower.
2200+
2201+
Returns:
2202+
a PandaPower Dataframe for the Shunt component
2203+
"""
2204+
# TODO: create unit tests for the function
2205+
assert "res_shunt_3ph" not in self.pp_output_data
2206+
2207+
if ComponentType.shunt not in self.pgm_output_data or self.pgm_output_data[ComponentType.shunt].size == 0:
2208+
return
2209+
2210+
pgm_output_shunts = self.pgm_output_data[ComponentType.shunt]
2211+
2212+
pp_output_shunts = pd.DataFrame(
2213+
columns=["p_mw", "q_mvar", "vm_pu"],
2214+
index=self._get_pp_ids("shunt", pgm_output_shunts["id"]),
2215+
)
2216+
pp_output_shunts["p_mw"] = pgm_output_shunts["p"].sum() * 1e-6
2217+
pp_output_shunts["q_mvar"] = pgm_output_shunts["q"].sum() * 1e-6
2218+
# TODO Find a better way for mapping vm_pu from bus
2219+
# pp_output_shunts["vm_pu"] = np.nan
2220+
self.pp_output_data["res_shunt_3ph"] = pp_output_shunts
2221+
21572222
def _pp_asym_loads_output_3ph(self):
21582223
"""
21592224
This function converts a power-grid-model Asymmetrical Load output array to an Asymmetrical Load Dataframe of

tests/unit/converters/test_pandapower_converter_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_create_output_data_3ph():
5454
PandaPowerConverter._create_output_data_3ph(self=converter) # type: ignore
5555

5656
# Assert
57-
assert len(converter.method_calls) == 8
57+
assert len(converter.method_calls) == 11
5858
converter._pp_buses_output_3ph.assert_called_once_with()
5959
converter._pp_lines_output_3ph.assert_called_once_with()
6060
converter._pp_ext_grids_output_3ph.assert_called_once_with()

tests/validation/converters/test_pandapower_converter_output.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,20 +311,15 @@ def _get_total_powers_3ph(net):
311311
else:
312312
s_motor = complex128()
313313

314-
if "res_ward_3ph" in net:
315-
s_ward = (
316-
net.res_ward_3ph.loc[:, ["p_a_mw", "p_b_mw", "p_c_mw"]].sum().sum()
317-
+ 1j * net.res_ward_3ph.loc[:, ["q_a_mvar", "q_b_mvar", "q_c_mvar"]].sum().sum()
318-
)
314+
if ("res_ward_3ph" in net) and (not net.res_ward_3ph.empty):
315+
s_ward = net.res_ward_3ph.loc[:, "p_mw"].sum() + 1j * net.res_ward_3ph.loc[:, "q_mvar"].sum()
319316
else:
320317
s_ward = complex128()
321318

322-
# TODO: enable res_shunt_3ph when implemented, right now the table exists but columns not defined.
323-
# if "res_shunt_3ph" in net:
324-
# print(net.res_shunt_3ph)
325-
# s_shunt = net.res_shunt_3ph.loc[:, "p_mw"].sum() + 1j * net.res_shunt_3ph.loc[:, "q_mvar"].sum()
326-
# else:
327-
s_shunt = complex128()
319+
if ("res_shunt_3ph" in net) and (not net.res_shunt_3ph.empty):
320+
s_shunt = net.res_shunt_3ph.loc[:, "p_mw"].sum() + 1j * net.res_shunt_3ph.loc[:, "q_mvar"].sum()
321+
else:
322+
s_shunt = complex128()
328323

329324
s_load = s_load_sym + s_load_asym + s_motor + s_ward + s_shunt
330325

0 commit comments

Comments
 (0)