Skip to content

Commit

Permalink
Merge pull request #1118 from openego/features/#450-metadata_gas
Browse files Browse the repository at this point in the history
Add metadata for gas voronois and gas mapping tables
  • Loading branch information
AmeliaNadal authored Mar 17, 2023
2 parents 3bcdd78 + 3642f3b commit a65f9b0
Show file tree
Hide file tree
Showing 2 changed files with 265 additions and 5 deletions.
81 changes: 80 additions & 1 deletion src/egon/data/datasets/gas_areas.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
"""The central module containing code to create CH4 and H2 voronoi polygons
"""
import datetime
import json

from geoalchemy2.types import Geometry
from sqlalchemy import BigInteger, Column, Text
from sqlalchemy.ext.declarative import declarative_base

from egon.data import db
from egon.data.datasets import Dataset
from egon.data.datasets.generate_voronoi import get_voronoi_geodataframe
from egon.data.metadata import (
context,
contributors,
license_egon_data_odbl,
meta_metadata,
sources,
)


class GasAreaseGon2035(Dataset):
Expand All @@ -34,8 +44,77 @@ def __init__(self, dependencies):


class EgonPfHvGasVoronoi(Base):
source_list = [
sources()["openstreetmap"],
sources()["SciGRID_gas"],
sources()["bgr_inspeeds_data_bundle"],
]
meta = {
"name": "grid.egon_gas_voronoi",
"title": "Gas voronoi areas",
"id": "WILL_BE_SET_AT_PUBLICATION",
"description": "H2 and CH4 voronoi cells",
"language": ["en-EN"],
"publicationDate": datetime.date.today().isoformat(),
"context": context(),
"spatial": {
"location": None,
"extent": "Germany",
"resolution": None,
},
"sources": source_list,
"licenses": [license_egon_data_odbl()],
"contributors": contributors(["fw"]),
"resources": [
{
"profile": "tabular-data-resource",
"name": "grid.egon_gas_voronoi",
"path": None,
"format": "PostgreSQL",
"encoding": "UTF-8",
"schema": {
"fields": [
{
"name": "scn_name",
"description": "Name of the scenario",
"type": "str",
"unit": None,
},
{
"name": "bus_id",
"description": "Unique identifier",
"type": "integer",
"unit": None,
},
{
"name": "carrier",
"description": "Carrier of the voronoi cell",
"type": "str",
"unit": None,
},
{
"name": "geom",
"description": "Voronoi cell geometry",
"type": "Geometry(Polygon, 4326)",
"unit": None,
},
],
"primaryKey": ["scn_name", "bus_id"],
"foreignKeys": [],
},
"dialect": {"delimiter": None, "decimalSeparator": "."},
}
],
"metaMetadata": meta_metadata(),
}
# Create json dump
meta_json = "'" + json.dumps(meta, indent=4, ensure_ascii=False) + "'"

__tablename__ = "egon_gas_voronoi"
__table_args__ = {"schema": "grid"}
__table_args__ = {
"schema": "grid",
"comment": meta_json,
}

scn_name = Column(Text, primary_key=True, nullable=False)
bus_id = Column(BigInteger, primary_key=True, nullable=False)
Expand Down
189 changes: 185 additions & 4 deletions src/egon/data/datasets/hydrogen_etrago/bus.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
"""The central module containing all code dealing with heat sector in etrago
"""
import datetime
import json

from geoalchemy2 import Geometry
from sqlalchemy import BigInteger, Column, Text
from sqlalchemy.ext.declarative import declarative_base

from egon.data import config, db
from egon.data.datasets.etrago_helpers import (
copy_and_modify_buses,
finalize_bus_insertion,
initialise_bus_insertion,
)
from egon.data.metadata import (
context,
contributors,
license_egon_data_odbl,
meta_metadata,
sources,
)


def insert_hydrogen_buses(scenario="eGon2035"):
""" Insert hydrogen buses to etrago table
"""Insert hydrogen buses to etrago table
Hydrogen buses are divided into cavern and methane grid attached buses
Expand Down Expand Up @@ -40,6 +51,89 @@ def insert_hydrogen_buses(scenario="eGon2035"):
insert_H2_buses_from_CH4_grid(hydrogen_buses, carrier, target, scenario)


Base = declarative_base()


class EgonMapACH2(Base):
source_list = [
sources()["openstreetmap"],
sources()["SciGRID_gas"],
sources()["bgr_inspeeds_data_bundle"],
]
meta_ac_h2 = {
"name": "grid.egon_etrago_ac_h2",
"title": "Mapping table of AC-H2 buses",
"id": "WILL_BE_SET_AT_PUBLICATION",
"description": "Table mapping AC and H2 buses in Germany",
"language": ["en-EN"],
"publicationDate": datetime.date.today().isoformat(),
"context": context(),
"spatial": {
"location": None,
"extent": "Germany",
"resolution": None,
},
"sources": source_list,
"licenses": [license_egon_data_odbl()],
"contributors": contributors(["fw"]),
"resources": [
{
"profile": "tabular-data-resource",
"name": "grid.egon_etrago_ac_h2",
"path": None,
"format": "PostgreSQL",
"encoding": "UTF-8",
"schema": {
"fields": [
{
"name": "scn_name",
"description": "Name of the scenario",
"type": "str",
"unit": None,
},
{
"name": "bus_H2",
"description": "H2 bus_id",
"type": "integer",
"unit": None,
},
{
"name": "bus_AC",
"description": "AC bus_id",
"type": "integer",
"unit": None,
},
],
"primaryKey": ["scn_name", "bus_H2"],
"foreignKeys": [],
},
"dialect": {"delimiter": None, "decimalSeparator": "."},
}
],
"metaMetadata": meta_metadata(),
}
# Create json dump
meta_json_ac_h2 = (
"'" + json.dumps(meta_ac_h2, indent=4, ensure_ascii=False) + "'"
)

