Skip to content

Commit

Permalink
bugfix for undefined trafo3w characteristics
Browse files Browse the repository at this point in the history
  • Loading branch information
rbolgaryn committed Jan 18, 2024
1 parent 8a9f98a commit d964a70
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Change Log
- [ADDED] function :code:`outage_results_OTDF` to obtain the matrix of results for all outage scenarios, with rows as outage scenarios and columns as branch power flows in that scenario
- [FIXED] add some safeguards for TDPF to avoid numerical issues in some cases
- [ADDED] the function :code:`run_contingency` can raise a captured error if parameter :code:`raise_errors` is passed
- [FIXED] bugfix for tap dependent impedance characteristics so that not all characteristics columns are necessary

[2.13.1] - 2023-05-12
-------------------------------
Expand Down
3 changes: 2 additions & 1 deletion pandapower/build_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ def _get_vk_values(trafo_df, characteristic, trafotype="2W"):
# must cast to float64 unfortunately, because numpy.vstack casts arrays to object because it doesn't know pandas.NA, np.isnan fails
all_characteristic_idx = np.vstack([get_trafo_values(
trafo_df, f"{c}_characteristic").astype(np.float64) for c in char_columns]).T
index_column = {c: i for i, c in enumerate(char_columns)}
# now we check if any trafos that have tap_dependent_impedance have all of the characteristics missing
all_missing = np.isnan(all_characteristic_idx).all(axis=1) & tap_dependent_impedance
if np.any(all_missing):
Expand All @@ -512,7 +513,7 @@ def _get_vk_values(trafo_df, characteristic, trafotype="2W"):
if use_tap_dependent_impedance and vk_var in char_columns:
vals += (_calc_tap_dependent_value(
trafo_df, tap_pos, vk_value, vk_var, tap_dependent_impedance,
characteristic, all_characteristic_idx[:, c]),)
characteristic, all_characteristic_idx[:, index_column[vk_var]]),)
else:
vals += (vk_value,)

Expand Down
17 changes: 0 additions & 17 deletions pandapower/test/loadflow/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,30 +370,13 @@ def test_undefined_tap_dependent_impedance_characteristics_trafo3w():
add_trafo_connection(net, 1, "3W")
add_trafo_connection(net, 1, "3W")

pp.control.create_trafo_characteristics(net, 'trafo3w', [0, 1], 'vk_hv_percent', [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]], [[0.7, 0.9, 1, 1.1, 1.3], [0.7, 0.9, 1, 1.1, 1.3]])
pp.control.create_trafo_characteristics(net, 'trafo3w', [0, 1], 'vk_mv_percent', [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]], [[0.7, 0.9, 1, 1.1, 1.3], [0.7, 0.9, 1, 1.1, 1.3]])
pp.control.create_trafo_characteristics(net, 'trafo3w', [0, 1], 'vk_lv_percent', [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]], [[0.7, 0.9, 1, 1.1, 1.3], [0.7, 0.9, 1, 1.1, 1.3]])
pp.control.create_trafo_characteristics(net, 'trafo3w', [0, 1], 'vkr_hv_percent', [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]], [[0.3, 0.45, 0.5, 0.55, 0.7], [0.3, 0.45, 0.5, 0.55, 0.7]])
pp.control.create_trafo_characteristics(net, 'trafo3w', [0, 1], 'vkr_mv_percent', [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]], [[0.3, 0.45, 0.5, 0.55, 0.7], [0.3, 0.45, 0.5, 0.55, 0.7]])
pp.control.create_trafo_characteristics(net, 'trafo3w', [0, 1], 'vkr_lv_percent', [[-2, -1, 0, 1, 2], [-2, -1, 0, 1, 2]], [[0.3, 0.45, 0.5, 0.55, 0.7], [0.3, 0.45, 0.5, 0.55, 0.7]])


# does not raise error
pp.runpp(net)

# this will raise error
net.trafo3w.at[0, "vk_hv_percent_characteristic"] = None
pp.runpp(net)
net.trafo3w.at[0, "vk_mv_percent_characteristic"] = None
pp.runpp(net)
net.trafo3w.at[0, "vk_lv_percent_characteristic"] = None
pp.runpp(net)

net.trafo3w.at[0, "vkr_hv_percent_characteristic"] = None
pp.runpp(net)
net.trafo3w.at[0, "vkr_mv_percent_characteristic"] = None
pp.runpp(net)
net.trafo3w.at[0, "vkr_lv_percent_characteristic"] = None
with pytest.raises(UserWarning):
pp.runpp(net)

Expand Down

0 comments on commit d964a70

Please sign in to comment.