Skip to content

Commit 43796cb

Browse files
Michael Lindnerlkstrp
andauthored
Maintenance: improve iiasa_database handling, update_config_from_wildcards, raise errors (#102)
* * rename iiasa_database section to pypsa-de * require retrieve config to be active * relocate ariadne_databse from resources to data * remove unused params from some rules * remove unused config * changelog and scenario name * make sure every logger.error is actually raised * setting scenario snakemake.config everywhere * minor simplifications * logger.info instead of print * fix some warnings from plotting scripts * eliminate some globals --------- Co-authored-by: Lukas Trippe <[email protected]>
1 parent df36b86 commit 43796cb

27 files changed

+285
-144
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
path: |
7070
data
7171
cutouts
72-
resources/ariadne_database.csv
72+
data/ariadne_database.csv
7373
key: data-cutouts-${{ env.WEEK }}
7474

7575
- uses: conda-incubator/setup-miniconda@v3

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
- Simplified IIASA database download
23
- Bugfix: Enforce stricter H2 derivative import limit to avoid that exports of one type of derivative compensate for imports of another
34
- Added an option to source mobility demand from UBA MWMS (Projektionsbericht 2025) for the years 2025-2035
45
- Renamed functions and script for exogenous mobility demand

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ PyPSA-DE is a softfork of PyPSA-EUR. As such, large parts of the functionality a
7777

7878
## New Config Options
7979

80-
- `iiasa_database` - interaction with IIASA database. Specify a database, and `leitmodelle` for demand and co2 emissions data in specific sectors
80+
- `pypsa-de` - interaction with IIASA database. Specify a database, and `leitmodelle` for demand and co2 emissions data in specific sectors
8181
- `wasserstoff_kernnetz` - configure which parts of the Wasserstoff Kernnetz should be included in the model
8282
- `new_decentral_fossil_boiler_ban` - specify in which country and which years to ban fossil boilers
8383
- `coal_generation_ban` - specify in which country and which years to ban electricity generation from coal

Snakefile

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -302,33 +302,6 @@ rule clean:
302302
print("Data downloaded to data/ has not been cleaned.")
303303

304304

305-
rule retrieve_egon_data:
306-
output:
307-
spatial="data/egon/demandregio_spatial_2018.json",
308-
mapping="data/egon/mapping_technologies.json",
309-
shell:
310-
"""
311-
mkdir -p data/egon
312-
curl -o {output.spatial} "https://api.opendata.ffe.de/demandregio/demandregio_spatial?id_spatial=5&year=2018"
313-
curl -o {output.mapping} "https://api.opendata.ffe.de/demandregio/demandregio_spatial_description?id_spatial=5"
314-
"""
315-
316-
317-
rule retrieve_ariadne_database:
318-
params:
319-
db_name=config["iiasa_database"]["db_name"],
320-
leitmodelle=config["iiasa_database"]["leitmodelle"],
321-
scenarios=config["iiasa_database"]["scenarios"],
322-
output:
323-
data="resources/ariadne_database.csv",
324-
log:
325-
"logs/retrieve_ariadne_database.log",
326-
resources:
327-
mem_mb=1000,
328-
script:
329-
"scripts/pypsa-de/retrieve_ariadne_database.py"
330-
331-
332305
rule modify_cost_data:
333306
params:
334307
file_path="ariadne-data/costs/",
@@ -354,23 +327,81 @@ rule modify_cost_data:
354327
"scripts/pypsa-de/modify_cost_data.py"
355328

356329

330+
if config["enable"]["retrieve"]:
331+
332+
rule retrieve_ariadne_database:
333+
output:
334+
data="data/ariadne_database.csv",
335+
log:
336+
"logs/retrieve_ariadne_database.log",
337+
resources:
338+
mem_mb=1000,
339+
script:
340+
"scripts/pypsa-de/retrieve_ariadne_database.py"
341+
342+
343+
if config["enable"]["retrieve"]:
344+
345+
rule retrieve_ariadne_template:
346+
input:
347+
storage(
348+
"https://github.com/iiasa/ariadne-intern-workflow/raw/main/attachments/2025-01-27_template_Ariadne.xlsx",
349+
keep_local=True,
350+
),
351+
output:
352+
"data/template_ariadne_database.xlsx",
353+
run:
354+
move(input[0], output[0])
355+
356+
357+
if config["enable"]["retrieve"]:
358+
359+
rule retrieve_mastr:
360+
input:
361+
storage(
362+
"https://zenodo.org/records/8225106/files/bnetza_open_mastr_2023-08-08_B.zip",
363+
keep_local=True,
364+
),
365+
params:
366+
"data/mastr",
367+
output:
368+
"data/mastr/bnetza_open_mastr_2023-08-08_B_biomass.csv",
369+
"data/mastr/bnetza_open_mastr_2023-08-08_B_combustion.csv",
370+
run:
371+
unpack_archive(input[0], params[0])
372+
373+
374+
if config["enable"]["retrieve"]:
375+
376+
rule retrieve_egon_data:
377+
output:
378+
spatial="data/egon/demandregio_spatial_2018.json",
379+
mapping="data/egon/mapping_technologies.json",
380+
shell:
381+
"""
382+
mkdir -p data/egon
383+
curl -o {output.spatial} "https://api.opendata.ffe.de/demandregio/demandregio_spatial?id_spatial=5&year=2018"
384+
curl -o {output.mapping} "https://api.opendata.ffe.de/demandregio/demandregio_spatial_description?id_spatial=5"
385+
"""
386+
387+
357388
if config["enable"]["retrieve"] and config["enable"].get("retrieve_cost_data", True):
358389

359390
ruleorder: modify_cost_data > retrieve_cost_data
360391

361392

362393
rule build_exogenous_mobility_data:
363394
params:
364-
reference_scenario=config_provider("iiasa_database", "reference_scenario"),
395+
reference_scenario=config_provider("pypsa-de", "reference_scenario"),
365396
planning_horizons=config_provider("scenario", "planning_horizons"),
366-
leitmodelle=config_provider("iiasa_database", "leitmodelle"),
367-
ageb_for_mobility=config_provider("iiasa_database", "ageb_for_mobility"),
368-
uba_for_mobility=config_provider("iiasa_database", "uba_for_mobility"),
397+
leitmodelle=config_provider("pypsa-de", "leitmodelle"),
398+
ageb_for_mobility=config_provider("pypsa-de", "ageb_for_mobility"),
399+
uba_for_mobility=config_provider("pypsa-de", "uba_for_mobility"),
369400
shipping_oil_share=config_provider("sector", "shipping_oil_share"),
370401
aviation_demand_factor=config_provider("sector", "aviation_demand_factor"),
371402
energy_totals_year=config_provider("energy", "energy_totals_year"),
372403
input:
373-
ariadne="resources/ariadne_database.csv",
404+
ariadne="data/ariadne_database.csv",
374405
energy_totals=resources("energy_totals.csv"),
375406
output:
376407
mobility_data=resources(
@@ -599,11 +630,8 @@ ruleorder: modify_industry_demand > build_industrial_production_per_country_tomo
599630

600631

601632
rule modify_existing_heating:
602-
params:
603-
iiasa_reference_scenario=config_provider("iiasa_database", "reference_scenario"),
604-
leitmodelle=config_provider("iiasa_database", "leitmodelle"),
605633
input:
606-
ariadne="resources/ariadne_database.csv",
634+
ariadne="data/ariadne_database.csv",
607635
existing_heating="data/existing_infrastructure/existing_heating_raw.csv",
608636
output:
609637
existing_heating=resources("existing_heating.csv"),
@@ -615,21 +643,6 @@ rule modify_existing_heating:
615643
"scripts/pypsa-de/modify_existing_heating.py"
616644

617645

618-
rule retrieve_mastr:
619-
input:
620-
storage(
621-
"https://zenodo.org/records/8225106/files/bnetza_open_mastr_2023-08-08_B.zip",
622-
keep_local=True,
623-
),
624-
params:
625-
"data/mastr",
626-
output:
627-
"data/mastr/bnetza_open_mastr_2023-08-08_B_biomass.csv",
628-
"data/mastr/bnetza_open_mastr_2023-08-08_B_combustion.csv",
629-
run:
630-
unpack_archive(input[0], params[0])
631-
632-
633646
rule build_existing_chp_de:
634647
params:
635648
district_heating_subnodes=config_provider(
@@ -658,9 +671,9 @@ rule build_existing_chp_de:
658671

659672
rule modify_industry_demand:
660673
params:
661-
reference_scenario=config_provider("iiasa_database", "reference_scenario"),
674+
reference_scenario=config_provider("pypsa-de", "reference_scenario"),
662675
input:
663-
ariadne="resources/ariadne_database.csv",
676+
ariadne="data/ariadne_database.csv",
664677
industrial_production_per_country_tomorrow=resources(
665678
"industrial_production_per_country_tomorrow_{planning_horizons}.csv"
666679
),
@@ -722,18 +735,6 @@ rule cluster_wasserstoff_kernnetz:
722735
"scripts/pypsa-de/cluster_wasserstoff_kernnetz.py"
723736

724737

725-
rule download_ariadne_template:
726-
input:
727-
storage(
728-
"https://github.com/iiasa/ariadne-intern-workflow/raw/main/attachments/2025-01-27_template_Ariadne.xlsx",
729-
keep_local=True,
730-
),
731-
output:
732-
"data/template_ariadne_database.xlsx",
733-
run:
734-
move(input[0], output[0])
735-
736-
737738
rule export_ariadne_variables:
738739
params:
739740
planning_horizons=config_provider("scenario", "planning_horizons"),
@@ -794,11 +795,10 @@ rule export_ariadne_variables:
794795

795796
rule plot_ariadne_variables:
796797
params:
797-
iiasa_scenario=config_provider("iiasa_database", "reference_scenario"),
798-
reference_scenario=config_provider("iiasa_database", "reference_scenario"),
798+
reference_scenario=config_provider("pypsa-de", "reference_scenario"),
799799
input:
800800
exported_variables_full=RESULTS + "ariadne/exported_variables_full.xlsx",
801-
ariadne_database="resources/ariadne_database.csv",
801+
ariadne_database="data/ariadne_database.csv",
802802
output:
803803
primary_energy=RESULTS + "ariadne/primary_energy.png",
804804
primary_energy_detailed=RESULTS + "ariadne/primary_energy_detailed.png",
@@ -863,9 +863,9 @@ rule ariadne_all:
863863
rule build_scenarios:
864864
params:
865865
scenarios=config["run"]["name"],
866-
leitmodelle=config["iiasa_database"]["leitmodelle"],
866+
leitmodelle=config["pypsa-de"]["leitmodelle"],
867867
input:
868-
ariadne_database="resources/ariadne_database.csv",
868+
ariadne_database="data/ariadne_database.csv",
869869
scenario_yaml=config["run"]["scenarios"]["manual_file"],
870870
output:
871871
scenario_yaml=config["run"]["scenarios"]["file"],

config/config.de.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# docs in https://pypsa-eur.readthedocs.io/en/latest/configuration.html#run
66
run:
7-
prefix: 20250901_h2_deriv_fix
7+
prefix: 20250811_improve_database
88
name:
99
# - ExPol
1010
- KN2045_Mix
@@ -27,20 +27,12 @@ run:
2727
- modify_existing_heating
2828
disable_progressbar: true
2929

30-
iiasa_database:
31-
db_name: ariadne2
32-
leitmodelle:
30+
pypsa-de:
31+
leitmodelle: # Model data downloaded from public IIASA database 'ariadne2'
3332
general: REMIND-EU v1.1
3433
buildings: REMod v1.0
3534
transport: Aladin v1
3635
industry: FORECAST v1.0
37-
scenarios:
38-
- ExPol
39-
- KN2045_Elek
40-
- KN2045_H2
41-
- KN2045_Mix
42-
- KN2045_NFniedrig
43-
- KN2045_NFhoch
4436
reference_scenario: KN2045_Mix
4537
region: Deutschland
4638
ageb_for_mobility: true # In 2020 use AGEB data for final energy demand and KBA for vehicles

config/scenarios.manual.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ExPol:
88
# Kernnetz is not assumed to be built
99
# Not forcing renewables after 2030
1010

11-
iiasa_database:
11+
pypsa-de:
1212
reference_scenario: ExPol
1313

1414
co2_budget_DE_source: UBA
@@ -80,7 +80,7 @@ KN2045_Elek:
8080
# Ausbau der erneuerbaren Stromerzeugung erreicht politisch gesetzte Ziele
8181
# Importe erneuerbar erzeugter Energien auf mittlerem Niveau
8282

83-
iiasa_database:
83+
pypsa-de:
8484
reference_scenario: KN2045_Elek
8585

8686
solving:
@@ -135,7 +135,7 @@ KN2045_H2:
135135
# Direkte Elektrifizierung spielt dennoch wesentliche Rolle bei der Dekarbonisierung der Endenergie
136136
# Ausbau der erneuerbaren Stromerzeugung erreicht politisch gesetzte Ziele
137137

138-
iiasa_database:
138+
pypsa-de:
139139
reference_scenario: KN2045_H2
140140

141141
solving:
@@ -204,7 +204,7 @@ KN2045_NFniedrig:
204204
# Importe erneuerbar erzeugter Energien auf mittlerem Niveau
205205
# dient als Referenzszenario in der Familie der Ariadne-Szenarien
206206

207-
iiasa_database:
207+
pypsa-de:
208208
reference_scenario: KN2045_NFniedrig
209209

210210
sector:
@@ -224,7 +224,7 @@ KN2045_NFhoch:
224224
# Importe erneuerbar erzeugter Energien auf mittlerem Niveau
225225
# dient als Referenzszenario in der Familie der Ariadne-Szenarien
226226

227-
iiasa_database:
227+
pypsa-de:
228228
reference_scenario: KN2045_NFhoch
229229

230230
sector:

config/scenarios.sysgf.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
Baseline:
77
foresight: myopic
8-
iiasa_database:
8+
pypsa-de:
99
reference_scenario: KN2045_Mix
1010
co2_budget_DE_source: UBA
1111

scripts/add_existing_baseyear.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,7 @@ def add_power_capacities_installed_before_baseyear(
444444
bus0 = spatial.biogas.df.loc[new_capacity.index, "nodes"].values
445445
else:
446446
logger.error(f"Generator {generator} not recognized.")
447+
raise ValueError(f"Generator {generator} not recognized.")
447448

448449
# We assume the electrical efficiency of a CHP for the biomass and biogas power plants
449450
# The EOP from technology data seems to be somewhat too efficient

scripts/build_industry_sector_ratios.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,9 @@ def other_industrial_sectors():
16451645
logger.error(
16461646
"Fractions for steam processing do not sum to 1! Please check config[industry][steam_biomass_fraction], config[industry][steam_hydrogen_fraction] and config[industry][steam_electricity_fraction]!"
16471647
)
1648+
raise ValueError(
1649+
"Fractions for steam processing do not sum to 1! Please check config[industry][steam_biomass_fraction], config[industry][steam_hydrogen_fraction] and config[industry][steam_electricity_fraction]!"
1650+
)
16481651

16491652
logger.info(
16501653
f"Steam processing fractions set to {params['steam_biomass_fraction']} biomass, {params['steam_hydrogen_fraction']} hydrogen and {params['steam_electricity_fraction']} electricity."

scripts/pypsa-de/additional_functionality.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,9 @@ def add_national_co2_budgets(n, snakemake, national_co2_budgets, investment_year
384384
logger.error(
385385
f"CO2 budget for countries other than `DE` is not yet supported. Found country {ct}. Please check the config file."
386386
)
387+
raise NotImplementedError(
388+
f"CO2 budget for countries other than `DE` is not yet supported. Found country {ct}. Please check the config file."
389+
)
387390

388391
limit = co2_total_totals[ct] * national_co2_budgets[ct][investment_year]
389392
logger.info(

0 commit comments

Comments
 (0)