Skip to content

Commit

Permalink
Merge pull request #247 from openego/features/#162-district-heating-a…
Browse files Browse the repository at this point in the history
…reas

Features/#162 district heating areas
  • Loading branch information
EvaWie authored May 14, 2021
2 parents 00fca06 + 641a34b commit 78387fc
Show file tree
Hide file tree
Showing 6 changed files with 1,346 additions and 28 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Added
`#214 <https://github.com/openego/eGon-data/issues/214>`_
* Integrate weather data and renewable feedin timeseries
`#19 <https://github.com/openego/eGon-data/issues/19>`_
* Create and import district heating areas
`#162 <https://github.com/openego/eGon-data/issues/162>`_

.. _PR #159: https://github.com/openego/eGon-data/pull/159

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def read(*names, **kwargs):
"geopandas>=0.9.0",
"importlib-resources",
"loguru",
"matplotlib",
"oedialect==0.0.8",
"psycopg2",
"pyaml",
Expand Down
20 changes: 19 additions & 1 deletion src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import egon.data.importing.industrial_sites as industrial_sites
import egon.data.processing.loadarea as loadarea
import egon.data.processing.renewable_feedin as import_feedin
import egon.data.processing.district_heating_areas as district_heating_areas

from egon.data import db

Expand Down Expand Up @@ -336,6 +337,7 @@
task_id="osmtgmod_osm_import",
python_callable=osmtgmod.import_osm_data,
)

run_osmtgmod = PythonOperator(
task_id="run_osmtgmod",
python_callable=osmtgmod.run_osmtgmod,
Expand Down Expand Up @@ -366,7 +368,7 @@
)
osmtgmod_substation >> create_voronoi


define_mv_grid_districts = PythonOperator(
task_id="define_mv_grid_districts",
python_callable=mvgd.define_mv_grid_districts
Expand Down Expand Up @@ -500,3 +502,19 @@
feedin_pv, feedin_solar_thermal]
vg250_clean_and_prepare >> [feedin_wind_onshore,
feedin_pv, feedin_solar_thermal]

# District heating areas demarcation
create_district_heating_areas_table = PythonOperator(
task_id="create-district-heating-areas-table",
python_callable=district_heating_areas.create_tables
)
import_district_heating_areas = PythonOperator(
task_id="import-district-heating-areas",
python_callable=district_heating_areas.
district_heating_areas_demarcation
)
setup >> create_district_heating_areas_table
create_district_heating_areas_table >> import_district_heating_areas
zensus_misc_import >> import_district_heating_areas
heat_demand_import >> import_district_heating_areas
scenario_input_import >> import_district_heating_areas
60 changes: 33 additions & 27 deletions src/egon/data/importing/heat_demand_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ def future_heat_demand_germany(scenario_name):
"""
Calculate the future residential and service-sector heat demand per ha.
The calculation is based on Peta5_0_1 heat demand densities, cutcut for
The calculation is based on Peta5_0_1 heat demand densities, cutout for
Germany, for the year 2015. The given scenario name is used to read the
adjustment factors for the heat demand rasters from the scenario table.
Expand Down Expand Up @@ -335,12 +335,14 @@ def future_heat_demand_germany(scenario_name):
"""
# Load the values
heat_parameters = get_sector_parameters('heat', scenario=scenario_name)

res_hd_reduction = heat_parameters['DE_demand_reduction_residential']

ser_hd_reduction = heat_parameters['DE_demand_reduction_service']
if scenario_name == "eGon2015":
res_hd_reduction = 1
ser_hd_reduction = 1
else:
heat_parameters = get_sector_parameters('heat', scenario=scenario_name)

res_hd_reduction = heat_parameters['DE_demand_reduction_residential']
ser_hd_reduction = heat_parameters['DE_demand_reduction_service']

# Define the directory where the created rasters will be saved
scenario_raster_directory = "heat_scenario_raster"
Expand Down Expand Up @@ -457,28 +459,30 @@ def heat_demand_to_db_table():
db.execute_sql("DELETE FROM demand.egon_peta_heat;")

for source in sources:
# Create a temporary table and fill the final table using the sql script
rasters = f"heat_demand_rasters_{source.stem.lower()}"
import_rasters = subprocess.run(
["raster2pgsql", "-e", "-s", "3035", "-I", "-C", "-F", "-a"]
+ [source]
+ [f"{rasters}"],
text=True,
).stdout
with engine.begin() as connection:
print(f'CREATE TEMPORARY TABLE "{rasters}"'
' ("rid" serial PRIMARY KEY,"rast" raster,"filename" text);')
connection.execute(
f'CREATE TEMPORARY TABLE "{rasters}"'
' ("rid" serial PRIMARY KEY,"rast" raster,"filename" text);'
)
connection.execute(import_rasters)
connection.execute(f'ANALYZE "{rasters}"')
with open(sql_script) as convert:

if not '2015' in source.stem:
# Create a temporary table and fill the final table using the sql script
rasters = f"heat_demand_rasters_{source.stem.lower()}"
import_rasters = subprocess.run(
["raster2pgsql", "-e", "-s", "3035", "-I", "-C", "-F", "-a"]
+ [source]
+ [f"{rasters}"],
text=True,
).stdout
with engine.begin() as connection:
print(f'CREATE TEMPORARY TABLE "{rasters}"'
' ("rid" serial PRIMARY KEY,"rast" raster,"filename" text);')
connection.execute(
Template(convert.read()).render(version="0.0.0",
source=rasters)
f'CREATE TEMPORARY TABLE "{rasters}"'
' ("rid" serial PRIMARY KEY,"rast" raster,"filename" text);'
)
connection.execute(import_rasters)
connection.execute(f'ANALYZE "{rasters}"')
with open(sql_script) as convert:
connection.execute(
Template(convert.read()).render(version="0.0.0",
source=rasters)
)
return None


Expand Down Expand Up @@ -615,7 +619,7 @@ def add_metadata():

# Metadata creation
meta = {
"name": "heat",
"name": "egon_peta_heat_metadata",
"title": "eGo_n scenario-specific future heat demand data",
"description": "Future heat demands per hectare grid cell of "
"the residential and service sector",
Expand Down Expand Up @@ -837,9 +841,11 @@ def future_heat_demand_data_import():
# Specifiy the scenario names for loading factors from csv file
future_heat_demand_germany("eGon2035")
future_heat_demand_germany("eGon100RE")
# future_heat_demand_germany("eGon2015")
heat_demand_to_db_table()
adjust_residential_heat_to_zensus("eGon2035")
adjust_residential_heat_to_zensus("eGon100RE")
# future_heat_demand_germany("eGon2015")
add_metadata()

return None
Loading

0 comments on commit 78387fc

Please sign in to comment.