Skip to content

Commit

Permalink
Merge pull request #793 from openego/features/#779_eGon100RE_CH4_stor…
Browse files Browse the repository at this point in the history
…es_DE

Add CH4 stores in Germany for eGon100RE and adjust grid pipeline capcities (CH4 and H2)
  • Loading branch information
AmeliaNadal committed Jun 16, 2022
2 parents c0c70e8 + a81c213 commit 7863805
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 32 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,10 @@ Changed
`#735 <https://github.com/openego/eGon-data/issues/735>`_
* Improve CH4 stores and productions aggregation by removing dedicated task
`#PR775 <https://github.com/openego/eGon-data/pull/775>`_
* Add CH4 stores in Germany for eGon100RE
`#779 <https://github.com/openego/eGon-data/issues/779>`_
* Assigment of H2 and CH4 capacitites for pipelines in eGon100RE
`#686 <https://github.com/openego/eGon-data/issues/686>`_
* Update deposit id to access v0.8 of the zenodo repository
`#760 <https://github.com/openego/eGon-data/issues/760>`_
* Add primary key to table openstreetmap.osm_ways_with_segments
Expand Down
40 changes: 33 additions & 7 deletions src/egon/data/datasets/ch4_storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ch4_nodes_number_G,
define_gas_nodes_list,
)
from egon.data.datasets.scenario_parameters import get_sector_parameters


class CH4Storages(Dataset):
Expand All @@ -26,7 +27,7 @@ def __init__(self, dependencies):
name="CH4Storages",
version="0.0.2",
dependencies=dependencies,
tasks=(import_ch4_storages),
tasks=(insert_ch4_storages),
)


Expand Down Expand Up @@ -182,27 +183,41 @@ def import_ch4_grid_capacity(scn_name):
Gas_storages_list = db.select_geodataframe(sql_gas, epsg=4326)

# Add missing column
Gas_storages_list["e_nom"] = Store_capacity
Gas_storages_list["bus"] = Gas_storages_list["bus_id"]
if scn_name == "eGon100RE":
Gas_storages_list["e_nom"] = Store_capacity * (
1
- get_sector_parameters("gas", scn_name)[
"retrofitted_CH4pipeline-to-H2pipeline_share"
]
)
else:
Gas_storages_list["e_nom"] = Store_capacity

# Remove useless columns
Gas_storages_list = Gas_storages_list.drop(columns=["bus_id", "geom"])

return Gas_storages_list


def import_ch4_storages():
"""Insert list of gas storages units in database"""
def insert_ch4_stores(scn_name):
"""Insert gas stores for specific scenario
Parameters
----------
scn_name : str
Name of the scenario.
Returns
----
None"""

# Connect to local database
engine = db.engine()

# Select target from dataset configuration
source = config.datasets()["gas_stores"]["source"]
target = config.datasets()["gas_stores"]["target"]

# TODO move this to function call, how to do it is directly called in task list?
scn_name = "eGon2035"

