Skip to content

Commit

Permalink
Merge pull request #8 from JakobKirschner/feature/shunt-characteristi…
Browse files Browse the repository at this point in the history
…cs_merge_trafocharactersitic

 merge trafo charactersitic
  • Loading branch information
panos-xenos authored Dec 20, 2024
2 parents d02ee5b + bb013bb commit c123fad
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pandapower/test/contingency/test_contingency.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def _randomize_indices(net):

def test_reminder_bring_back_case118():
from packaging.version import Version
if lightsim2grid_installed and Version(lightsim2grid.__version__) > Version("0.9.0"):
if lightsim2grid_installed and Version(lightsim2grid.__version__) > Version("0.10.0"):
raise UserWarning("bring back case 118 and remove xfail for test_unequal_trafo_impedances and test_case118")


Expand Down
50 changes: 28 additions & 22 deletions pandapower/test/toolbox/test_grid_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,28 +190,34 @@ def test_merge_with_groups():
assert list(pp.group_element_index(net, 4, "line")) == list(np.array([1, 3], dtype=np.int64) + \
net1.line.shape[0])

# commented out due to change in logic of characteristics
# def test_merge_with_characteristics():
# from pandapower.networks.simple_pandapower_test_networks import simple_four_bus_system
# from pandapower.control.util.characteristic import Characteristic
#
# # create two networks
# net1 = simple_four_bus_system()
# net2 = simple_four_bus_system()
#
# # create two characteristic
# Characteristic(net1, x_values=[0.85, 1.15], y_values=[5, 15])
# Characteristic(net2, x_values=[0.95, 1.05], y_values=[10, 20])
#
# # assign the characteristic ids to the trafos
# net1.trafo.loc[:, "vk_percent_characteristic"] = 0
# net2.trafo.loc[:, "vk_percent_characteristic"] = 0
#
# # merge networks
# merged, lookup = pp.merge_nets(net1, net2, validate=False, return_net2_reindex_lookup=True)
#
# # The second transformer should have the second characteristic
# assert merged.trafo.loc[1, "vk_percent_characteristic"] == 1
def test_merge_with_characteristics():
from pandapower.networks.simple_pandapower_test_networks import simple_four_bus_system
from pandapower.control.util.characteristic import Characteristic

# create two networks
net1 = simple_four_bus_system()
net2 = simple_four_bus_system()

net1["trafo_characteristic_table"] = pd.DataFrame(
{'id_characteristic': [0, 0, 0, 0, 0], 'step': [-2, -1, 0, 1, 2], 'voltage_ratio': [1, 1, 1, 1, 1],
'angle_deg': [0, 0, 0, 0, 0], 'vk_percent': [2, 3, 4, 5, 6],
'vkr_percent': [1.323, 1.324, 1.325, 1.326, 1.327], 'vk_hv_percent': np.nan, 'vkr_hv_percent': np.nan,
'vk_mv_percent': np.nan, 'vkr_mv_percent': np.nan, 'vk_lv_percent': np.nan, 'vkr_lv_percent': np.nan})
net2["trafo_characteristic_table"] = pd.DataFrame(
{'id_characteristic': [0, 0, 0, 0, 0], 'step': [-2, -1, 0, 1, 2], 'voltage_ratio': [1, 1, 1, 1, 1],
'angle_deg': [0, 0, 0, 0, 0], 'vk_percent': [2.1, 3.1, 4.1, 5.1, 6.1],
'vkr_percent': [1.3, 1.4, 1.5, 1.6, 1.7], 'vk_hv_percent': np.nan, 'vkr_hv_percent': np.nan,
'vk_mv_percent': np.nan, 'vkr_mv_percent': np.nan, 'vk_lv_percent': np.nan, 'vkr_lv_percent': np.nan})

# merge networks
merged, lookup = pp.merge_nets(net1, net2, validate=False, return_net2_reindex_lookup=True)

# The second transformer should have the second characteristic
result = merged.trafo_characteristic_table[
(merged.trafo_characteristic_table["id_characteristic"] == 1) &
(merged.trafo_characteristic_table["step"] == 2)
]
assert result["vkr_percent"].values[0] == 1.7


def test_merge_nets_with_custom_elements():
Expand Down
4 changes: 4 additions & 0 deletions pandapower/toolbox/data_modification.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ def reindex_elements(net, element_type, new_indices=None, old_indices=None, look
net[cost_df].loc[element_in_cost_df, "element"] = get_indices(net[cost_df].element[
element_in_cost_df], lookup)

# --- adapt tap_characteristic
if element_type == "trafo":
if "trafo_characteristic_table" in net and "id_characteristic" in net["trafo_characteristic_table"]:
net["trafo_characteristic_table"]["id_characteristic"] = net["trafo_characteristic_table"]["id_characteristic"].map(lookup)

def create_continuous_elements_index(net, start=0, add_df_to_reindex=set()):
"""
Expand Down

0 comments on commit c123fad

Please sign in to comment.