Skip to content

Commit 40d3a73

Browse files
committed
resolved test_pandapower_converter_ouput to completely test trafo and switch output, also corrected bugs in pp_trafo_output and pp_switch_output
Signed-off-by: furqan463 <[email protected]>
1 parent 1cecec4 commit 40d3a73

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

src/power_grid_model_io/converters/pandapower_converter.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def _create_pgm_input_lines(self):
425425
pgm_lines["tan1"] = np.divide(
426426
self._get_pp_attr("line", "g_us_per_km", expected_type="f8", default=0),
427427
c_nf_per_km * (2 * np.pi * self.system_frequency * 1e-3),
428-
where=np.not_equal(c_nf_per_km, 0.0),
428+
where= c_nf_per_km != 0.0,
429429
)
430430
pgm_lines["tan1"][np.equal(c_nf_per_km, 0.0)] = 0.0
431431
pgm_lines["i_n"] = (
@@ -439,7 +439,7 @@ def _create_pgm_input_lines(self):
439439
pgm_lines["tan0"] = np.divide(
440440
self._get_pp_attr("line", "g0_us_per_km", expected_type="f8", default=0),
441441
c0_nf_per_km * (2 * np.pi * self.system_frequency * 1e-3),
442-
where=np.not_equal(c0_nf_per_km, 0.0),
442+
where= c0_nf_per_km != 0.0,
443443
)
444444
pgm_lines["tan0"][np.equal(c0_nf_per_km, 0.0)] = 0.0
445445
assert ComponentType.line not in self.pgm_input_data
@@ -1384,7 +1384,8 @@ def _pp_trafos_output(self):
13841384
if self.trafo_loading == "current":
13851385
ui_from = pgm_output_transformers["i_from"] * pgm_input_transformers["u1"]
13861386
ui_to = pgm_output_transformers["i_to"] * pgm_input_transformers["u2"]
1387-
loading = np.maximum(ui_from, ui_to) / pgm_input_transformers["sn"] * loading_multiplier * 1e2
1387+
loading = (np.sqrt(3) * np.maximum(ui_from, ui_to) /
1388+
pgm_input_transformers["sn"]) * loading_multiplier * 1e2
13881389
elif self.trafo_loading == "power":
13891390
loading = pgm_output_transformers["loading"] * loading_multiplier * 1e2
13901391
else:
@@ -1706,15 +1707,18 @@ def join_currents(table: str, bus_name: str, i_name: str) -> pd.DataFrame:
17061707
)
17071708
pp_switches_output = pp_switches_output[["i_ka"]]
17081709
pp_switches_output.set_index(pp_switches_output_index, inplace=True)
1709-
pp_switches_output["loading_percent"] = np.nan
17101710

17111711
# For et=b, ie bus to bus switches, links are created. get result from them
17121712
if not links_absent:
17131713
links = self.pgm_output_data[ComponentType.link]
17141714
# For links, i_from = i_to = i_ka / 1e3
17151715
link_ids = self._get_pp_ids("switch", links["id"], "b2b_switches")
17161716
pp_switches_output.loc[link_ids, "i_ka"] = links["i_from"] * 1e-3
1717-
1717+
in_ka = self.pp_input_data["switch"]["in_ka"].values
1718+
pp_switches_output["loading_percent"] = np.nan
1719+
pp_switches_output["loading_percent"] = np.divide(pp_switches_output["i_ka"],
1720+
in_ka, where= in_ka != 0)
1721+
17181722
assert "res_switch" not in self.pp_output_data
17191723
self.pp_output_data["res_switch"] = pp_switches_output
17201724

tests/data/pandapower/pp_v2_net_output.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2708,7 +2708,7 @@
27082708
"res_switch": {
27092709
"_module": "pandas.core.frame",
27102710
"_class": "DataFrame",
2711-
"_object": "{\"columns\":[\"i_ka\",\"loading_percent\"],\"index\":[101,3021,321],\"data\":[[0.064048243266779,null],[null,null],[0.020545341606839,null]]}",
2711+
"_object": "{\"columns\":[\"i_ka\",\"loading_percent\"],\"index\":[101,3021,321],\"data\":[[0.064048243266779,null],[0.0,null],[0.020545341606839,null]]}",
27122712
"orient": "split",
27132713
"dtype": {
27142714
"i_ka": "float64",

tests/unit/converters/test_pandapower_converter_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ def test_pp_switch_output():
770770
"element": [10, 10, 10, 10, 10, 11, 11, 77, 88],
771771
"et": ["t", "t", "t3", "t3", "t3", "l", "l", "b", "b"],
772772
"closed": [True, True, True, True, True, True, True, True, True],
773+
"in_ka": [np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan],
773774
},
774775
index=[40, 41, 42, 43, 44, 45, 46, 47, 48],
775776
),
@@ -863,7 +864,6 @@ def test_output_line_3ph(converter):
863864
mock_pgm_array.__getitem__.assert_any_call("q_to")
864865
mock_pgm_array.__getitem__.assert_any_call("i_from")
865866
mock_pgm_array.__getitem__.assert_any_call("i_to")
866-
mock_pgm_array.__getitem__.assert_any_call("loading")
867867

868868
# assignment
869869
mock_pp_df.return_value.__setitem__.assert_any_call("p_a_from_mw", ANY)

tests/validation/converters/test_pandapower_converter_output.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ def temporary_file_cleanup(file_path):
3838

3939

4040
@lru_cache
41-
def load_and_convert_pgm_data() -> PandaPowerData:
41+
def load_and_convert_pgm_data(trafo_loading="power") -> PandaPowerData:
4242
"""
4343
Load and convert the power_grid_model results
4444
"""
45-
data, extra_info = load_json_single_dataset(PGM_OUTPUT_FILE, data_type="sym_output")
46-
converter = PandaPowerConverter()
47-
return converter.convert(data=data, extra_info=extra_info)
45+
data, _ = load_json_single_dataset(PGM_OUTPUT_FILE, data_type="sym_output")
46+
converter = PandaPowerConverter(trafo_loading=trafo_loading)
47+
converter.load_input_data(load_validation_data(), make_extra_info=False)
48+
return converter.convert(data=data)
4849

4950

5051
@lru_cache
@@ -77,12 +78,12 @@ def load_validation_data_3ph(trafo_loading="power") -> PandaPowerData:
7778
return pp.file_io.from_json(PP_V2_NET_3PH_OUTPUT_FILE_CURRENT_LOADING)
7879

7980

80-
@pytest.fixture
81-
def output_data() -> Tuple[PandaPowerData, PandaPowerData]:
81+
@pytest.fixture(params = ["power", "current"])
82+
def output_data(request) -> Tuple[PandaPowerData, PandaPowerData]:
8283
"""
8384
Load the pandapower network and the json file, and return the output_data
8485
"""
85-
actual = load_and_convert_pgm_data()
86+
actual = load_and_convert_pgm_data(request.param)
8687
expected = load_validation_data()
8788
return actual, expected
8889

0 commit comments

Comments
 (0)