Skip to content

Commit

Permalink
Merge pull request #1027 from openego/features/#1026-add-rural-heat-a…
Browse files Browse the repository at this point in the history
…t-gas-nodes

Add loads of rural gas boilers for eGon2035
  • Loading branch information
ClaraBuettner committed Feb 2, 2023
2 parents 8ae202f + 73320d1 commit 7584924
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ Changed
* SQLAlchemy `engine` objects created via :code:`egon.data.db.engine`
are now cached on a per process basis, so only one `engine` is ever
created for a single process. This fixes issue `#799`_.
* Insert rural heat per supply technology
`#1026 <https://github.com/openego/eGon-data/issues/1026>`_

.. _#799: https://github.com/openego/eGon-data/issues/799

Expand Down
4 changes: 2 additions & 2 deletions src/egon/data/datasets/heat_demand_timeseries/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def create_district_heating_profile_python_like(scenario="eGon2035"):
)

assert (
abs(diff) < 0.02
abs(diff) < 0.03
), f"""Deviation of residential heat demand time
series for district heating grid {str(area)} is {diff}"""

Expand Down Expand Up @@ -739,7 +739,7 @@ def create_individual_heating_profile_python_like(scenario="eGon2035"):
) / (annual_demand[annual_demand.bus_id == grid].demand_total.sum())

assert (
abs(diff) < 0.02
abs(diff) < 0.03
), f"""Deviation of residential heat demand time
series for mv grid {str(grid)} is {diff}"""

Expand Down
3 changes: 1 addition & 2 deletions src/egon/data/datasets/heat_etrago/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,7 @@ def insert_store(scenario, carrier):

def store():
insert_store("eGon2035", "central_heat")
# Temporary drop everything related to rural heat
# insert_store("eGon2035", "rural_heat")
insert_store("eGon2035", "rural_heat")


def insert_central_direct_heat(scenario="eGon2035"):
Expand Down
102 changes: 78 additions & 24 deletions src/egon/data/datasets/heat_etrago/hts_etrago.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from egon.data import config, db
from egon.data.db import next_etrago_id
from egon.data.datasets import Dataset
from egon.data.datasets.heat_demand_timeseries import (
individual_heating_per_mv_grid_tables,
individual_heating_per_mv_grid_2035,
individual_heating_per_mv_grid_100,
)
from egon.data.datasets.scenario_parameters import get_sector_parameters

import pandas as pd
import numpy as np
Expand All @@ -16,9 +12,7 @@ def hts_to_etrago():
sources = config.datasets()["etrago_heat"]["sources"]
targets = config.datasets()["etrago_heat"]["targets"]
scenario = "eGon2035"
carriers = ["central_heat", "rural_heat"]
# Temporary drop everything related to rural heat
carriers = ["central_heat"]
carriers = ["central_heat", "rural_heat", "rural_gas_boiler"]

for carrier in carriers:
if carrier == "central_heat":
Expand Down Expand Up @@ -53,7 +47,7 @@ def hts_to_etrago():
bus_area, disct_time_series, on="area_id", how="inner"
)

else:
elif carrier == "rural_heat":
# interlinking heat_bus_id and mv_grid bus_id
bus_sub = db.select_dataframe(
f"""
Expand All @@ -79,10 +73,11 @@ def hts_to_etrago():
# individual heating time series
ind_time_series = db.select_dataframe(
f"""
SELECT * FROM
demand.egon_etrago_timeseries_individual_heating
WHERE scenario ='{scenario}'
"""
SELECT scenario, bus_id, dist_aggregated_mw FROM
demand.egon_etrago_timeseries_individual_heating
WHERE scenario ='{scenario}'
AND carrier = 'heat_pump'
"""
)

# bus_id connected to corresponding time series
Expand All @@ -93,6 +88,73 @@ def hts_to_etrago():
# Connect heat loads to heat buses
bus_ts.loc[:, "bus_id"] = bus_ts.loc[:, "heat_bus_id"]

else:

efficiency_gas_boiler = get_sector_parameters("heat", "eGon2035")[
"efficiency"
]["rural_gas_boiler"]

# Select rural heat demand coverd by individual gas boilers
ind_time_series = db.select_dataframe(
f"""
SELECT * FROM
demand.egon_etrago_timeseries_individual_heating
WHERE scenario ='{scenario}'
AND carrier = 'CH4'
"""
)

# Select geoetry of medium voltage grid districts
mvgd_geom = db.select_geodataframe(
f"""
SELECT bus_id, ST_CENTROID(geom) as geom FROM
{sources['egon_mv_grid_district']['schema']}.
{sources['egon_mv_grid_district']['table']}
"""
)

# Select geometry of gas (CH4) voronoi
gas_voronoi = db.select_geodataframe(
f"""
SELECT bus_id, geom FROM
grid.egon_gas_voronoi
WHERE scn_name = '{scenario}'
AND carrier = 'CH4'
"""
)

# Map centroid of mvgd to gas voronoi
join = mvgd_geom.sjoin(gas_voronoi, lsuffix="AC", rsuffix="gas")[
["bus_id_AC", "bus_id_gas"]
].set_index("bus_id_AC")

# Assign gas bus to each rural heat demand coverd by gas boiler
ind_time_series["gas_bus"] = join.loc[
ind_time_series.bus_id
].values

# Initialize dataframe to store final heat demand per gas node
gas_ts = pd.DataFrame(
index=ind_time_series["gas_bus"].unique(), columns=range(8760)
)

# Group heat demand per hour in the year
for i in range(8760):
gas_ts[i] = (
ind_time_series.set_index("gas_bus")
.dist_aggregated_mw.str[i]
.groupby("gas_bus")
.sum()
.div(efficiency_gas_boiler)
)

# Prepare resulting DataFrame
bus_ts = pd.DataFrame(columns=["dist_aggregated_mw", "bus_id"])

# Insert values to dataframe
bus_ts.dist_aggregated_mw = gas_ts.values.tolist()
bus_ts.bus_id = gas_ts.index

# Delete existing data from database
db.execute_sql(
f"""
Expand Down Expand Up @@ -137,7 +199,7 @@ def hts_to_etrago():
etrago_load_timeseries["scn_name"] = scenario
etrago_load_timeseries["load_id"] = bus_ts.load_id
etrago_load_timeseries["temp_id"] = 1
etrago_load_timeseries["p_set"] = bus_ts.iloc[:, 3]
etrago_load_timeseries["p_set"] = bus_ts.loc[:, "dist_aggregated_mw"]

etrago_load_timeseries.to_sql(
"egon_etrago_load_timeseries",
Expand All @@ -152,15 +214,7 @@ class HtsEtragoTable(Dataset):
def __init__(self, dependencies):
super().__init__(
name="HtsEtragoTable",
version="0.0.5",
version="0.0.6",
dependencies=dependencies,
tasks=(
# Temporary drop everything related to rural heat
# individual_heating_per_mv_grid_tables,
# {
# individual_heating_per_mv_grid_2035,
# individual_heating_per_mv_grid_100,
# },
hts_to_etrago,
),
tasks=(hts_to_etrago,),
)

0 comments on commit 7584924

Please sign in to comment.