From ed342b5cfe73271866e6def9bd112fdb0d4ef6ab Mon Sep 17 00:00:00 2001 From: Kilian Helfenbein Date: Fri, 17 Mar 2023 15:05:45 +0100 Subject: [PATCH 1/6] add voltage level to scenario plants --- src/egon/data/datasets/power_plants/pv_rooftop_buildings.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py b/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py index 9794b19dc..ccd3d9b22 100644 --- a/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py +++ b/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py @@ -59,6 +59,7 @@ from egon.data.datasets.electricity_demand_timeseries.hh_buildings import ( OsmBuildingsSynthetic, ) +from egon.data.datasets.power_plants.mastr import infer_voltage_level from egon.data.datasets.power_plants.mastr_db_classes import EgonPowerPlantsPv from egon.data.datasets.scenario_capacities import EgonScenarioCapacities from egon.data.datasets.zensus_vg250 import Vg250Gem @@ -2234,4 +2235,4 @@ def pv_rooftop_to_buildings(): all_buildings_gdf = add_bus_ids_sq(all_buildings_gdf) # export scenario - create_scenario_table(all_buildings_gdf) + create_scenario_table(infer_voltage_level(all_buildings_gdf)) From 7f176432cae1a3ce26836560ca9163373a018eb4 Mon Sep 17 00:00:00 2001 From: Kilian Helfenbein Date: Fri, 17 Mar 2023 15:21:55 +0100 Subject: [PATCH 2/6] copy function because of circular import --- .../power_plants/pv_rooftop_buildings.py | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py b/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py index ccd3d9b22..61ed2f76b 100644 --- a/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py +++ b/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py @@ -59,7 +59,6 @@ from egon.data.datasets.electricity_demand_timeseries.hh_buildings import ( OsmBuildingsSynthetic, ) -from egon.data.datasets.power_plants.mastr import infer_voltage_level from egon.data.datasets.power_plants.mastr_db_classes import EgonPowerPlantsPv from egon.data.datasets.scenario_capacities import EgonScenarioCapacities from egon.data.datasets.zensus_vg250 import Vg250Gem @@ -2183,6 +2182,46 @@ def add_bus_ids_sq( return buildings_gdf +def infer_voltage_level( + units_gdf: gpd.GeoDataFrame, +) -> gpd.GeoDataFrame: + """ + Infer nan values in voltage level derived from generator capacity to + the power plants. + + Parameters + ----------- + units_gdf : geopandas.GeoDataFrame + GeoDataFrame containing units with voltage levels from MaStR + Returnsunits_gdf: gpd.GeoDataFrame + ------- + geopandas.GeoDataFrame + GeoDataFrame containing units all having assigned a voltage level. + """ + + def voltage_levels(p: float) -> int: + if p <= 100: + return 7 + elif p <= 200: + return 6 + elif p <= 5500: + return 5 + elif p <= 20000: + return 4 + elif p <= 120000: + return 3 + return 1 + + units_gdf["voltage_level_inferred"] = False + mask = units_gdf.voltage_level.isna() + units_gdf.loc[mask, "voltage_level_inferred"] = True + units_gdf.loc[mask, "voltage_level"] = units_gdf.loc[ + mask + ].Nettonennleistung.apply(voltage_levels) + + return units_gdf + + def pv_rooftop_to_buildings(): """Main script, executed as task""" From 618e717acad1a3518b81fd1431a7c70e6c56f90b Mon Sep 17 00:00:00 2001 From: Kilian Helfenbein Date: Mon, 20 Mar 2023 09:19:40 +0100 Subject: [PATCH 3/6] fixeing devision by zero error --- src/egon/data/datasets/power_plants/mastr.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/egon/data/datasets/power_plants/mastr.py b/src/egon/data/datasets/power_plants/mastr.py index 19f2d9b36..24330280d 100644 --- a/src/egon/data/datasets/power_plants/mastr.py +++ b/src/egon/data/datasets/power_plants/mastr.py @@ -473,10 +473,11 @@ def import_mastr() -> None: units = units.loc[units.geometry.within(boundary)] - logger.debug( - f"{init_len - len(units)}/{init_len} " - f"({((init_len - len(units)) / init_len) * 100: g} %) dropped." - ) + if init_len > 0: + logger.debug( + f"{init_len - len(units)}/{init_len} " + f"({((init_len - len(units)) / init_len) * 100: g} %) dropped." + ) # drop unnecessary and rename columns logger.debug("Reformatting...") From 384ce5bf4814369868673802ff058116125ecb92 Mon Sep 17 00:00:00 2001 From: Kilian Helfenbein Date: Mon, 20 Mar 2023 09:20:06 +0100 Subject: [PATCH 4/6] fixeing devision by zero error --- src/egon/data/datasets/power_plants/mastr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egon/data/datasets/power_plants/mastr.py b/src/egon/data/datasets/power_plants/mastr.py index 24330280d..225c7c685 100644 --- a/src/egon/data/datasets/power_plants/mastr.py +++ b/src/egon/data/datasets/power_plants/mastr.py @@ -500,7 +500,7 @@ def import_mastr() -> None: units["voltage_level"] = units.voltage_level.fillna(-1).astype(int) units.set_geometry("geom", inplace=True) - units["id"] = range(0, len(units)) + units["id"] = range(len(units)) # change capacity unit: kW to MW units["capacity"] = units["capacity"] / 1e3 From 26d12c9688eb1131595e61c571e2edcb7fb4c11e Mon Sep 17 00:00:00 2001 From: Kilian Helfenbein Date: Mon, 20 Mar 2023 09:29:50 +0100 Subject: [PATCH 5/6] update dataset version --- src/egon/data/datasets/power_plants/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/egon/data/datasets/power_plants/__init__.py b/src/egon/data/datasets/power_plants/__init__.py index 672431240..71213e66f 100755 --- a/src/egon/data/datasets/power_plants/__init__.py +++ b/src/egon/data/datasets/power_plants/__init__.py @@ -59,7 +59,7 @@ class PowerPlants(Dataset): def __init__(self, dependencies): super().__init__( name="PowerPlants", - version="0.0.17", + version="0.0.18", dependencies=dependencies, tasks=( create_tables, From 5b5dcaab6e12b710df5b9dcea173b1eb074ea082 Mon Sep 17 00:00:00 2001 From: Kilian Helfenbein Date: Mon, 20 Mar 2023 10:01:25 +0100 Subject: [PATCH 6/6] fix wrong col name --- .../power_plants/pv_rooftop_buildings.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py b/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py index 61ed2f76b..0c625a992 100644 --- a/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py +++ b/src/egon/data/datasets/power_plants/pv_rooftop_buildings.py @@ -2200,24 +2200,24 @@ def infer_voltage_level( """ def voltage_levels(p: float) -> int: - if p <= 100: + if p <= 0.1: return 7 - elif p <= 200: + elif p <= 0.2: return 6 - elif p <= 5500: + elif p <= 5.5: return 5 - elif p <= 20000: + elif p <= 20: return 4 - elif p <= 120000: + elif p <= 120: return 3 return 1 units_gdf["voltage_level_inferred"] = False mask = units_gdf.voltage_level.isna() units_gdf.loc[mask, "voltage_level_inferred"] = True - units_gdf.loc[mask, "voltage_level"] = units_gdf.loc[ - mask - ].Nettonennleistung.apply(voltage_levels) + units_gdf.loc[mask, "voltage_level"] = units_gdf.loc[mask].capacity.apply( + voltage_levels + ) return units_gdf