Multiple weather years in one optimisation problem - #1613
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for handling multiple weather years and concatenating cutouts, along with improvements to documentation and type hints. Key changes include:
- Introducing a new load_cutout helper to support multiple cutout files and multiple time ranges
- Updating various build scripts to use get_snapshots and load_cutout instead of hardcoding atlite.Cutout calls
- Changing the default cutout configuration in the YAML file to "default" for several renewable energy sources
Reviewed Changes
Copilot reviewed 23 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| scripts/build_hac_features.py | Updated imports and switched to load_cutout for cutout handling |
| scripts/build_egs_potentials.py | Updated get_capacity_factors signature and integrated get_snapshots |
| scripts/build_daily_heat_demand.py | Replaced direct atlite.Cutout call with load_cutout |
| scripts/build_cutout.py | Added an assert to limit snapshots to a single start/end date |
| scripts/build_clustered_population_layouts.py | Switched to load_cutout for cutout creation |
| scripts/build_central_heating_temperature_profiles/run.py | Updated snapshots generation via get_snapshots |
| scripts/_helpers.py | Enhanced get_snapshots for multiple time ranges and added load_cutout |
| config/config.default.yaml | Changed cutout references from specific strings to "default" |
Files not reviewed (12)
- doc/configtables/atlite.csv: Language not supported
- doc/configtables/hydro.csv: Language not supported
- doc/configtables/lines.csv: Language not supported
- doc/configtables/offwind.csv: Language not supported
- doc/configtables/onwind.csv: Language not supported
- doc/configtables/snapshots.csv: Language not supported
- doc/configtables/solar.csv: Language not supported
- doc/release_notes.rst: Language not supported
- rules/build_electricity.smk: Language not supported
- rules/build_sector.smk: Language not supported
- rules/common.smk: Language not supported
- rules/postprocess.smk: Language not supported
Comments suppressed due to low confidence (2)
scripts/build_cutout.py:90
- The assertion in build_cutout.py limits the snapshots to a single start and end date, which may conflict with the new support for multiple weather years. Consider updating the cutout rule to handle multiple time ranges or document the limitation clearly.
assert (len(snakemake.params.snapshots["start"]) == 1 and len(snakemake.params.snapshots["end"]) == 1), "The cutout rule currently only supports a single start and end date."
scripts/_helpers.py:1083
- Using NamedTemporaryFile().name without managing the file lifecycle may cause issues with file availability on some platforms. Consider explicitly creating a persistent temporary file or managing the temporary file context to ensure the data file remains accessible.
cutout = atlite.Cutout(NamedTemporaryFile().name, data=combined_data)
cpschau
left a comment
There was a problem hiding this comment.
Codewise everything looks good to me. I tested the myopic foresight and everything ran smoothly. Also the concatenation of more than 2 years worked. The only thing that failed is the plotting routine in plot_heatmap_timeseries which might needs to be skipped for multi-year optimizations.
Corrected objectives values (divided by 2 years) of run with concatenated weather years 2013 & 2019 lie in between the objectives of the single-year runs with 2019 being the less challenging year (2019) and 2013 being the more challenging.

Energy balances of network with both weather years look like this:

for more information, see https://pre-commit.ci
|
Great, thanks @cpschau for reviewing! I will merge once CI passes. |
for more information, see https://pre-commit.ci
This might be relevant #1576. |
|
I think the setting was changed in be9fa8d after I tested the functionality. I do not remember the workflow failing without that change, so probably it is related to the last commits. Will probably be worth it to bring it back, as the calculation of the renewable profiles can take a lot of time. |
* cutouts: use a default and allow concatenation * docs: docstrings and type hints for get_snapshots() * multiple heat years for multiple meteorological years * adjust add_import_limit_constraint for multiple years * adjust add_co2_sequestration_limit for multiple years * adjust add_biomass (potentials) for multiple years * follow-up: add up snapshot weightings in add_co2_sequestration_limit * add release notes for multiple full consecutive weather years * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * build_hydro_profile: use full-year cutouts for subannual periods * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix: handle non-contiguous date range in time aggregation koen-vg@1dce9b0 * avoid that aggregated snapshot indices land on Feb 29 * support for non-consecutive weather years * update snapshots options documentation * config/test: simplify as technologies automatically go to default cutout * refactor: remove snapshots parameter from build_cutout rule and simplify time handling * refactor: Update cutout handling in solar rooftop potentials script * plto_heatmap_timeseries: leap days and non-contiguity check * switch era5-annual-hdd/runoff... to daily data and data bundle * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * use highs-default for myopic and perfect test * ci: do not share resources, go back to highs-simplex, test biomass import myopic * fix: add_co2_sequestration_limit nyears with perfect foresight * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Closes #1610.
Closes #1627.
Changes proposed in this Pull Request
TLDR: Allow multiple years (consecutive or non-consecutive) or flexible periods (e.g. July-June meteorological year) in one optimisation model.
Details: See release notes.
data/era5-annual-HDD-per-country.csvis currently only annually resolved, the heat demand for July-June years is currently only scaled 50% first year and 50% second year. I.e. different distributions of heat demand in first and second winter of year are not considered. -> data bundle is updated with daily resolved HDD, handling deferred to follow-up PR.Configuration for one year
Configuration for N consecutive years
Configuration for meteorological year
Configuration for N non-contiguous years
Checklist
envs/environment.yaml.config/config.default.yaml.doc/configtables/*.csv.doc/data_sources.rst.doc/release_notes.rstis added.