Skip to content

Commit 39e72aa

Browse files
author
Micha
authored
add weather year config option to build_scenarios (#100)
* add weather year config to scenarios * better error message
1 parent 37c5554 commit 39e72aa

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Changelog
2+
- Added a helper function to change the weather_year to build_scenario
23
- Longer lifetime (40 years) is only applied to existing gas CHPs, not new ones. Added a new config entry `existing_capacities:fill_value_gas_chp_lifetime`
34
- Bugfix: gas CHPs are extendable again
45
- Simplified scenarion definition and made `Mix` the default scenario

config/config.de.yaml

Lines changed: 1 addition & 1 deletion
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: 20253006_fix_chp_lifetime
7+
prefix: 20250721_weather_year_helper
88
name:
99
# - ExPol
1010
- KN2045_Mix

scripts/pypsa-de/build_scenarios.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,47 @@ def get_co2_budget(df, source):
129129
return target_fractions_pypsa.round(3)
130130

131131

132+
def write_weather_dependent_config(config, scenario, weather_year):
133+
# Insert weather-dependent configuration dynamically
134+
cutout_name = f"europe-{weather_year}-sarah3-era5"
135+
136+
# atlite section
137+
config[scenario]["atlite"] = {
138+
"default_cutout": cutout_name,
139+
"cutouts": {
140+
cutout_name: {
141+
"module": ["sarah", "era5"],
142+
"x": [-12.0, 42.0],
143+
"y": [33.0, 72.0],
144+
"dx": 0.3,
145+
"dy": 0.3,
146+
"time": [str(weather_year), str(weather_year)],
147+
}
148+
},
149+
}
150+
151+
# snapshots section
152+
config[scenario]["snapshots"] = {
153+
"start": f"{weather_year}-01-01",
154+
"end": f"{int(weather_year) + 1}-01-01",
155+
"inclusive": "left",
156+
}
157+
158+
# renewable section
159+
config[scenario]["renewable"] = {
160+
"onwind": {"cutout": cutout_name},
161+
"offwind-ac": {"cutout": cutout_name},
162+
"offwind-dc": {"cutout": cutout_name},
163+
"offwind-float": {"cutout": cutout_name},
164+
"solar": {"cutout": cutout_name},
165+
"solar-hsat": {"cutout": cutout_name},
166+
"hydro": {"cutout": cutout_name},
167+
}
168+
169+
# lines section
170+
config[scenario]["lines"] = {"dynamic_line_rating": {"cutout": cutout_name}}
171+
172+
132173
def write_to_scenario_yaml(input, output, scenarios, df):
133174
# read in yaml file
134175
yaml = ruamel.yaml.YAML()
@@ -140,6 +181,17 @@ def write_to_scenario_yaml(input, output, scenarios, df):
140181
f"Found an empty scenario config for {scenario}. Using default config `pypsa.de.yaml`."
141182
)
142183
config[scenario] = {}
184+
if config[scenario].get("weather_year", False):
185+
weather_year = config[scenario]["weather_year"]
186+
default_weather_year = int(snakemake.config["snapshots"]["start"][:4])
187+
if (
188+
snakemake.config["run"]["shared_resources"]["policy"] != False
189+
and weather_year != default_weather_year
190+
):
191+
raise ValueError(
192+
f"The run uses shared resources, but weather year {weather_year} in scenario {scenario} does not match the start year of the snapshots {default_weather_year}. If you are running scenarios with multiple weather years, make sure to deactivate shared_resources!"
193+
)
194+
write_weather_dependent_config(config, scenario, weather_year)
143195

144196
reference_scenario = (
145197
config[scenario]

0 commit comments

Comments
 (0)