Skip to content

Commit

Permalink
Merge pull request #453 from openego/features/#392-include-powerplants
Browse files Browse the repository at this point in the history
Features/#392 include powerplants
  • Loading branch information
IlkaCu authored Nov 2, 2021
2 parents 73865d0 + 6459deb commit 8281e35
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 56 deletions.
5 changes: 2 additions & 3 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,12 @@ Added
`#330 <https://github.com/openego/eGon-data/issues/330>`_
* Distribute wind offshore capacities
`#329 <https://github.com/openego/eGon-data/issues/329>`_
* Include allocation of conventional (non CHP) power plants
`#392 <https://github.com/openego/eGon-data/issues/392>`_

.. _PR #159: https://github.com/openego/eGon-data/pull/159





Changed
-------

Expand Down
88 changes: 49 additions & 39 deletions src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
from egon.data.datasets.demandregio import DemandRegio
from egon.data.datasets.district_heating_areas import DistrictHeatingAreas
from egon.data.datasets.DSM_cts_ind import dsm_Potential
from egon.data.datasets.electricity_demand import (CtsElectricityDemand,
HouseholdElectricityDemand)
from egon.data.datasets.electricity_demand import (
CtsElectricityDemand,
HouseholdElectricityDemand,
)
from egon.data.datasets.electricity_demand_etrago import ElectricalLoadEtrago
from egon.data.datasets.era5 import WeatherData
from egon.data.datasets.etrago_setup import EtragoSetup
from egon.data.datasets.gas_prod import CH4Production
from egon.data.datasets.heat_demand import HeatDemandImport
from egon.data.datasets.heat_etrago import HeatEtrago
from egon.data.datasets.heat_supply import HeatSupply
from egon.data.datasets.hh_demand_profiles import (hh_demand_setup,
houseprofiles_in_census_cells,
mv_grid_district_HH_electricity_load)
from egon.data.datasets.hh_demand_profiles import (
hh_demand_setup,
houseprofiles_in_census_cells,
mv_grid_district_HH_electricity_load,
)
from egon.data.datasets.industrial_gas_demand import IndustrialGasDemand
from egon.data.datasets.industrial_sites import MergeIndustrialSites
from egon.data.datasets.industry import IndustrialDemandCurves
Expand Down Expand Up @@ -351,36 +355,6 @@
"electricity_demand.distribute-cts-demands"
]

# Power plants
power_plants = PowerPlants(
dependencies=[
setup,
renewable_feedin,
mv_grid_districts,
mastr_data,
re_potential_areas,
scenario_parameters,
scenario_capacities,
Vg250MvGridDistricts,
]
)

power_plant_import = tasks["power_plants.insert-hydro-biomass"]
generate_wind_farms = tasks["power_plants.wind_farms.insert"]
generate_pv_ground_mounted = tasks["power_plants.pv_ground_mounted.insert"]
solar_rooftop_etrago = tasks[
"power_plants.pv_rooftop.pv-rooftop-per-mv-grid"
]
generate_wind_offshore = tasks["power_plants.wind_offshore.insert"]

hvmv_substation_extraction >> generate_wind_farms
hvmv_substation_extraction >> generate_pv_ground_mounted
feedin_pv >> solar_rooftop_etrago
elec_cts_demands_zensus >> solar_rooftop_etrago
elec_household_demands_zensus >> solar_rooftop_etrago
etrago_input_data >> solar_rooftop_etrago
map_zensus_grid_districts >> solar_rooftop_etrago

