Skip to content

Commit

Permalink
Merge pull request #1068 from openego/features/#864_gas_sanity_checks…
Browse files Browse the repository at this point in the history
…_eGon2035

Features/#864 gas sanity checks eGon2035
  • Loading branch information
IlkaCu committed Jun 30, 2023
2 parents 733e9e4 + 8a8d9eb commit 770207c
Show file tree
Hide file tree
Showing 6 changed files with 1,037 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,8 @@ Changed
`#519 <https://github.com/openego/eGon-data/issues/519>`_
* Add missing VOM costs for heat sector components
`#942 <https://github.com/openego/eGon-data/issues/942>`_
* Add sanity checks for gas sector in eGon2035
`#864 <https://github.com/openego/eGon-data/issues/864>`_
* Desaggregate industry demands to OSM areas and industrial sites
`#1001 <https://github.com/openego/eGon-data/issues/1001>`_
* Add gas generator in Norway
Expand Down
125 changes: 91 additions & 34 deletions src/egon/data/datasets/gas_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,26 +294,28 @@ def insert_CH4_nodes_list(gas_nodes_list):
)


def insert_gas_buses_abroad(scn_name="eGon2035"):
def define_gas_buses_abroad(scn_name="eGon2035"):
"""
Insert CH4 buses in neighbouring countries to database for eGon2035
Define central CH4 buses in foreign countries for eGon2035
For the scenario eGon2035, insert central CH4 buses in foreign
countries to the database. The considered foreign countries are the
direct neighbouring countries, with the addition of Russia that is
For the scenario eGon2035, define central CH4 buses in foreign
countries. The considered foreign countries are the direct
neighbouring countries, with the addition of Russia that is
considered as a source of fossil CH4.
Therefore, the following steps are executed:
* Definition of the foreign buses with the function
:py:func:`import_central_buses_egon100 <egon.data.datasets.electrical_neighbours.central_buses_egon100>` from
:py:func:`central_buses_egon100 <egon.data.datasets.electrical_neighbours.central_buses_egon100>` from
the module :py:mod:`electrical_neighbours <egon.data.datasets.electrical_neighbours>`
* Removal of the superfluous buses in order to have only one bus
in each neighbouring country
* Removal of the the irrelevant columns
* Addition of the missing information: scn_name and carrier
* Attribution of an id to each bus
* Cleaning of the database table grid.egon_etrago_bus of the
CH4 buses of the specific scenario (eGon2035) out of Germany
* Insertion of the neighbouring buses in the table grid.egon_etrago_bus.
Parameters
----------
scn_name : str
Name of the scenario
Returns
-------
Expand All @@ -329,15 +331,6 @@ def insert_gas_buses_abroad(scn_name="eGon2035"):
"main_gas_carrier"
]

# Connect to local database
engine = db.engine()
db.execute_sql(
f"""
DELETE FROM grid.egon_etrago_bus WHERE "carrier" = '{main_gas_carrier}' AND
scn_name = '{scn_name}' AND country != 'DE';
"""
)

# Select the foreign buses
gdf_abroad_buses = central_buses_egon100(sources)
gdf_abroad_buses = gdf_abroad_buses.drop_duplicates(subset=["country"])
Expand Down Expand Up @@ -396,6 +389,46 @@ def insert_gas_buses_abroad(scn_name="eGon2035"):
columns={"geometry": "geom"}
).set_geometry("geom", crs=4326)

return gdf_abroad_buses


def insert_gas_buses_abroad(scn_name="eGon2035"):
"""
Insert CH4 buses in neighbouring countries to database for eGon2035
* Definition of the CH4 buses abroad with the function
:py:func:`define_gas_buses_abroad`
* Cleaning of the data base table grid.egon_etrago_bus of the
CH4 buses of the specific scenario (eGon2035) out of Germany
* Insertion of the neighbouring buses in the table grid.egon_etrago_bus.
Parameters
----------
scn_name : str
Name of the scenario
Returns
-------
gdf_abroad_buses : dataframe
Dataframe containing the CH4 buses in the neighbouring countries
and one in the center of Germany in test mode
"""
main_gas_carrier = get_sector_parameters("gas", scenario=scn_name)[
"main_gas_carrier"
]

# Connect to local database
engine = db.engine()
db.execute_sql(
f"""
DELETE FROM grid.egon_etrago_bus WHERE "carrier" = '{main_gas_carrier}' AND
scn_name = '{scn_name}' AND country != 'DE';
"""
)

gdf_abroad_buses = define_gas_buses_abroad(scn_name)

# Insert to db
print(gdf_abroad_buses)
gdf_abroad_buses.to_postgis(
Expand All @@ -409,28 +442,26 @@ def insert_gas_buses_abroad(scn_name="eGon2035"):
return gdf_abroad_buses


def insert_gas_pipeline_list(
def define_gas_pipeline_list(
gas_nodes_list, abroad_gas_nodes_list, scn_name="eGon2035"
):
"""
Insert list of gas pipelines into the database
Define gas pipelines in Germany from SciGRID_gas IGGIELGN data
The gas pipelines, modelled as Pypsa links are red from the IGGIELGN_PipeSegments
csv file previously downloded in the function :py:func:`download_SciGRID_gas_data`,
adapted and inserted in the database for the eGon2035 scenario.
The manual corrections allows to:
* Delete gas pipelines disconnected of the rest of the gas grid
* Connect one pipeline (also connected to Norway) disconnected of
the rest of the gas grid
* Correct erroneous country of some pipelines
csv file previously downloded in the function :py:func:`download_SciGRID_gas_data`.
The capacities of the pipelines are determined by the correspondance
table given by the Parameters for the classification of gas pipelines
in `Electricity, heat, and gas sector data for modeling the German system
<https://www.econstor.eu/bitstream/10419/173388/1/1011162628.pdf>`_
related to the pipeline diameter given in the SciGRID_gas dataset.
The database is cleaned before the insertion of the pipelines.
The manual corrections allows to:
* Delete gas pipelines disconnected of the rest of the gas grid
* Connect one pipeline (also connected to Norway) disconnected of
the rest of the gas grid
* Correct erroneous country of some pipelines
Parameters
----------
Expand All @@ -444,7 +475,8 @@ def insert_gas_pipeline_list(
Returns
-------
None
gas_pipelines_list : pandas.DataFrame
Dataframe containing the gas pipelines in Germany
"""
abroad_gas_nodes_list = abroad_gas_nodes_list.set_index("country")
Expand All @@ -453,8 +485,6 @@ def insert_gas_pipeline_list(
"main_gas_carrier"
]

engine = db.engine()

# Select next id value
new_id = db.next_etrago_id("link")

Expand Down Expand Up @@ -771,8 +801,6 @@ def insert_gas_pipeline_list(
"NUTS1_0",
"NUTS1_1",
"country_code",
"country_0",
"country_1",
"diameter",
"pipe_class",
"classification",
Expand All @@ -783,6 +811,32 @@ def insert_gas_pipeline_list(
]
)

return gas_pipelines_list


def insert_gas_pipeline_list(gas_pipelines_list, scn_name="eGon2035"):
"""
Insert list of gas pipelines into the database
Receive as argument a list of gas pipelines and insert them into the
data base after cleaning it.
Parameters
----------
gas_pipelines_list : pandas.DataFrame
Dataframe containing the gas pipelines in Germany
scn_name : str
Name of the scenario
"""
main_gas_carrier = get_sector_parameters("gas", scenario=scn_name)[
"main_gas_carrier"
]
engine = db.engine()
gas_pipelines_list = gas_pipelines_list.drop(
columns=["country_0", "country_1"]
)

# Clean db
db.execute_sql(
f"""DELETE FROM grid.egon_etrago_link
Expand Down Expand Up @@ -878,7 +932,10 @@ def insert_gas_data():
insert_CH4_nodes_list(gas_nodes_list)
abroad_gas_nodes_list = insert_gas_buses_abroad()

insert_gas_pipeline_list(gas_nodes_list, abroad_gas_nodes_list)
gas_pipeline_list = define_gas_pipeline_list(
gas_nodes_list, abroad_gas_nodes_list
)
insert_gas_pipeline_list(gas_pipeline_list)
remove_isolated_gas_buses()


Expand Down
2 changes: 1 addition & 1 deletion src/egon/data/datasets/gas_neighbours/gas_abroad.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def insert_gas_grid_capacities(Neighbouring_pipe_capacities_list, scn_name):
For eGon2035, all the CH4 crossbordering pipelines are inserted
there (no H2 grid in this scenario).
For eGon100RE, only the the crossbordering pipelines with Germany
are inserted there (the other ones are inerted in PypsaEurSec),
are inserted there (the other ones are inserted in PypsaEurSec),
but in this scenario there are H2 and CH4 pipelines.
Parameters
Expand Down
4 changes: 2 additions & 2 deletions src/egon/data/datasets/hydrogen_etrago/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
insert_power_to_h2_to_power_eGon100RE,
)
from egon.data.datasets.hydrogen_etrago.storage import (
calculate_and_map_saltcavern_storage_potential,
insert_H2_overground_storage,
insert_H2_saltcavern_storage,
insert_H2_storage_eGon100RE,
write_saltcavern_potential,
)


