Skip to content

Commit

Permalink
Merge branch 'dev' into features/#382-sanity-check
Browse files Browse the repository at this point in the history
  • Loading branch information
IlkaCu committed May 10, 2022
2 parents 32ad810 + 810a2ef commit 20663ca
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 34 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,17 @@ Bug Fixes
`#725 <https://github.com/openego/eGon-data/issues/725>`_
* Fix assignemnt of impedances (x) to etrago tables
`#710 <https://github.com/openego/eGon-data/issues/710>`_
* Fix country_code attribution of two gas buses
`#710 <https://github.com/openego/eGon-data/issues/744>`_
* Fix voronoi assignemnt for enclaves
`#734 <https://github.com/openego/eGon-data/issues/734>`_
* Set lengths of non-pipeline links to 0
`#741 <https://github.com/openego/eGon-data/issues/741>`_
* Change table name from :code:`boundaries.saltstructures_inspee` to
:code:`boundaries.inspee_saltstructures`
`#746 <https://github.com/openego/eGon-data/issues/746>`_
* Add missing marginal costs for conventional generators in Germany
`#722 <https://github.com/openego/eGon-data/issues/722>`_

.. _PR #692: https://github.com/openego/eGon-data/pull/692
.. _#343: https://github.com/openego/eGon-data/issues/343
Expand Down
4 changes: 2 additions & 2 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ bgr:
processed:
schema: "boundaries"
file_table_map:
"Potenzialbewertung_InSpEE_InSpEE_DS.shp": "saltstructures_inspee"
"Potenzialbewertung_InSpEE_InSpEE_DS.shp": "inspee_saltstructures"
sources:
vg250_federal_states:
schema: 'boundaries'
table: 'vg250_lan'
saltcaverns:
schema: 'boundaries'
table: 'saltstructures_inspee'
table: 'inspee_saltstructures'
targets:
storage_potential:
schema: 'grid'
Expand Down
33 changes: 28 additions & 5 deletions src/egon/data/datasets/chp_etrago.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
from egon.data import config, db
from egon.data.datasets import Dataset
from egon.data.datasets.etrago_setup import link_geom_from_buses
from egon.data.datasets.scenario_parameters import get_sector_parameters


