Skip to content

Commit

Permalink
merge filling etrago generators table
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosEpia committed Nov 5, 2021
2 parents bb7e5cf + 333279e commit 794c1e6
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 96 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -164,6 +164,8 @@ Added
`#405 <https://github.com/openego/eGon-data/issues/405>`_
* Fill egon-etrago-generators table
`#485 <https://github.com/openego/eGon-data/issues/485>`_
* Include biomass CHP plants to eTraGo tables
`#498 <https://github.com/openego/eGon-data/issues/498>`_

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

Expand Down
4 changes: 4 additions & 0 deletions src/egon/data/datasets.yml
Expand Up @@ -701,6 +701,7 @@ chp_location:
vg250_lan:
schema: 'boundaries'
table: 'vg250_lan'
mastr_biomass: "bnetza_mastr_biomass_cleaned.csv"
targets:
chp_table:
table: 'egon_chp_plants'
Expand All @@ -724,6 +725,9 @@ chp_etrago:
link:
schema: 'grid'
table: 'egon_etrago_link'
generator:
schema: 'grid'
table: 'egon_etrago_generator'

DSM_CTS_industry:
sources:
Expand Down
136 changes: 120 additions & 16 deletions src/egon/data/datasets/chp/__init__.py
Expand Up @@ -16,11 +16,18 @@
from egon.data.datasets import Dataset
from egon.data.datasets.chp.match_nep import insert_large_chp
from egon.data.datasets.chp.small_chp import (
assign_use_case,
existing_chp_smaller_10mw,
extension_per_federal_state,
select_target,
)
from egon.data.datasets.etrago_setup import link_geom_from_buses
from egon.data.datasets.power_plants import (
assign_bus_id,
assign_voltage_level,
filter_mastr_geometry,
scale_prox2now,
)

Base = declarative_base()

Expand Down Expand Up @@ -183,25 +190,120 @@ def assign_heat_bus(scenario="eGon2035"):
# Insert district heating CHP with heat_bus_id
session = sessionmaker(bind=db.engine())()
for i, row in chp.iterrows():
entry = EgonChp(
id=i,
sources=row.sources,
source_id=row.source_id,
carrier=row.carrier,
el_capacity=row.el_capacity,
th_capacity=row.th_capacity,
electrical_bus_id=row.electrical_bus_id,
ch4_bus_id=row.ch4_bus_id,
district_heating_area_id=row.district_heating_area_id,
district_heating=row.district_heating,
voltage_level=row.voltage_level,
scenario=scenario,
geom=f"SRID=4326;POINT({row.geom.x} {row.geom.y})",
)
if row.carrier != "biomass":
entry = EgonChp(
id=i,
sources=row.sources,
source_id=row.source_id,
carrier=row.carrier,
el_capacity=row.el_capacity,
th_capacity=row.th_capacity,
electrical_bus_id=row.electrical_bus_id,
ch4_bus_id=row.ch4_bus_id,
district_heating_area_id=row.district_heating_area_id,
district_heating=row.district_heating,
voltage_level=row.voltage_level,
scenario=scenario,
geom=f"SRID=4326;POINT({row.geom.x} {row.geom.y})",
)
else:
entry = EgonChp(
id=i,
sources=row.sources,
source_id=row.source_id,
carrier=row.carrier,
el_capacity=row.el_capacity,
th_capacity=row.th_capacity,
electrical_bus_id=row.electrical_bus_id,
district_heating_area_id=row.district_heating_area_id,
district_heating=row.district_heating,
voltage_level=row.voltage_level,
scenario=scenario,
geom=f"SRID=4326;POINT({row.geom.x} {row.geom.y})",
)
session.add(entry)
session.commit()


def insert_biomass_chp(scenario):
"""Insert biomass chp plants of future scenario
Parameters
----------
scenario : str
Name of scenario.
Returns
-------
None.
"""
cfg = config.datasets()["chp_location"]

# import target values from NEP 2021, scneario C 2035
target = select_target("biomass", scenario)

# import data for MaStR
mastr = pd.read_csv(cfg["sources"]["mastr_biomass"]).query(
"EinheitBetriebsstatus=='InBetrieb'"
)

# Drop entries without federal state or 'AusschließlichWirtschaftszone'
mastr = mastr[
mastr.Bundesland.isin(
pd.read_sql(
f"""SELECT DISTINCT ON (gen)
REPLACE(REPLACE(gen, '-', ''), 'ü', 'ue') as states
FROM {cfg['sources']['vg250_lan']['schema']}.
{cfg['sources']['vg250_lan']['table']}""",
con=db.engine(),
).states.values
)
]

# Scaling will be done per federal state in case of eGon2035 scenario.
if scenario == "eGon2035":
level = "federal_state"
else:
level = "country"

# Choose only entries with valid geometries inside DE/test mode
mastr_loc = filter_mastr_geometry(mastr).set_geometry("geometry")