mv_hh_electricity_load_2035 = PythonOperator(
task_id="MV-hh-electricity-load-2035",
python_callable=mv_grid_district_HH_electricity_load,
Expand Down Expand Up @@ -447,6 +421,36 @@
create_gas_polygons >> chp_locations_nep
import_district_heating_areas >> chp_locations_nep

# Power plants
power_plants = PowerPlants(
dependencies=[
setup,
renewable_feedin,
mv_grid_districts,
mastr_data,
re_potential_areas,
scenario_parameters,
scenario_capacities,
Vg250MvGridDistricts,
chp,
]
)

power_plant_import = tasks["power_plants.insert-hydro-biomass"]
generate_wind_farms = tasks["power_plants.wind_farms.insert"]
generate_pv_ground_mounted = tasks["power_plants.pv_ground_mounted.insert"]
solar_rooftop_etrago = tasks[
"power_plants.pv_rooftop.pv-rooftop-per-mv-grid"
]

hvmv_substation_extraction >> generate_wind_farms
hvmv_substation_extraction >> generate_pv_ground_mounted
feedin_pv >> solar_rooftop_etrago
elec_cts_demands_zensus >> solar_rooftop_etrago
elec_household_demands_zensus >> solar_rooftop_etrago
etrago_input_data >> solar_rooftop_etrago
map_zensus_grid_districts >> solar_rooftop_etrago

# Heat supply
heat_supply = HeatSupply(
dependencies=[
Expand Down Expand Up @@ -480,7 +484,13 @@

# Heat time Series
heat_time_series = HeatTimeSeries(
dependencies = [data_bundle,demandregio,heat_demand_Germany, import_district_heating_areas,
import_district_heating_areas,vg250,
map_zensus_grid_districts])

dependencies=[
data_bundle,
demandregio,
heat_demand_Germany,
import_district_heating_areas,
import_district_heating_areas,
vg250,
map_zensus_grid_districts,
]
)
2 changes: 2 additions & 0 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,13 @@ power_plants:
mastr_biomass: "bnetza_mastr_biomass_cleaned.csv"
mastr_hydro: "bnetza_mastr_hydro_cleaned.csv"
mastr_location: "location_elec_generation_raw.csv"
mastr_combustion_without_chp: "supply.egon_mastr_conventional_without_chp"
capacities: "supply.egon_scenario_capacities"
geom_germany: "boundaries.vg250_sta_union"
geom_federal_states: "boundaries.vg250_lan"
egon_mv_grid_district: "grid.egon_mv_grid_district"
ehv_voronoi: "grid.egon_ehv_substation_voronoi"
nep_conv: "supply.egon_nep_2021_conventional_powerplants"
buses_data: "osmtgmod_results.bus_data"
power_plants: 'supply.egon_power_plants'
nep_2035: "NEP2035_V2021_scnC2035.xlsx"
Expand Down
183 changes: 174 additions & 9 deletions src/egon/data/datasets/power_plants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@

from egon.data import db
from egon.data.datasets import Dataset
from egon.data.datasets.power_plants.conventional import (
match_nep_no_chp,
select_nep_power_plants,
select_no_chp_combustion_mastr,
)
from egon.data.datasets.power_plants.pv_rooftop import pv_rooftop_per_mv_grid
import egon.data.config
import egon.data.datasets.power_plants.wind_farms as wind_onshore
import egon.data.datasets.power_plants.wind_offshore as wind_offshore
import egon.data.datasets.power_plants.pv_ground_mounted as pv_ground_mounted

import egon.data.datasets.power_plants.assign_weather_data as assign_weather_data
import egon.data.datasets.power_plants.pv_ground_mounted as pv_ground_mounted
import egon.data.datasets.power_plants.wind_farms as wind_onshore
import egon.data.datasets.power_plants.wind_offshore as wind_offshore

Base = declarative_base()

Expand All @@ -52,16 +55,19 @@ class PowerPlants(Dataset):
def __init__(self, dependencies):
super().__init__(
name="PowerPlants",
version="0.0.2",
version="0.0.4",
dependencies=dependencies,
tasks=(
create_tables,
insert_hydro_biomass,
wind_onshore.insert,
pv_ground_mounted.insert,
pv_rooftop_per_mv_grid,
allocate_conventional_non_chp_power_plants,
{
wind_onshore.insert,
pv_ground_mounted.insert,
pv_rooftop_per_mv_grid,
},
assign_weather_data.weather_id,
wind_offshore.insert,
wind_offshore.insert,
),
)

Expand Down Expand Up @@ -581,3 +587,162 @@ def insert_hydro_biomass():
for scenario in ["eGon2035"]:
insert_biomass_plants(scenario)
insert_hydro_plants(scenario)


def allocate_conventional_non_chp_power_plants():

carrier = ["oil", "gas", "other_non_renewable"]

cfg = egon.data.config.datasets()["power_plants"]

# Delete existing CHP in the target table
db.execute_sql(
f"""
DELETE FROM {cfg ['target']['schema']}.{cfg ['target']['table']}
WHERE carrier IN ('gas', 'other_non_renewable', 'oil')
AND scenario='eGon2035';
"""
)

for carrier in carrier:

nep = select_nep_power_plants(carrier)

if nep.empty:
print(f"DataFrame from NEP for carrier {carrier} is empty!")

else:

mastr = select_no_chp_combustion_mastr(carrier)

# Assign voltage level to MaStR
mastr["voltage_level"] = assign_voltage_level(
mastr.rename({"el_capacity": "Nettonennleistung"}, axis=1), cfg
)

# Initalize DataFrame for matching power plants
matched = gpd.GeoDataFrame(
columns=[
"carrier",
"el_capacity",
"scenario",
"geometry",
"MaStRNummer",
"source",
"voltage_level",
]
)

# Match combustion plants of a certain carrier from NEP list
# using PLZ and capacity
matched, mastr, nep = match_nep_no_chp(
nep,
mastr,
matched,
buffer_capacity=0.1,
consider_carrier=False,
)

# Match plants from NEP list using city and capacity
matched, mastr, nep = match_nep_no_chp(
nep,
mastr,
matched,
buffer_capacity=0.1,
consider_carrier=False,
consider_location="city",
)

# Match plants from NEP list using plz,
# neglecting the capacity
matched, mastr, nep = match_nep_no_chp(
nep,
mastr,
matched,
consider_location="plz",
consider_carrier=False,
consider_capacity=False,
)

# Match plants from NEP list using city,
# neglecting the capacity
matched, mastr, nep = match_nep_no_chp(
nep,
mastr,
matched,
consider_location="city",
consider_carrier=False,
consider_capacity=False,
)

# Match remaining plants from NEP using the federal state
matched, mastr, nep = match_nep_no_chp(
nep,
mastr,
matched,
buffer_capacity=0.1,
consider_location="federal_state",
consider_carrier=False,
)

# Match remaining plants from NEP using the federal state
matched, mastr, nep = match_nep_no_chp(
nep,
mastr,
matched,
buffer_capacity=0.7,
consider_location="federal_state",
consider_carrier=False,
)

print(f"{matched.el_capacity.sum()} MW of {carrier} matched")
print(f"{nep.c2035_capacity.sum()} MW of {carrier} not matched")

matched.crs = "EPSG:4326"

# Assign bus_id
# Load grid district polygons
mv_grid_districts = db.select_geodataframe(
f"""
SELECT * FROM {cfg['sources']['egon_mv_grid_district']}
""",
epsg=4326,
)

ehv_grid_districts = db.select_geodataframe(
f"""
SELECT * FROM {cfg['sources']['ehv_voronoi']}
""",
epsg=4326,
)

# Perform spatial joins for plants in ehv and hv level seperately
power_plants_hv = gpd.sjoin(
matched[matched.voltage_level >= 3],
mv_grid_districts[["bus_id", "geom"]],
how="left",
).drop(columns=["index_right"])
power_plants_ehv = gpd.sjoin(
matched[matched.voltage_level < 3],
ehv_grid_districts[["bus_id", "geom"]],
how="left",
).drop(columns=["index_right"])

# Combine both dataframes
power_plants = pd.concat([power_plants_hv, power_plants_ehv])

# Insert into target table
session = sessionmaker(bind=db.engine())()
for i, row in power_plants.iterrows():
entry = EgonPowerPlants(
sources={"el_capacity": row.source},
source_id={"MastrNummer": row.MaStRNummer},
carrier=row.carrier,
el_capacity=row.el_capacity,
voltage_level=row.voltage_level,
bus_id=row.bus_id,
scenario=row.scenario,
geom=f"SRID=4326;POINT({row.geometry.x} {row.geometry.y})",
)
session.add(entry)
session.commit()
Loading

0 comments on commit 8281e35

Please sign in to comment.