class ChpEtrago(Dataset):
def __init__(self, dependencies):
super().__init__(
name="ChpEtrago",
version="0.0.3",
version="0.0.5",
dependencies=dependencies,
tasks=(insert),
)
Expand All @@ -41,13 +42,13 @@ def insert():
DELETE FROM {targets['link']['schema']}.{targets['link']['table']}
WHERE carrier LIKE '%%CHP%%'
AND scn_name = 'eGon2035'
AND bus0 IN
(SELECT bus_id
AND bus0 IN
(SELECT bus_id
FROM {sources['etrago_buses']['schema']}.{sources['etrago_buses']['table']}
WHERE scn_name = 'eGon2035'
AND country = 'DE')
AND bus1 IN
(SELECT bus_id
AND bus1 IN
(SELECT bus_id
FROM {sources['etrago_buses']['schema']}.{sources['etrago_buses']['table']}
WHERE scn_name = 'eGon2035'
AND country = 'DE')
Expand Down Expand Up @@ -107,6 +108,12 @@ def insert():
chp_el["link_id"] = range(
db.next_etrago_id("link"), len(chp_el) + db.next_etrago_id("link")
)

# Add marginal cost which is only VOM in case of gas chp
chp_el["marginal_cost"] = get_sector_parameters("gas", "eGon2035")[
"marginal_cost"
]["gas_chp"]

# Insert into database
chp_el.to_postgis(
targets["link"]["table"],
Expand Down Expand Up @@ -160,6 +167,11 @@ def insert():
len(chp_el_gen) + db.next_etrago_id("generator"),
)

# Add marginal cost
chp_el_gen["marginal_cost"] = get_sector_parameters(
"electricity", "eGon2035"
)["marginal_cost"]["biomass"]

chp_el_gen.to_sql(
targets["generator"]["table"],
schema=targets["generator"]["schema"],
Expand Down Expand Up @@ -227,12 +239,18 @@ def insert():
db.next_etrago_id("link"), len(chp_el_ind) + db.next_etrago_id("link")
)

# Add marginal cost which is only VOM in case of gas chp
chp_el_ind["marginal_cost"] = get_sector_parameters("gas", "eGon2035")[
"marginal_cost"
]["gas_chp"]

chp_el_ind.to_postgis(
targets["link"]["table"],
schema=targets["link"]["schema"],
con=db.engine(),
if_exists="append",
)

# Insert biomass CHP as generators
chp_el_ind_gen = pd.DataFrame(
index=chp_generator_ind,
Expand All @@ -251,6 +269,11 @@ def insert():
len(chp_el_ind_gen) + db.next_etrago_id("generator"),
)

# Add marginal cost
chp_el_ind_gen["marginal_cost"] = get_sector_parameters(
"electricity", "eGon2035"
)["marginal_cost"]["biomass"]

chp_el_ind_gen.to_sql(
targets["generator"]["table"],
schema=targets["generator"]["schema"],
Expand Down
27 changes: 24 additions & 3 deletions src/egon/data/datasets/fill_etrago_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from egon.data import db
from egon.data.datasets import Dataset
from egon.data.datasets.scenario_parameters import get_sector_parameters
import egon.data.config


Expand Down Expand Up @@ -45,6 +46,8 @@ def fill_etrago_generators():
cfg=cfg,
)

etrago_pp = add_marginal_costs(etrago_pp)

etrago_gen_table = fill_etrago_gen_table(
etrago_pp2=etrago_pp, etrago_gen_orig=etrago_gen_orig, cfg=cfg, con=con
)
Expand Down Expand Up @@ -92,9 +95,27 @@ def group_power_plants(power_plants, renew_feedin, etrago_gen_orig, cfg):
return etrago_pp


def add_marginal_costs(power_plants):

# Read marginal costs from scenario capacities

marginal_costs = pd.DataFrame.from_dict(
get_sector_parameters("electricity", "eGon2035")["marginal_cost"],
orient="index",
).rename(columns={0: "marginal_cost"})

power_plants = power_plants.merge(
right=marginal_costs, left_on="carrier", right_index=True
)

return power_plants


def fill_etrago_gen_table(etrago_pp2, etrago_gen_orig, cfg, con):

etrago_pp = etrago_pp2[["carrier", "el_capacity", "bus_id", "scenario"]]
etrago_pp = etrago_pp2[
["carrier", "el_capacity", "bus_id", "scenario", "marginal_cost"]
]
etrago_pp = etrago_pp.rename(
columns={
"el_capacity": "p_nom",
Expand Down Expand Up @@ -228,7 +249,7 @@ def delete_previuos_gen(cfg, con, etrago_gen_orig, power_plants):

if carrier_delete:
db.execute_sql(
f"""DELETE FROM
f"""DELETE FROM
{cfg['targets']['etrago_generators']['schema']}.
{cfg['targets']['etrago_generators']['table']}
WHERE carrier IN {*carrier_delete,}
Expand All @@ -241,7 +262,7 @@ def delete_previuos_gen(cfg, con, etrago_gen_orig, power_plants):
)

db.execute_sql(
f"""DELETE FROM
f"""DELETE FROM
{cfg['targets']['etrago_gen_time']['schema']}.
{cfg['targets']['etrago_gen_time']['table']}
WHERE generator_id NOT IN (
Expand Down
18 changes: 15 additions & 3 deletions src/egon/data/datasets/gas_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GasNodesandPipes(Dataset):
def __init__(self, dependencies):
super().__init__(
name="GasNodesandPipes",
version="0.0.4",
version="0.0.5",
dependencies=dependencies,
tasks=(insert_gas_data, insert_gas_data_eGon100RE),
)
Expand Down Expand Up @@ -92,7 +92,13 @@ def define_gas_nodes_list():
usecols=["lat", "long", "id", "country_code", "param"],
)

# Ajouter tri pour ne conserver que les pays ayant des pipelines en commun.
# Correct non valid neighbouring country nodes
gas_nodes_list.loc[
gas_nodes_list["id"] == "INET_N_1182", "country_code"
] = "AT"
gas_nodes_list.loc[
gas_nodes_list["id"] == "SEQ_10608_p", "country_code"
] = "NL"

gas_nodes_list = gas_nodes_list.rename(columns={"lat": "y", "long": "x"})

Expand Down Expand Up @@ -137,7 +143,7 @@ def insert_CH4_nodes_list(gas_nodes_list):

gas_nodes_list = gas_nodes_list[
gas_nodes_list["country_code"].str.match("DE")
] # A remplacer evtmt par un test sur le NUTS0 ?
] # To eventually replace with a test if the nodes are in the german boundaries.

# Cut data to federal state if in testmode
NUTS1 = []
Expand Down Expand Up @@ -460,6 +466,12 @@ def insert_gas_pipeline_list(
gas_pipelines_list.loc[
gas_pipelines_list["country_1"] == "FI", "country_1"
] = "SE"
gas_pipelines_list.loc[
gas_pipelines_list["id"] == "INET_PL_385_EE_3_Seg_0_Seg_1", "country_1"
] = "AT"
gas_pipelines_list.loc[
gas_pipelines_list["id"] == "LKD_PS_0_Seg_0_Seg_3", "country_0"
] = "NL"

# Remove link test if length = 0
gas_pipelines_list = gas_pipelines_list[
Expand Down
12 changes: 4 additions & 8 deletions src/egon/data/datasets/power_plants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PowerPlants(Dataset):
def __init__(self, dependencies):
super().__init__(
name="PowerPlants",
version="0.0.7",
version="0.0.8",
dependencies=dependencies,
tasks=(
create_tables,
Expand Down Expand Up @@ -276,9 +276,7 @@ def insert_biomass_plants(scenario):
for i, row in mastr_loc.iterrows():
if not row.ThermischeNutzleistung > 0:
entry = EgonPowerPlants(
sources={
"el_capacity": "MaStR scaled with NEP 2021",
},
sources={"el_capacity": "MaStR scaled with NEP 2021"},
source_id={"MastrNummer": row.EinheitMastrNummer},
carrier="biomass",
el_capacity=row.Nettonennleistung,
Expand Down Expand Up @@ -365,9 +363,7 @@ def insert_hydro_plants(scenario):
session = sessionmaker(bind=db.engine())()
for i, row in mastr_loc.iterrows():
entry = EgonPowerPlants(
sources={
"el_capacity": "MaStR scaled with NEP 2021",
},
sources={"el_capacity": "MaStR scaled with NEP 2021"},
source_id={"MastrNummer": row.EinheitMastrNummer},
carrier=carrier,
el_capacity=row.Nettonennleistung,
Expand Down Expand Up @@ -522,7 +518,7 @@ def assign_bus_id(power_plants, cfg):
ehv_grid_districts,
)

if 'bus_id_right' in ehv_join.columns:
if "bus_id_right" in ehv_join.columns:
power_plants.loc[power_plants_ehv, "bus_id"] = gpd.sjoin(
power_plants[power_plants.index.isin(power_plants_ehv)],
ehv_grid_districts,
Expand Down
6 changes: 5 additions & 1 deletion src/egon/data/datasets/power_plants/pv_rooftop.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pandas as pd

from egon.data import config, db
from egon.data.datasets.scenario_parameters import get_sector_parameters


def next_id(component):
Expand Down Expand Up @@ -199,7 +200,10 @@ def pv_rooftop_per_mv_grid(scenario="eGon2035", level="federal_state"):
}
).set_index("generator_id")

pv_rooftop = pv_rooftop.reset_index().set_index("generator_id")
pv_rooftop = pv_rooftop.set_index("generator_id")
pv_rooftop["marginal_cost"] = get_sector_parameters(
"electricity", "eGon2035"
)["marginal_cost"]["pv"]

# Insert data to database
pv_rooftop.to_sql(
Expand Down
2 changes: 1 addition & 1 deletion src/egon/data/datasets/saltcavern/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SaltcavernData(Dataset):
def __init__(self, dependencies):
super().__init__(
name="SaltcavernData",
version="0.0.0",
version="0.0.1",
dependencies=dependencies,
tasks=(to_postgres,),
)
Loading

0 comments on commit 20663ca

Please sign in to comment.