|
15 | 15 | from power_grid_model_io.converters import PandaPowerConverter |
16 | 16 | from power_grid_model_io.converters.pandapower_converter import PandaPowerData |
17 | 17 |
|
18 | | -from ...data.pandapower.pp_validation import pp_net, pp_net_3ph |
| 18 | +from ...data.pandapower.pp_validation import pp_net, pp_net_3ph, pp_net_3ph_minimal_trafo |
19 | 19 | from ..utils import component_attributes_df, load_json_single_dataset |
20 | 20 |
|
21 | 21 | pp = pytest.importorskip("pandapower", reason="pandapower is not installed") |
@@ -51,10 +51,8 @@ def load_and_convert_pgm_data_3ph() -> PandaPowerData: |
51 | 51 | """ |
52 | 52 | Load and convert the power_grid_model results |
53 | 53 | """ |
54 | | - data, extra_info = load_json_single_dataset(PGM_ASYM_OUTPUT_FILE, data_type="asym_output") |
55 | | - # trafo_loading = "power", as validation data is based on power based loading |
| 54 | + data, _ = load_json_single_dataset(PGM_ASYM_OUTPUT_FILE, data_type="asym_output") |
56 | 55 | converter = PandaPowerConverter(trafo_loading="power") |
57 | | - # if pp_input_data is not present in converter, some convert functions may fail. |
58 | 56 | converter.load_input_data(load_validation_data_3ph(), make_extra_info=False) |
59 | 57 | return converter.convert(data=data) |
60 | 58 |
|
@@ -129,6 +127,74 @@ def test_generate_output_3ph(): # TODO: REMOVE THIS FUNCTION |
129 | 127 | json_converter.save(data=output_data_asym, extra_info=extra_info) |
130 | 128 |
|
131 | 129 |
|
| 130 | +def test_output_trafos_3ph__power__with_comparison(): |
| 131 | + import numpy as np |
| 132 | + |
| 133 | + def check_result(net): |
| 134 | + v_hv = net.trafo.vn_hv_kv |
| 135 | + v_lv = net.trafo.vn_lv_kv |
| 136 | + i_max_hv = np.divide(net.trafo.sn_mva, v_hv * np.sqrt(3)) * 1e3 |
| 137 | + i_max_lv = np.divide(net.trafo.sn_mva, v_lv * np.sqrt(3)) * 1e3 |
| 138 | + |
| 139 | + i_a_hv = net.res_trafo_3ph.loc[:, "i_a_hv_ka"] * 1000 |
| 140 | + i_b_hv = net.res_trafo_3ph.loc[:, "i_b_hv_ka"] * 1000 |
| 141 | + i_c_hv = net.res_trafo_3ph.loc[:, "i_c_hv_ka"] * 1000 |
| 142 | + |
| 143 | + i_a_lv = net.res_trafo_3ph.loc[:, "i_a_lv_ka"] * 1000 |
| 144 | + i_b_lv = net.res_trafo_3ph.loc[:, "i_b_lv_ka"] * 1000 |
| 145 | + i_c_lv = net.res_trafo_3ph.loc[:, "i_c_lv_ka"] * 1000 |
| 146 | + |
| 147 | + np.testing.assert_allclose( |
| 148 | + np.maximum(i_a_hv / i_max_hv, i_a_lv / i_max_lv) * 100, net.res_trafo_3ph.loading_a_percent |
| 149 | + ) |
| 150 | + np.testing.assert_allclose( |
| 151 | + np.maximum(i_b_hv / i_max_hv, i_b_lv / i_max_lv) * 100, net.res_trafo_3ph.loading_b_percent |
| 152 | + ) |
| 153 | + np.testing.assert_allclose( |
| 154 | + np.maximum(i_c_hv / i_max_hv, i_c_lv / i_max_lv) * 100, net.res_trafo_3ph.loading_c_percent |
| 155 | + ) |
| 156 | + |
| 157 | + def compare_result(actual, expected, *, rtol): |
| 158 | + np.testing.assert_allclose(actual.trafo.vn_hv_kv, expected.trafo.vn_hv_kv, rtol=rtol) |
| 159 | + np.testing.assert_allclose(actual.trafo.vn_lv_kv, expected.trafo.vn_lv_kv, rtol=rtol) |
| 160 | + np.testing.assert_allclose(actual.trafo.sn_mva, expected.trafo.sn_mva, rtol=rtol) |
| 161 | + np.testing.assert_allclose( |
| 162 | + actual.res_trafo_3ph.loc[:, "i_a_hv_ka"], expected.res_trafo_3ph.loc[:, "i_a_hv_ka"], rtol=rtol |
| 163 | + ) |
| 164 | + np.testing.assert_allclose( |
| 165 | + actual.res_trafo_3ph.loc[:, "i_b_hv_ka"], expected.res_trafo_3ph.loc[:, "i_b_hv_ka"], rtol=rtol |
| 166 | + ) |
| 167 | + np.testing.assert_allclose( |
| 168 | + actual.res_trafo_3ph.loc[:, "i_c_hv_ka"], expected.res_trafo_3ph.loc[:, "i_c_hv_ka"], rtol=rtol |
| 169 | + ) |
| 170 | + np.testing.assert_allclose( |
| 171 | + actual.res_trafo_3ph.loc[:, "i_a_lv_ka"], expected.res_trafo_3ph.loc[:, "i_a_lv_ka"], rtol=rtol |
| 172 | + ) |
| 173 | + np.testing.assert_allclose( |
| 174 | + actual.res_trafo_3ph.loc[:, "i_b_lv_ka"], expected.res_trafo_3ph.loc[:, "i_b_lv_ka"], rtol=rtol |
| 175 | + ) |
| 176 | + np.testing.assert_allclose( |
| 177 | + actual.res_trafo_3ph.loc[:, "i_c_lv_ka"], expected.res_trafo_3ph.loc[:, "i_c_lv_ka"], rtol=rtol |
| 178 | + ) |
| 179 | + np.testing.assert_allclose( |
| 180 | + actual.res_trafo_3ph.loading_a_percent, expected.res_trafo_3ph.loading_a_percent, rtol=rtol |
| 181 | + ) |
| 182 | + np.testing.assert_allclose( |
| 183 | + actual.res_trafo_3ph.loading_b_percent, expected.res_trafo_3ph.loading_b_percent, rtol=rtol |
| 184 | + ) |
| 185 | + np.testing.assert_allclose( |
| 186 | + actual.res_trafo_3ph.loading_c_percent, expected.res_trafo_3ph.loading_c_percent, rtol=rtol |
| 187 | + ) |
| 188 | + |
| 189 | + pgm_net = pp_net_3ph_minimal_trafo() |
| 190 | + pp_net = pp_net_3ph_minimal_trafo() |
| 191 | + pp.runpp_pgm(pgm_net, symmetric=False) |
| 192 | + pp.runpp_3ph(pp_net) |
| 193 | + check_result(pgm_net) |
| 194 | + check_result(pp_net) |
| 195 | + compare_result(pgm_net, pp_net, rtol=0.04) |
| 196 | + |
| 197 | + |
132 | 198 | def test_output_data(output_data: Tuple[PandaPowerData, PandaPowerData]): |
133 | 199 | """ |
134 | 200 | Unit test to preload the expected and actual data |
@@ -166,6 +232,7 @@ def test_attributes(output_data: Tuple[PandaPowerData, PandaPowerData], componen |
166 | 232 | # Assert |
167 | 233 | pd.testing.assert_series_equal(actual_values, expected_values, atol=5e-4, rtol=1e-4) |
168 | 234 |
|
| 235 | + |
169 | 236 | # The following test only works for those components where valid data is returned by |
170 | 237 | # load_and_convert_pgm_data_3ph. since this is failing for trafo_output_3ph (returning |
171 | 238 | # from first "if", this function's output is not being tested currently. |
|
0 commit comments