Skip to content

Commit

Permalink
Merge pull request #2155 from rbolgaryn/fix/characteristic_update_format
Browse files Browse the repository at this point in the history
add updating the characteristic attributes to convert_format.py
  • Loading branch information
rbolgaryn authored Oct 24, 2023
2 parents 50db2cf + d72039b commit 3544151
Show file tree
Hide file tree
Showing 6 changed files with 2,070 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Change Log
- [ADDED] matplotlib v3.8.0 support (fixed :code:`plotting_colormaps.ipynb`)
- [CHANGED] PowerFactory converter - name :code:`for_name` as :code:`equipment` for all elements; also add to line
- [ADDED] option to use a second tap changer for the trafo element
- [FIXED] :code:`convert_format.py`: update the attributes of the characteristic objects to match the new characteristic


[2.13.1] - 2023-05-12
Expand Down
2 changes: 1 addition & 1 deletion pandapower/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = "2.13.1"
__format_version__ = "2.12.0"
__format_version__ = "2.13.1"
14 changes: 14 additions & 0 deletions pandapower/convert_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def convert_format(net, elements_to_deserialize=None):
if isinstance(net.format_version, float) and net.format_version < 1.6:
set_data_type_of_columns_to_default(net)
_convert_objects(net, elements_to_deserialize)
_update_characteristics(net, elements_to_deserialize)
correct_dtypes(net, error=False)
_add_missing_std_type_tables(net)
net.format_version = __format_version__
Expand Down Expand Up @@ -453,3 +454,16 @@ def _check_elements_to_deserialize(element, elements_to_deserialize):
def _add_missing_std_type_tables(net):
if "fuse" not in net.std_types:
net.std_types["fuse"] = {}


def _update_characteristics(net, elements_to_deserialize):
# new interpolator type has been added to SplineCharacteristic - "pchip", and the attributes have been refactored
if not _check_elements_to_deserialize("characteristic", elements_to_deserialize) or \
"characteristic" not in net or net.characteristic.empty:
return
for c in net.characteristic.object.values:
# meta check for old SplineCharacteristic (cannot import it here to use isinstance):
if not (hasattr(c, "kind") and hasattr(c, "fill_value")):
continue
c.interpolator_kind = "interp1d"
c.kwargs = {"kind": c.__dict__.pop("kind"), "bounds_error": False, "fill_value": c.__dict__.pop("fill_value")}
17 changes: 14 additions & 3 deletions pandapower/test/api/test_convert_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
# and Energy System Technology (IEE), Kassel. All rights reserved.


from pandapower import pp_dir
import pandapower as pp
import numpy as np
import os
import pytest
from packaging import version as vs

folder = os.path.join(pp_dir, "test", "test_files", "old_versions")
folder = os.path.join(pp.pp_dir, "test", "test_files", "old_versions")
found_versions = [file.split("_")[1].split(".json")[0] for _, _, files
in os.walk(folder) for file in files]

Expand All @@ -25,7 +24,7 @@ def test_convert_format(version):
try:
net = pp.from_json(filename, convert=False)
if ('version' in net) and (vs.parse(str(net.version)) > vs.parse('2.0.1')):
_ = pp.from_json(filename, elements_to_deserialize = ['bus', 'load'])
_ = pp.from_json(filename, elements_to_deserialize=['bus', 'load'])
except:
raise UserWarning("Can not load network saved in pandapower version %s" % version)
vm_pu_old = net.res_bus.vm_pu.copy()
Expand All @@ -39,6 +38,7 @@ def test_convert_format(version):
raise UserWarning("Power flow results mismatch "
"with pandapower version %s" % version)


def test_convert_format_pq_bus_meas():
net = pp.from_json(os.path.join(folder, "example_2.3.1.json"), convert=False)
net = pp.convert_format(net)
Expand All @@ -47,10 +47,21 @@ def test_convert_format_pq_bus_meas():
bus_p_meas = net.measurement.query("element_type=='bus' and measurement_type=='p'").set_index("element", drop=True)
assert np.allclose(net.res_bus.p_mw, bus_p_meas["value"])


def test_convert_format_controller():
net = pp.from_json(os.path.join(folder, "example_2.3.0.json"), convert=True)
controller = net.controller.object.iloc[0]
assert not hasattr(controller, "net")


def test_convert_format_characteristics():
net = pp.from_json(os.path.join(folder, "example_2.13.0.1.json"), convert=True)
assert hasattr(net.characteristic.at[0, "object"], "interpolator_kind")
assert hasattr(net.characteristic.at[0, "object"], "kwargs")
assert not hasattr(net.characteristic.at[0, "object"], "kind")
assert not hasattr(net.characteristic.at[0, "object"], "fill_value")
pp.runpp(net)


if __name__ == '__main__':
pytest.main([__file__])
Loading

0 comments on commit 3544151

Please sign in to comment.