Expand Down Expand Up @@ -67,7 +67,7 @@ def __init__(self, dependencies):
version=self.version,
dependencies=dependencies,
tasks=(
calculate_and_map_saltcavern_storage_potential,
write_saltcavern_potential,
insert_hydrogen_buses,
insert_hydrogen_buses_eGon100RE,
),
Expand Down
11 changes: 9 additions & 2 deletions src/egon/data/datasets/hydrogen_etrago/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def insert_H2_saltcavern_storage(scn_name="eGon2035"):
f"""
SELECT *
FROM {sources['H2_AC_map']['schema']}.
{sources['H2_AC_map']['table']}""",
{sources['H2_AC_map']['table']}"""
)

storage_potentials["storage_potential"] = (
Expand Down Expand Up @@ -188,7 +188,6 @@ def calculate_and_map_saltcavern_storage_potential():

# select onshore vg250 data
sources = config.datasets()["bgr"]["sources"]
targets = config.datasets()["bgr"]["targets"]
vg250_data = db.select_geodataframe(
f"""SELECT * FROM
{sources['vg250_federal_states']['schema']}.
Expand Down Expand Up @@ -366,7 +365,15 @@ def calculate_and_map_saltcavern_storage_potential():
epsg=25832
).area / potential_areas.groupby("gen")["shape_star"].transform("sum")

return potential_areas


def write_saltcavern_potential():
"""Write saltcavern potentials in the database"""
potential_areas = calculate_and_map_saltcavern_storage_potential()

# write information to saltcavern data
targets = config.datasets()["bgr"]["targets"]
potential_areas.to_crs(epsg=4326).to_postgis(
targets["storage_potential"]["table"],
db.engine(),
Expand Down

0 comments on commit 770207c

Please sign in to comment.