Skip to content

Commit

Permalink
Use scenario table in demandregio import
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaraBuettner committed Apr 15, 2021
1 parent e5d9cd1 commit 4600423
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
25 changes: 15 additions & 10 deletions src/egon/data/airflow/dags/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@
] >> map_zensus_vg250 >> zensus_inside_ger >> zensus_inside_ger_metadata
zensus_inside_ger >> vg250_population >> vg250_population_metadata

# Scenario table
scenario_input_tables = PythonOperator(
task_id="create-scenario-parameters-table",
python_callable=import_scenarios.create_table
)

scenario_input_import = PythonOperator(
task_id="import-scenario-parameters",
python_callable=import_scenarios.insert_scenarios
)
setup >> scenario_input_tables >> scenario_input_import

# DemandRegio data import
demandregio_tables = PythonOperator(
task_id="demandregio-tables",
Expand All @@ -169,20 +181,23 @@
)
vg250_clean_and_prepare >> demandregio_society
demandregio_tables >> demandregio_society
scenario_input_import >> demandregio_society

demandregio_demand_households = PythonOperator(
task_id="demandregio-household-demands",
python_callable=import_dr.insert_household_demand,
)
vg250_clean_and_prepare >> demandregio_demand_households
demandregio_tables >> demandregio_demand_households
scenario_input_import >> demandregio_demand_households

demandregio_demand_cts_ind = PythonOperator(
task_id="demandregio-cts-industry-demands",
python_callable=import_dr.insert_cts_ind_demands,
)
vg250_clean_and_prepare >> demandregio_demand_cts_ind
demandregio_tables >> demandregio_demand_cts_ind
scenario_input_import >> demandregio_demand_cts_ind

# Society prognosis
prognosis_tables = PythonOperator(
Expand Down Expand Up @@ -354,15 +369,5 @@
nep_insert_data >> power_plant_import
retrieve_mastr_data >> power_plant_import

# Scenario table
scenario_input_tables = PythonOperator(
task_id="create-scenario-parameters-table",
python_callable=import_scenarios.create_table
)

scenario_input_import = PythonOperator(
task_id="import-scenario-parameters",
python_callable=import_scenarios.insert_scenarios
)
setup >> scenario_input_tables >> scenario_input_import

14 changes: 10 additions & 4 deletions src/egon/data/datasets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ demandregio_society:
vg250_krs:
schema: 'boundaries'
table: 'vg250_krs'
scenarios:
schema: 'grid'
table: 'egon_scenarios'
targets:
population:
schema: 'society'
table: 'egon_demandregio_population'
target_years: [2018, 2035, 2050]
household:
schema: 'society'
table: 'egon_demandregio_household'
target_years: [2018, 2035, 2050]


demandregio_household_demand:
sources:
Expand All @@ -93,11 +95,13 @@ demandregio_household_demand:
vg250_krs:
schema: 'boundaries'
table: 'vg250_krs'
scenarios:
schema: 'grid'
table: 'egon_scenarios'
targets:
household_demand:
schema: 'demand'
table: 'egon_demandregio_hh'
scenarios: ["eGon2035", "eGon100RE"]

demandregio_cts_ind_demand:
sources:
Expand All @@ -110,11 +114,13 @@ demandregio_cts_ind_demand:
wz_definitions:
"CTS": 'CTS_WZ_definition.csv'
"industry": 'ind_WZ_definition.csv'
scenarios:
schema: 'grid'
table: 'egon_scenarios'
targets:
cts_ind_demand:
schema: 'demand'
table: 'egon_demandregio_cts_ind'
scenarios: ["eGon2035", "eGon100RE"]
wz_definitions:
schema: 'demand'
table: 'egon_demandregio_wz'
Expand Down
28 changes: 13 additions & 15 deletions src/egon/data/importing/demandregio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"""
import os
import pandas as pd
import numpy as np
import egon.data.config
from egon.data import db
from sqlalchemy import Column, String, Float, Integer
from sqlalchemy.ext.declarative import declarative_base
from disaggregator import data, spatial
import egon.data.importing.scenarios.parameters as scenario_parameters
# will be later imported from another file ###
Base = declarative_base()

Expand Down Expand Up @@ -385,14 +387,9 @@ def insert_household_demand():
db.execute_sql(
f"DELETE FROM {targets[t]['schema']}.{targets[t]['table']};")

for scn in targets['household_demand']['scenarios']:
for scn in ['eGon2035', 'eGon100RE']:

if scn == 'eGon2035':
year = 2035
elif scn == 'eGon100RE':
year = 2050
else:
print(f"Warning: Scenario {scn} can not be imported.")
year = scenario_parameters.global_settings(scn)['population_year']

# Insert demands of private households
insert_hh_demand(scn, year, engine)
Expand All @@ -417,14 +414,12 @@ def insert_cts_ind_demands():

insert_cts_ind_wz_definitions()

for scn in targets['cts_ind_demand']['scenarios']:
for scn in ['eGon2035', 'eGon100RE']:

if scn == 'eGon2035':
year = 2035
elif scn == 'eGon100RE':
year = scenario_parameters.global_settings(scn)['population_year']

if year > 2035:
year = 2035
else:
print(f"Warning: Scenario {scn} can not be imported.")

# target values per scenario in MWh
target_values = {
Expand Down Expand Up @@ -458,8 +453,11 @@ def insert_society_data():
db.execute_sql(
f"DELETE FROM {targets[t]['schema']}.{targets[t]['table']};")

target_years = np.append(db.select_dataframe(
"SELECT global_parameters -> 'population_year' as years "
"FROM grid.egon_scenarios").years.values, 2018)

for year in targets['population']['target_years']:
for year in target_years:
df_pop = pd.DataFrame(data.population(year=year))
df_pop['year'] = year
df_pop = df_pop.rename({'value': 'population'}, axis='columns')
Expand All @@ -471,7 +469,7 @@ def insert_society_data():
if_exists='append')


for year in targets['household']['target_years']:
for year in target_years:
df_hh = pd.DataFrame(data.households_per_size(year=year))
# Select data for nuts3-regions in boundaries (needed for testmode)
df_hh = data_in_boundaries(df_hh)
Expand Down

0 comments on commit 4600423

Please sign in to comment.