__tablename__ = "egon_etrago_ac_h2"
__table_args__ = {
"schema": "grid",
"comment": meta_json_ac_h2,
}

scn_name = Column(Text, primary_key=True, nullable=False)
bus_H2 = Column(BigInteger, primary_key=True, nullable=False)
bus_AC = Column(BigInteger, primary_key=False, nullable=False)


def create_AC_H2_table():
engine = db.engine()
EgonMapACH2.__table__.drop(bind=engine, checkfirst=True)
EgonMapACH2.__table__.create(bind=engine, checkfirst=True)


def insert_H2_buses_from_saltcavern(gdf, carrier, sources, target, scn_name):
"""Insert the H2 buses based saltcavern locations to db.
Expand Down Expand Up @@ -93,15 +187,98 @@ def insert_H2_buses_from_saltcavern(gdf, carrier, sources, target, scn_name):
gdf_H2_cavern["bus_AC"] = AC_bus_ids
gdf_H2_cavern["scn_name"] = hydrogen_bus_ids["scn_name"]

create_AC_H2_table()

# Insert data to db
gdf_H2_cavern.to_sql(
"egon_etrago_ac_h2",
db.engine(),
schema="grid",
index=False,
if_exists="replace",
if_exists="append",
)


class EgonMapH2CH4(Base):
source_list = [
sources()["openstreetmap"],
sources()["SciGRID_gas"],
sources()["bgr_inspeeds_data_bundle"],
]
meta_H2_CH4 = {
"name": "grid.egon_etrago_ch4_h2",
"title": "Mapping table of CH4-H2 buses",
"id": "WILL_BE_SET_AT_PUBLICATION",
"description": "Table mapping CH4 and H2 buses in Germany",
"language": ["en-EN"],
"publicationDate": datetime.date.today().isoformat(),
"context": context(),
"spatial": {
"location": None,
"extent": "Germany",
"resolution": None,
},
"sources": source_list,
"licenses": [license_egon_data_odbl()],
"contributors": contributors(["fw"]),
"resources": [
{
"profile": "tabular-data-resource",
"name": "grid.egon_etrago_ch4_h2",
"path": None,
"format": "PostgreSQL",
"encoding": "UTF-8",
"schema": {
"fields": [
{
"name": "scn_name",
"description": "Name of the scenario",
"type": "str",
"unit": None,
},
{
"name": "bus_H2",
"description": "H2 bus_id",
"type": "integer",
"unit": None,
},
{
"name": "bus_CH4",
"description": "CH4 bus_id",
"type": "integer",
"unit": None,
},
],
"primaryKey": ["scn_name", "bus_H2"],
"foreignKeys": [],
},
"dialect": {"delimiter": None, "decimalSeparator": "."},
}
],
"metaMetadata": meta_metadata(),
}

# Create json dump
meta_json_H2_CH4 = (
"'" + json.dumps(meta_H2_CH4, indent=4, ensure_ascii=False) + "'"
)

__tablename__ = "egon_etrago_ch4_h2"
__table_args__ = {
"schema": "grid",
"comment": meta_json_H2_CH4,
}

scn_name = Column(Text, primary_key=True, nullable=False)
bus_H2 = Column(BigInteger, primary_key=True, nullable=False)
bus_CH4 = Column(BigInteger, primary_key=False, nullable=False)


def create_H2_CH4_table():
engine = db.engine()
EgonMapH2CH4.__table__.drop(bind=engine, checkfirst=True)
EgonMapH2CH4.__table__.create(bind=engine, checkfirst=True)


def insert_H2_buses_from_CH4_grid(gdf, carrier, target, scn_name):
"""Insert the H2 buses based on CH4 grid to db.
Expand Down Expand Up @@ -140,18 +317,22 @@ def insert_H2_buses_from_CH4_grid(gdf, carrier, target, scn_name):
gdf_H2_CH4["bus_CH4"] = CH4_bus_ids["bus_id"]
gdf_H2_CH4["scn_name"] = CH4_bus_ids["scn_name"]

create_H2_CH4_table()

# Insert data to db
gdf_H2_CH4.to_sql(
"egon_etrago_ch4_h2",
engine,
schema="grid",
index=False,
if_exists="replace",
if_exists="append",
)


def insert_hydrogen_buses_eGon100RE():
"""Copy H2 buses from the eGon2035 to the eGon100RE scenario."""
copy_and_modify_buses(
"eGon2035", "eGon100RE", {"carrier": ["H2_grid", "H2_saltcavern"]},
"eGon2035",
"eGon100RE",
{"carrier": ["H2_grid", "H2_saltcavern"]},
)

0 comments on commit a65f9b0

Please sign in to comment.