Skip to content

Commit

Permalink
Merge features/#392-include_powerplants into pumped hydro branch
Browse files Browse the repository at this point in the history
  • Loading branch information
IlkaCu committed Sep 27, 2021
2 parents 3165ce7 + 2bffb51 commit b99a932
Show file tree
Hide file tree
Showing 6 changed files with 464 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ Added
* Extend zensus by a combined table with all cells where
there's either building, apartment or population data
`#359 <https://github.com/openego/eGon-data/issues/359>`_
* 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

Expand Down
5 changes: 4 additions & 1 deletion src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ 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"
mastr_storage: "bnetza_mastr_storage_cleaned.csv"
capacities: "supply.egon_scenario_capacities"
geom_germany: "boundaries.vg250_sta_union"
Expand Down Expand Up @@ -654,10 +655,11 @@ etrago_electricity:
schema: 'grid'
table: 'egon_etrago_load_timeseries'


chp_location:
sources:
list_conv_pp:
table: 'nep_2021_conv_powerplants'
table: 'egon_nep_2021_conventional_powerplants'
schema: 'supply'
mastr_combustion: 'bnetza_mastr_combustion_cleaned.csv'
mastr_location: 'location_elec_generation_raw.csv'
Expand Down Expand Up @@ -688,3 +690,4 @@ chp_location:
mastr_conventional_without_chp:
table: 'egon_mastr_conventional_without_chp'
schema: 'supply'

4 changes: 3 additions & 1 deletion src/egon/data/datasets/chp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class EgonMaStRConventinalWithoutChp(Base):
EinheitMastrNummer = Column(String)
carrier = Column(String)
el_capacity = Column(Float)
plz = Column(Integer)
city = Column(String)
geometry = Column(Geometry("POINT", 4326))


Expand Down Expand Up @@ -208,7 +210,7 @@ def insert_chp_egon2035():
existing_chp_smaller_10mw(sources, MaStR_konv, EgonChp)

gpd.GeoDataFrame(MaStR_konv[['EinheitMastrNummer', 'el_capacity',
'geometry', 'carrier']]).to_postgis(
'geometry', 'carrier', 'plz', 'city']]).to_postgis(
targets["mastr_conventional_without_chp"]["table"],
schema=targets["mastr_conventional_without_chp"]["schema"],
con=db.engine(),
Expand Down
166 changes: 160 additions & 6 deletions src/egon/data/datasets/power_plants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
from egon.data import db
from egon.data.datasets import Dataset
from egon.data.datasets.power_plants.pv_rooftop import pv_rooftop_per_mv_grid
import egon.data.config
import egon.data.datasets.power_plants.pv_ground_mounted as pv_ground_mounted
from egon.data.datasets.power_plants.conventional import (
select_nep_power_plants,
select_no_chp_combustion_mastr,
match_nep_no_chp,
)
import egon.data.datasets.power_plants.wind_farms as wind_onshore
import egon.data.datasets.power_plants.pv_ground_mounted as pv_ground_mounted

Base = declarative_base()

Expand All @@ -45,17 +49,20 @@ class EgonPowerPlants(Base):


class PowerPlants(Dataset):

def __init__(self, dependencies):
super().__init__(
name="PowerPlants",
version="0.0.1",
version="0.0.2",
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

),
)

Expand Down Expand Up @@ -578,3 +585,150 @@ 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"]

for carrier in carrier:

nep = select_nep_power_plants(carrier)
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])

# 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';"""
)

# 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 b99a932

Please sign in to comment.