Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gas sanity checks eGon100RE #1129

Open
wants to merge 31 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e15b0aa
Update CHANGELOG
Dec 14, 2022
e57797e
Create new functions reused in sanity_checks
Dec 14, 2022
db0ae44
Add sanity checks for gas in Germany in eGon2035
Dec 14, 2022
241b915
Format documentation
Dec 14, 2022
9b33d5a
Separate definition and insertion in the DB of abroad gas buses
Dec 19, 2022
4ea1031
New imports and apply isort
AmeliaNadal Dec 29, 2022
e78faea
Complete sanity checks of gas buses
AmeliaNadal Dec 29, 2022
543ea5a
Add functions sanity_check_gas_one_port and sanity_check_gas_links
AmeliaNadal Dec 29, 2022
5f7f388
Add sanity checks for gas abroad
AmeliaNadal Dec 29, 2022
09a922f
Correct typo and formating
AmeliaNadal Dec 29, 2022
ef8eb38
Increase dataset version
AmeliaNadal Dec 29, 2022
030d27e
Merge branch 'dev' into features/#864_gas_sanity_checks_eGon2035
AmeliaNadal Feb 1, 2023
91acb66
Add sanity checks abroads
AmeliaNadal Feb 1, 2023
fd246f6
Correct typo
AmeliaNadal Feb 1, 2023
3ee36a8
Remove f-string without interpolation
AmeliaNadal Feb 10, 2023
e9d3c5c
Adapt sanity check to account for changes of PR #1101
AmeliaNadal Feb 10, 2023
6185d1f
Merge branch 'dev' into features/#864_gas_sanity_checks_eGon2035
AmeliaNadal Feb 10, 2023
84b9be5
Bypass SSL verification
AmeliaNadal Feb 14, 2023
6924eaa
Update CHANGELOG
AmeliaNadal Feb 15, 2023
cee7f9f
Increase dataset version
AmeliaNadal Feb 15, 2023
6f135eb
Merge branch 'features/#864_gas_sanity_checks_eGon2035' into features…
AmeliaNadal Feb 20, 2023
e901673
Update CHANGELOG
AmeliaNadal Feb 20, 2023
cf580eb
Isolate calculation of global industrial gas demand
AmeliaNadal Feb 20, 2023
d7a3eea
Increase dataset version
AmeliaNadal Feb 20, 2023
cf9464b
Insert first gas sanity checks for eGon100RE
AmeliaNadal Feb 20, 2023
d97f693
Generalize sanity checks for gas generators
AmeliaNadal Feb 20, 2023
514b164
Add additional checks for gas sector in Germany
AmeliaNadal Feb 21, 2023
3c4e7bc
Merge branch 'fixes/#1102_TYNDP_url' into features/#1067-gas_sanitych…
AmeliaNadal Feb 21, 2023
c2b32cf
Merge branch 'dev' into features/#1067-gas_sanitycheck_eGon100RE
AmeliaNadal Mar 27, 2023
aaf5aa9
Merge branch 'dev' into features/#1067-gas_sanitycheck_eGon100RE
AmeliaNadal Mar 31, 2023
79f3fea
Increase dataset version
AmeliaNadal Mar 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,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 All @@ -484,6 +486,8 @@ Changed
created for a single process. This fixes issue `#799`_.
* Insert rural heat per supply technology
`#1026 <https://github.com/openego/eGon-data/issues/1026>`_
* Add sanity checks for gas sector in eGon100RE
`#1067 <https://github.com/openego/eGon-data/issues/1067>`_
* Change hgv data source to use database
`#1086 <https://github.com/openego/eGon-data/issues/1086>`_
* Rename eMob MIT carrier names (use underscores)
Expand Down Expand Up @@ -724,6 +728,8 @@ Bug Fixes
* Fix URL of TYNDP scenario dataset
* Automatically generated tasks now get unique :code:`task_id`\s.
Fixes issue `#985`_ via PR `#986`_.
* Bypass SSL verification
`#1102 <https://github.com/openego/eGon-data/issues/1102>`_
* Fix faulty DSM time series
`#1088 <https://github.com/openego/eGon-data/issues/1088>`_
* Set upper limit on commissioning date for units from MaStR
Expand Down
128 changes: 93 additions & 35 deletions src/egon/data/datasets/gas_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,27 +293,28 @@ def insert_CH4_nodes_list(gas_nodes_list):
dtype={"geom": Geometry()},
)


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 +330,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 +388,45 @@ 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 +440,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 +473,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 +483,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 +799,6 @@ def insert_gas_pipeline_list(
"NUTS1_0",
"NUTS1_1",
"country_code",
"country_0",
"country_1",
"diameter",
"pipe_class",
"classification",
Expand All @@ -783,6 +809,35 @@ 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 in 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 +933,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
5 changes: 5 additions & 0 deletions src/egon/data/datasets/gas_neighbours/eGon2035.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pathlib import Path
from urllib.request import urlretrieve
import ast
import ssl
import zipfile

from shapely.geometry import LineString, MultiLineString
Expand Down Expand Up @@ -1122,7 +1123,11 @@ def calculate_ch4_grid_capacities():
url = "https://www.entsog.eu/sites/default/files/2021-07/" + basename
target_file = Path(".") / "datasets" / "gas_data" / basename

context_backup = ssl._create_default_https_context
ssl._create_default_https_context = ssl._create_unverified_context
urlretrieve(url, target_file)
ssl._create_default_https_context = context_backup

map_pipelines = {
"NORDSTREAM": "RU00",
"NORDSTREAM 2": "RU00",
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
8 changes: 7 additions & 1 deletion src/egon/data/datasets/hydrogen_etrago/storage.py
Original file line number Diff line number Diff line change
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,14 @@ 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
Loading