Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge trafo charactersitic #8

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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