Skip to content

Commit

Permalink
Merge branch 'develop' into feature/consider_new_geo_data_format_in_d…
Browse files Browse the repository at this point in the history
…ocstring
  • Loading branch information
SteffenMeinecke authored Nov 13, 2024
2 parents 51257e1 + cddc937 commit 7547865
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down
58 changes: 48 additions & 10 deletions pandapower/test/plotting/test_geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -54,50 +55,89 @@ 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)

# 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():
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -295,6 +334,5 @@ def test_convert_gis_to_geojson():
pytest.skip("Not implemented")



if __name__ == "__main__":
pytest.main(["test_geo.py"])

0 comments on commit 7547865

Please sign in to comment.