# Clean table
db.execute_sql(
f"""
Expand Down Expand Up @@ -244,3 +259,14 @@ def import_ch4_storages():
index=False,
if_exists="append",
)


def insert_ch4_storages():
"""Overall function for importing the gas stores for both scenarios
Returns
-------
None.
"""
insert_ch4_stores("eGon2035")
insert_ch4_stores("eGon100RE")
67 changes: 61 additions & 6 deletions src/egon/data/datasets/gas_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
from egon.data.config import settings
from egon.data.datasets import Dataset
from egon.data.datasets.electrical_neighbours import central_buses_egon100
from egon.data.datasets.etrago_helpers import (
copy_and_modify_buses,
copy_and_modify_links,
)
from egon.data.datasets.etrago_helpers import copy_and_modify_buses
from egon.data.datasets.scenario_parameters import get_sector_parameters


class GasNodesandPipes(Dataset):
def __init__(self, dependencies):
super().__init__(
name="GasNodesandPipes",
version="0.0.5",
version="0.0.6",
dependencies=dependencies,
tasks=(insert_gas_data, insert_gas_data_eGon100RE),
)
Expand Down Expand Up @@ -732,5 +729,63 @@ def insert_gas_data_eGon100RE():
-------
None.
"""
# copy buses
copy_and_modify_buses("eGon2035", "eGon100RE", {"carrier": ["CH4"]})
copy_and_modify_links("eGon2035", "eGon100RE", ["CH4"], "gas")

# get CH4 pipelines and modify their nominal capacity with the
# retrofitting factor
gdf = db.select_geodataframe(
f"""
SELECT * FROM grid.egon_etrago_link
WHERE carrier = 'CH4' AND scn_name = 'eGon2035' AND
bus0 IN (
SELECT bus_id FROM grid.egon_etrago_bus
WHERE scn_name = 'eGon2035' AND country = 'DE'
) AND bus1 IN (
SELECT bus_id FROM grid.egon_etrago_bus
WHERE scn_name = 'eGon2035' AND country = 'DE'
);
""",
epsg=4326,
geom_col="topo",
)

# Update scenario specific information
scn_name = "eGon100RE"
gdf["scn_name"] = scn_name
scn_params = get_sector_parameters("gas", scn_name)

for param in ["capital_cost", "marginal_cost", "efficiency"]:
try:
gdf.loc[:, param] = scn_params[param]["CH4"]
except KeyError:
pass

# remaining CH4 share is 1 - retroffited pipeline share
gdf["p_nom"] *= (
1 - scn_params["retrofitted_CH4pipeline-to-H2pipeline_share"]
)

# delete old entries
db.execute_sql(
f"""
DELETE FROM grid.egon_etrago_link
WHERE carrier = 'CH4' AND scn_name = '{scn_name}' AND
bus0 NOT IN (
SELECT bus_id FROM grid.egon_etrago_bus
WHERE scn_name = '{scn_name}' AND country != 'DE'
) AND bus1 NOT IN (
SELECT bus_id FROM grid.egon_etrago_bus
WHERE scn_name = '{scn_name}' AND country != 'DE'
);
"""
)

gdf.to_postgis(
"egon_etrago_link",
schema="grid",
if_exists="append",
con=db.engine(),
index=False,
dtype={"geom": Geometry(), "topo": Geometry()},
)
2 changes: 1 addition & 1 deletion src/egon/data/datasets/hydrogen_etrago/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class HydrogenGridEtrago(Dataset):
def __init__(self, dependencies):
super().__init__(
name="HydrogenGridEtrago",
version="0.0.0",
version="0.0.1",
dependencies=dependencies,
tasks=(insert_h2_pipelines,),
)
44 changes: 39 additions & 5 deletions src/egon/data/datasets/hydrogen_etrago/h2_grid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""The central module containing all code dealing with heat sector in etrago
"""
from geoalchemy2.types import Geometry
from shapely.geometry import MultiLineString
import geopandas as gpd

from egon.data import db
Expand Down Expand Up @@ -43,7 +44,15 @@ def insert_h2_pipelines():
scn_params = get_sector_parameters("gas", "eGon100RE")

pipelines["carrier"] = "H2_retrofit"
pipelines["p_nom"] *= 0.6 # capacity retrofitting factor
# the volumetric energy density of pure H2 at 50 bar vs. pure CH4 at
# 50 bar is at about 30 %, however due to less friction volumetric flow can
# be increased for pure H2 leading to higher capacities. Data for both
# the retriffiting share and the capacity factor are obtained from the
# scenario parameters
pipelines["p_nom"] *= (
scn_params["retrofitted_CH4pipeline-to-H2pipeline_share"]
* scn_params["retrofitted_capacity_share"]
)
# map pipeline buses
pipelines["bus0"] = CH4_H2_busmap.loc[pipelines["bus0"], "bus_H2"].values
pipelines["bus1"] = CH4_H2_busmap.loc[pipelines["bus1"], "bus_H2"].values
Expand Down Expand Up @@ -74,6 +83,10 @@ def insert_h2_pipelines():
new_pipelines = link_geom_from_buses(
new_pipelines[["bus0", "bus1"]], "eGon2035"
)
new_pipelines["geom"] = new_pipelines.apply(
lambda row: MultiLineString([row["topo"]]), axis=1
)
new_pipelines = new_pipelines.set_geometry("geom", crs=4326)
new_pipelines["carrier"] = "H2_gridextension"
new_pipelines["scn_name"] = "eGon100RE"
new_pipelines["p_nom_extendable"] = True
Expand Down Expand Up @@ -118,11 +131,32 @@ def insert_h2_pipelines():
new_id = db.next_etrago_id("link")
new_pipelines["link_id"] = range(new_id, new_id + len(new_pipelines))

new_pipelines.to_crs(epsg=4326).to_postgis(
"egon_etrago_link",
new_pipelines.to_postgis(
"egon_etrago_h2_link",
engine,
schema="grid",
index=False,
if_exists="append",
dtype={"topo": Geometry()},
if_exists="replace",
dtype={"geom": Geometry(), "topo": Geometry()},
)

db.execute_sql(
"""
select UpdateGeometrySRID('grid', 'egon_etrago_h2_link', 'topo', 4326) ;
INSERT INTO grid.egon_etrago_link (scn_name,
link_id, carrier,
bus0, bus1,
p_nom_extendable, length,
geom, topo)
SELECT scn_name,
link_id, carrier,
bus0, bus1,
p_nom_extendable, length,
geom, topo
FROM grid.egon_etrago_h2_link;
DROP TABLE grid.egon_etrago_h2_link;
"""
)
25 changes: 13 additions & 12 deletions src/egon/data/datasets/scenario_parameters/__init__.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"""The central module containing all code dealing with scenario table.
"""
from egon.data import db
from sqlalchemy import Column, String, VARCHAR
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.postgresql import JSONB
import pandas as pd
import egon.data.datasets.scenario_parameters.parameters as parameters
from egon.data.datasets import Dataset
from pathlib import Path
from urllib.request import urlretrieve
import shutil
import zipfile

from sqlalchemy import VARCHAR, Column, String
from sqlalchemy.dialects.postgresql import JSONB
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
import pandas as pd

from egon.data import db
from egon.data.datasets import Dataset
import egon.data.config
from pathlib import Path
import shutil
import egon.data.datasets.scenario_parameters.parameters as parameters

Base = declarative_base()

Expand Down Expand Up @@ -105,7 +106,7 @@ def insert_scenarios():


def get_sector_parameters(sector, scenario=None):
""" Returns parameters for each sector as dictionary.
"""Returns parameters for each sector as dictionary.
If scenario=None data for all scenarios is returned as pandas.DataFrame.
Otherwise the parameters of the specific scenario are returned as a dict.
Expand Down Expand Up @@ -190,7 +191,7 @@ class ScenarioParameters(Dataset):
def __init__(self, dependencies):
super().__init__(
name="ScenarioParameters",
version="0.0.8",
version="0.0.9",
dependencies=dependencies,
tasks=(
create_table,
Expand Down
13 changes: 12 additions & 1 deletion src/egon/data/datasets/scenario_parameters/parameters.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,18 @@ def gas(scenario):

costs = read_csv(2050)

parameters = {"main_gas_carrier": "H2"}
parameters = {
"main_gas_carrier": "H2",
"retrofitted_CH4pipeline-to-H2pipeline_share": 0.75,
# The H2 network will be based on 75% of converted natural gas pipelines.
# https://gasforclimate2050.eu/wp-content/uploads/2020/07/2020_European-Hydrogen-Backbone_Report.pdf
# This value is used temporary, later on we will use the result of p-e-s
"retrofitted_capacity_share": 0.8,
# The volumetric energy density of pure H2 at 50 bar vs. pure CH4 at
# 50 bar is at about 30 %, however due to less friction volumetric flow can
# be increased for pure H2 leading to higher capacities
# https://gasforclimate2050.eu/wp-content/uploads/2020/07/2020_European-Hydrogen-Backbone_Report.pdf p.10
}
# Insert effciencies in p.u.
parameters["efficiency"] = {
"power_to_H2": read_costs(costs, "electrolysis", "efficiency"),
Expand Down

0 comments on commit 7863805

Please sign in to comment.