From 51257e121fc3409e94556b5b8295e0abf0ea3440 Mon Sep 17 00:00:00 2001 From: Steffen Meinecke Date: Wed, 30 Oct 2024 16:20:32 +0100 Subject: [PATCH 1/3] consider new geo data format in docstrings --- pandapower/plotting/plotly/simple_plotly.py | 2 +- pandapower/plotting/plotly/vlevel_plotly.py | 4 ++-- pandapower/toolbox/data_modification.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pandapower/plotting/plotly/simple_plotly.py b/pandapower/plotting/plotly/simple_plotly.py index 4193739d7..db64ff56d 100644 --- a/pandapower/plotting/plotly/simple_plotly.py +++ b/pandapower/plotting/plotly/simple_plotly.py @@ -116,7 +116,7 @@ def simple_plotly(net, respect_switches=True, use_line_geo=None, on_map=False, **respect_switches** (bool, True) - Respect switches when artificial geodata is created **use_line_geo** (bool, True) - defines if lines patches are based on - net.line_geodata of the lines (True) or on net.bus_geodata of the connected buses (False) + net.line.geo of the lines (True) or on net.bus.geo of the connected buses (False) **on_map** (bool, False) - enables using mapbox plot in plotly. If provided geodata are not real geo-coordinates in lon/lat form, on_map will be set to False. diff --git a/pandapower/plotting/plotly/vlevel_plotly.py b/pandapower/plotting/plotly/vlevel_plotly.py index 409baf916..eda70a6e0 100644 --- a/pandapower/plotting/plotly/vlevel_plotly.py +++ b/pandapower/plotting/plotly/vlevel_plotly.py @@ -35,8 +35,8 @@ def vlevel_plotly(net, respect_switches=True, use_line_geo=None, colors_dict=Non OPTIONAL: **respect_switches** (bool, True) - Respect switches when artificial geodata is created - **use_line_geo** (bool, True) - defines if lines patches are based on net.line_geodata - of the lines (True) or on net.bus_geodata of the connected buses (False) + **use_line_geo** (bool, True) - defines if lines patches are based on net.line.geo + of the lines (True) or on net.bus.geo of the connected buses (False) *colors_dict** (dict, None) - dictionary for customization of colors for each voltage level in the form: voltage : color diff --git a/pandapower/toolbox/data_modification.py b/pandapower/toolbox/data_modification.py index a8164fedb..87e2f6b77 100644 --- a/pandapower/toolbox/data_modification.py +++ b/pandapower/toolbox/data_modification.py @@ -376,7 +376,7 @@ def create_continuous_elements_index(net, start=0, add_df_to_reindex=set()): if et in net and isinstance(net[et], pd.DataFrame): if et in ["bus_geodata", "line_geodata"]: - logger.info(et + " don't need to bo included to 'add_df_to_reindex'. It is " + + logger.info(et + " don't need to be included to 'add_df_to_reindex'. It is " + "already included by et=='" + et.split("_")[0] + "'.") else: reindex_elements(net, et, new_index) From 8870dd68c37329d5c00a77b7fe9aa14c4692c805 Mon Sep 17 00:00:00 2001 From: Moritz Franz Date: Mon, 4 Nov 2024 07:40:49 +0100 Subject: [PATCH 2/3] fix failing tests due to the precision changes --- pandapower/test/plotting/test_geo.py | 58 +++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/pandapower/test/plotting/test_geo.py b/pandapower/test/plotting/test_geo.py index 2559bb0a8..a3aac1c1e 100644 --- a/pandapower/test/plotting/test_geo.py +++ b/pandapower/test/plotting/test_geo.py @@ -10,6 +10,7 @@ import geojson import pandas as pd import pytest +from pandas.testing import assert_frame_equal, assert_index_equal import pandapower.plotting.geo as geo from pandapower.test.helper_functions import create_test_network @@ -54,30 +55,48 @@ def get_network_and_result(net, request): def test__node_geometries_from_geodata(get_network_and_result): pytest.importorskip("geopandas") - from geopandas import testing _net, expected = get_network_and_result _bus_geojson_to_geodata_(_net) result = geo._node_geometries_from_geodata(_net.bus_geodata) - testing.assert_geodataframe_equal(result, expected) + # is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function + # can't be adapted + assert result.shape == expected.shape + assert isinstance(result, type(expected)) + assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) | + (result.geometry.is_empty & expected.geometry.is_empty) | + (result.geometry.isna() & expected.geometry.isna())).all() + left2 = result.select_dtypes(exclude="geometry") + right2 = expected.select_dtypes(exclude="geometry") + assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns") + assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv", obj="GeoDataFrame") def test__branch_geometries_from_geodata(get_network_and_result): pytest.importorskip("geopandas") - from geopandas import testing _net, expected = get_network_and_result _line_geojson_to_geodata_(_net) result = geo._branch_geometries_from_geodata(_net.line_geodata) - testing.assert_geodataframe_equal(result, expected) + # is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function + # can't be adapted + assert result.shape == expected.shape + assert isinstance(result, type(expected)) + assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) | + (result.geometry.is_empty & expected.geometry.is_empty) | + (result.geometry.isna() & expected.geometry.isna())).all() + left2 = result.select_dtypes(exclude="geometry") + right2 = expected.select_dtypes(exclude="geometry") + assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns") + assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv", + obj="GeoDataFrame") def test__transform_node_geometry_to_geodata(get_network_and_result): pytest.importorskip("geopandas") - from geopandas import testing _net, expected = get_network_and_result _bus_geojson_to_geodata_(_net) @@ -85,19 +104,40 @@ def test__transform_node_geometry_to_geodata(get_network_and_result): # Transforming to geodata to test the inverse... _net.bus_geodata = geo._node_geometries_from_geodata(_net.bus_geodata) result = geo._transform_node_geometry_to_geodata(_net.bus_geodata) - testing.assert_geodataframe_equal(result, expected) + # is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function + # can't be adapted + assert result.shape == expected.shape + assert isinstance(result, type(expected)) + assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) | + (result.geometry.is_empty & expected.geometry.is_empty) | + (result.geometry.isna() & expected.geometry.isna())).all() + left2 = result.select_dtypes(exclude="geometry") + right2 = expected.select_dtypes(exclude="geometry") + assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns") + assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv", + obj="GeoDataFrame") def test__transform_branch_geometry_to_coords(get_network_and_result): pytest.importorskip("geopandas") - from geopandas import testing _net, expected = get_network_and_result _line_geojson_to_geodata_(_net) _net.line_geodata = geo._branch_geometries_from_geodata(_net.line_geodata) result = geo._transform_branch_geometry_to_coords(_net.line_geodata) - testing.assert_geodataframe_equal(result, expected) + # is mostly the same as assert_geodataframe_equal with check_less_precise=True, but the tolerance in the function + # can't be adapted + assert result.shape == expected.shape + assert isinstance(result, type(expected)) + assert (result.geom_equals_exact(expected.geometry, tolerance=1 * 10 ** (-6)) | + (result.geometry.is_empty & expected.geometry.is_empty) | + (result.geometry.isna() & expected.geometry.isna())).all() + left2 = result.select_dtypes(exclude="geometry") + right2 = expected.select_dtypes(exclude="geometry") + assert_index_equal(result.columns, expected.columns, exact="equiv", obj="GeoDataFrame.columns") + assert_frame_equal(left2, right2, check_dtype=True, check_index_type="equiv", check_column_type="equiv", + obj="GeoDataFrame") def test__convert_xy_epsg(): @@ -261,7 +301,6 @@ def test_dump_to_geojson(): assert dumps(result, sort_keys=True) == '{"features": [{"geometry": {"coordinates": [[1.0, 2.0], [3.0, 4.0]], "type": "LineString"}, "id": "line-0", "properties": {"c_nf_per_km": 720.0, "df": 1.0, "from_bus": 1, "g_us_per_km": 0.0, "i_from_ka": 7.0, "i_ka": 7.0, "i_to_ka": 7.0, "ices": 0.389985, "in_service": true, "length_km": 1.0, "loading_percent": 7.0, "max_i_ka": 0.328, "name": "line1", "p_from_mw": 7.0, "p_to_mw": 7.0, "parallel": 1, "pl_mw": 7.0, "pp_index": 0, "pp_type": "line", "q_from_mvar": 7.0, "q_to_mvar": 7.0, "ql_mvar": 7.0, "r_ohm_per_km": 0.2067, "std_type": null, "to_bus": 7, "type": null, "va_from_degree": 7.0, "va_to_degree": 7.0, "vm_from_pu": 7.0, "vm_to_pu": 7.0, "x_ohm_per_km": 0.1897522}, "type": "Feature"}], "type": "FeatureCollection"}' - def test_convert_geodata_to_geojson(): pytest.importorskip("geojson") pytest.importorskip("pandapower") @@ -295,6 +334,5 @@ def test_convert_gis_to_geojson(): pytest.skip("Not implemented") - if __name__ == "__main__": pytest.main(["test_geo.py"]) From 1058f2e182595d6be7858c0121d0b6e4a6ac4e70 Mon Sep 17 00:00:00 2001 From: Jakob Kirschner Date: Thu, 7 Nov 2024 14:10:40 +0100 Subject: [PATCH 3/3] fix bt_pu in cim series compensators --- .../converter_classes/impedance/seriesCompensatorsCim16.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandapower/converter/cim/cim2pp/converter_classes/impedance/seriesCompensatorsCim16.py b/pandapower/converter/cim/cim2pp/converter_classes/impedance/seriesCompensatorsCim16.py index 030e75701..824e568dd 100644 --- a/pandapower/converter/cim/cim2pp/converter_classes/impedance/seriesCompensatorsCim16.py +++ b/pandapower/converter/cim/cim2pp/converter_classes/impedance/seriesCompensatorsCim16.py @@ -107,7 +107,7 @@ def _prepare_series_compensators_cim16(self) -> pd.DataFrame: ser_comp['gf_pu'] = 0. ser_comp['bf_pu'] = 0. ser_comp['gt_pu'] = 0. - ser_comp['bf_pu'] = 0. + ser_comp['bt_pu'] = 0. ser_comp['in_service'] = ser_comp.connected & ser_comp.connected2 ser_comp = ser_comp.rename(columns={'rdfId_Terminal': sc['t_from'], 'rdfId_Terminal2': sc['t_to'], 'rdfId': sc['o_id'], 'index_bus': 'from_bus', 'index_bus2': 'to_bus'})