Skip to content

Commit

Permalink
Merge branch 'features/#864_gas_sanity_checks_eGon2035' into features/#…
Browse files Browse the repository at this point in the history
…1067-gas_sanitycheck_eGon100RE
  • Loading branch information
AmeliaNadal committed Feb 20, 2023
2 parents da19662 + 6185d1f commit 6f135eb
Show file tree
Hide file tree
Showing 6 changed files with 1,018 additions and 28 deletions.
2 changes: 2 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 Down
96 changes: 74 additions & 22 deletions src/egon/data/datasets/gas_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,10 @@ def insert_CH4_nodes_list(gas_nodes_list):
dtype={"geom": Geometry()},
)

def define_gas_buses_abroad(scn_name="eGon2035"):
"""Define central CH4 buses in foreign countries for eGon2035
def insert_gas_buses_abroad(scn_name="eGon2035"):
"""Insert central CH4 buses in foreign countries for eGon2035
Detailled description to be completed:
Insert central gas buses in foreign countries to db, same buses
Define central gas buses in foreign countries to db, same buses
than the foreign AC buses
Parameters
Expand All @@ -241,6 +239,7 @@ def insert_gas_buses_abroad(scn_name="eGon2035"):
gdf_abroad_buses : dataframe
Dataframe containing the CH4 buses in the neighbouring countries
and one in the center of Germany in test mode
"""
# Select sources and targets from dataset configuration
sources = config.datasets()["electrical_neighbours"]["sources"]
Expand All @@ -249,15 +248,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 @@ -316,6 +306,41 @@ 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 central CH4 buses in foreign countries for eGon2035
Insert central gas buses in foreign countries to db, same buses
than the foreign AC buses
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 @@ -329,10 +354,10 @@ 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 from SciGRID_gas IGGIELGN data
"""Define gas pipelines in Germany from SciGRID_gas IGGIELGN data
Insert detailled description
Expand All @@ -347,7 +372,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 @@ -356,8 +382,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 @@ -674,8 +698,6 @@ def insert_gas_pipeline_list(
"NUTS1_0",
"NUTS1_1",
"country_code",
"country_0",
"country_1",
"diameter",
"pipe_class",
"classification",
Expand All @@ -686,6 +708,33 @@ 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
Insert detailled description
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 @@ -766,7 +815,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 @@ -15,10 +15,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 All @@ -29,7 +29,7 @@ def __init__(self, dependencies):
version="0.0.1",
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
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,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 @@ -337,7 +336,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

0 comments on commit 6f135eb

Please sign in to comment.