# Scale capacities to meet target values
mastr_loc = scale_prox2now(mastr_loc, target, level=level)

# Assign bus_id
if len(mastr_loc) > 0:
mastr_loc["voltage_level"] = assign_voltage_level(mastr_loc, cfg)
mastr_loc = assign_bus_id(mastr_loc, cfg)

mastr_loc = assign_use_case(mastr_loc, cfg["sources"])

# Insert entries with location
session = sessionmaker(bind=db.engine())()
for i, row in mastr_loc.iterrows():
if row.ThermischeNutzleistung > 0:
entry = EgonChp(
sources={
"chp": "MaStR",
"el_capacity": "MaStR scaled with NEP 2021",
"th_capacity": "MaStR",
},
source_id={"MastrNummer": row.EinheitMastrNummer},
carrier="biomass",
el_capacity=row.Nettonennleistung,
th_capacity=row.ThermischeNutzleistung / 1000,
scenario=scenario,
district_heating=row.district_heating,
electrical_bus_id=row.bus_id,
voltage_level=row.voltage_level,
geom=f"SRID=4326;POINT({row.Laengengrad} {row.Breitengrad})",
)
session.add(entry)
session.commit()


def insert_chp_egon2035():
"""Insert CHP plants for eGon2035 considering NEP and MaStR data
Expand All @@ -217,6 +319,8 @@ def insert_chp_egon2035():

targets = config.datasets()["chp_location"]["targets"]

insert_biomass_chp("eGon2035")

# Insert large CHPs based on NEP's list of conventional power plants
MaStR_konv = insert_large_chp(sources, targets["chp_table"], EgonChp)

Expand Down Expand Up @@ -331,7 +435,7 @@ class Chp(Dataset):
def __init__(self, dependencies):
super().__init__(
name="Chp",
version="0.0.1",
version="0.0.2",
dependencies=dependencies,
tasks=(
create_tables,
Expand Down
11 changes: 6 additions & 5 deletions src/egon/data/datasets/chp/match_nep.py
Expand Up @@ -2,19 +2,20 @@
The module containing all code dealing with large chp from NEP list.
"""

import pandas as pd
from sqlalchemy.orm import sessionmaker
import geopandas
from egon.data import db, config
import pandas as pd

from egon.data import config, db
from egon.data.datasets.chp.small_chp import assign_use_case
from egon.data.datasets.power_plants import (
assign_voltage_level,
assign_bus_id,
assign_gas_bus_id,
assign_voltage_level,
filter_mastr_geometry,
select_target,
)
from egon.data.datasets.chp.small_chp import assign_use_case
from egon.data.datasets.scenario_capacities import map_carrier
from sqlalchemy.orm import sessionmaker


##################################### NEP treatment #################################
Expand Down
20 changes: 13 additions & 7 deletions src/egon/data/datasets/chp/small_chp.py
@@ -1,16 +1,17 @@
"""
The module containing all code dealing with chp < 10MW.
"""
from egon.data import db, config
from sqlalchemy.orm import sessionmaker
import geopandas as gpd
import numpy as np

from egon.data import config, db
from egon.data.datasets.power_plants import (
assign_bus_id,
assign_gas_bus_id,
filter_mastr_geometry,
select_target,
)
from sqlalchemy.orm import sessionmaker
import geopandas as gpd
import numpy as np


def insert_mastr_chp(mastr_chp, EgonChp):
Expand Down Expand Up @@ -254,14 +255,18 @@ def extension_to_areas(
areas.area_id == selected_areas.area_id.values[0]
],
"demand",
] -= (selected_chp.th_capacity * flh)
] -= (
selected_chp.th_capacity * flh
)
else:
areas.loc[
areas.index[
areas.osm_id == selected_areas.osm_id.values[0]
],
"demand",
] -= (selected_chp.th_capacity * flh)
] -= (
selected_chp.th_capacity * flh
)
areas = areas[areas.demand > 0]

else:
Expand Down Expand Up @@ -370,7 +375,7 @@ def extension_district_heating(
SELECT
b.residential_and_service_demand - sum(a.el_capacity)*{flh_chp}
as demand, b.area_id,
ST_Transform(ST_Centroid(geom_polygon), 4326) as geom
ST_Transform(ST_PointOnSurface(geom_polygon), 4326) as geom
FROM
{targets['chp_table']['schema']}.
{targets['chp_table']['table']} a,
Expand Down Expand Up @@ -538,6 +543,7 @@ def extension_per_federal_state(federal_state, EgonChp):
FROM {target_table['schema']}.
{target_table['table']}
WHERE sources::json->>'el_capacity' = 'MaStR'
AND carrier != 'biomass'
AND ST_Intersects(geom, (
SELECT ST_Union(geometry) FROM
{sources['vg250_lan']['schema']}.{sources['vg250_lan']['table']} b
Expand Down

0 comments on commit 794c1e6

Please sign in to comment.