Skip to content

Commit

Permalink
Merge pull request #846 from openego/features/#845-mapping-zensus-wea…
Browse files Browse the repository at this point in the history
…ther-cell

Mapping zensus weather cell
  • Loading branch information
nailend committed Aug 30, 2022
2 parents fc098ec + 70cb4bc commit 46f26ad
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ Added
`#382 <https://github.com/openego/eGon-data/issues/382>`_
* Add motorized individual travel
`#553 <https://github.com/openego/eGon-data/issues/553>`_
* Add mapping zensus - weather cells
`#845 <https://github.com/openego/eGon-data/issues/845>`_
* Add pv rooftop plants per mv grid for eGon100RE
`#861 <https://github.com/openego/eGon-data/issues/861>`_

Expand Down
4 changes: 3 additions & 1 deletion src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@
load_area = LoadArea(dependencies=[osm, vg250])

# Calculate feedin from renewables
renewable_feedin = RenewableFeedin(dependencies=[vg250, weather_data])
renewable_feedin = RenewableFeedin(
dependencies=[vg250, zensus_vg250, weather_data]
)

# Demarcate district heating areas
district_heating_areas = DistrictHeatingAreas(
Expand Down
92 changes: 85 additions & 7 deletions src/egon/data/datasets/renewable_feedin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,56 @@
Central module containing all code dealing with processing era5 weather data.
"""

from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.ext.declarative import declarative_base
import geopandas as gpd
import numpy as np
import pandas as pd

from egon.data import db
from egon.data.datasets import Dataset
from egon.data.datasets.era5 import import_cutout
from egon.data.datasets.era5 import EgonEra5Cells, import_cutout
from egon.data.datasets.scenario_parameters import get_sector_parameters
from egon.data.datasets.zensus_vg250 import (
DestatisZensusPopulationPerHaInsideGermany,
)
import egon.data.config


class RenewableFeedin(Dataset):
def __init__(self, dependencies):
super().__init__(
name="RenewableFeedin",
version="0.0.5",
version="0.0.6",
dependencies=dependencies,
tasks={wind, pv, solar_thermal, heat_pump_cop, wind_offshore},
tasks={
wind,
pv,
solar_thermal,
heat_pump_cop,
wind_offshore,
mapping_zensus_weather,
},
)


Base = declarative_base()
engine = db.engine()


class MapZensusWeatherCell(Base):
__tablename__ = "egon_map_zensus_weather_cell"
__table_args__ = {"schema": "boundaries"}

zensus_population_id = Column(
Integer,
ForeignKey(DestatisZensusPopulationPerHaInsideGermany.id),
primary_key=True,
index=True,
)
w_id = Column(Integer, ForeignKey(EgonEra5Cells.w_id), index=True)


def weather_cells_in_germany(geom_column="geom"):
"""Get weather cells which intersect with Germany
Expand Down Expand Up @@ -63,7 +92,8 @@ def offshore_weather_cells(geom_column="geom"):
FROM {cfg['weather_cells']['schema']}.
{cfg['weather_cells']['table']}
WHERE ST_Intersects('SRID=4326;
POLYGON((5.5 55.5, 14.5 55.5, 14.5 53.5, 5.5 53.5, 5.5 55.5))', geom)""",
POLYGON((5.5 55.5, 14.5 55.5, 14.5 53.5, 5.5 53.5, 5.5 55.5))',
geom)""",
geom_col=geom_column,
index_col="w_id",
)
Expand Down Expand Up @@ -124,7 +154,6 @@ def federal_states_per_weather_cell():
.set_index("w_id")
)


weather_cells = weather_cells.dropna(axis=0, subset=["federal_state"])

return weather_cells.to_crs(4326)
Expand Down Expand Up @@ -187,7 +216,8 @@ def feedin_per_turbine():
gdf = gpd.GeoDataFrame(geometry=cutout.grid_cells(), crs=4326)

# Calculate feedin-timeseries for E-141
# source: https://openenergy-platform.org/dataedit/view/supply/wind_turbine_library
# source:
# https://openenergy-platform.org/dataedit/view/supply/wind_turbine_library
turbine_e141 = {
"name": "E141 4200 kW",
"hub_height": 129,
Expand Down Expand Up @@ -230,7 +260,8 @@ def feedin_per_turbine():
gdf["E-141"] = ts_e141.to_pandas().transpose().values.tolist()

# Calculate feedin-timeseries for E-126
# source: https://openenergy-platform.org/dataedit/view/supply/wind_turbine_library
# source:
# https://openenergy-platform.org/dataedit/view/supply/wind_turbine_library
turbine_e126 = {
"name": "E126 4200 kW",
"hub_height": 159,
Expand Down Expand Up @@ -539,3 +570,50 @@ def insert_feedin(data, carrier, weather_year):
con=db.engine(),
if_exists="append",
)


def mapping_zensus_weather():
"""Perform mapping between era5 weather cell and zensus grid"""

with db.session_scope() as session:
cells_query = session.query(
DestatisZensusPopulationPerHaInsideGermany.id.label(
"zensus_population_id"
),
DestatisZensusPopulationPerHaInsideGermany.geom_point,
)

gdf_zensus_population = gpd.read_postgis(
cells_query.statement,
cells_query.session.bind,
index_col=None,
geom_col="geom_point",
)

with db.session_scope() as session:
cells_query = session.query(EgonEra5Cells.w_id, EgonEra5Cells.geom)

gdf_weather_cell = gpd.read_postgis(
cells_query.statement,
cells_query.session.bind,
index_col=None,
geom_col="geom",
)
# CRS is 4326
gdf_weather_cell = gdf_weather_cell.to_crs(epsg=3035)

gdf_zensus_weather = gdf_zensus_population.sjoin(
gdf_weather_cell, how="left", predicate="within"
)

MapZensusWeatherCell.__table__.drop(bind=engine, checkfirst=True)
MapZensusWeatherCell.__table__.create(bind=engine, checkfirst=True)

# Write mapping into db
with db.session_scope() as session:
session.bulk_insert_mappings(
MapZensusWeatherCell,
gdf_zensus_weather[["zensus_population_id", "w_id"]].to_dict(
orient="records"
),
)

0 comments on commit 46f26ad

Please sign in to comment.