From 8b5476e273b22d559071abb26f8b36e9be1301ea Mon Sep 17 00:00:00 2001 From: chrstphtrs Date: Wed, 20 Sep 2023 19:33:44 +0200 Subject: [PATCH 1/6] Move all rule to main Snakefile --- Snakefile | 6 ++++++ rules/collect.smk | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Snakefile b/Snakefile index 0e783beb..4bdc40f3 100644 --- a/Snakefile +++ b/Snakefile @@ -46,6 +46,12 @@ wildcard_constraints: sector_opts="[-+a-zA-Z0-9\.\s]*", +rule all: + input: + RESULTS + "graphs/costs.pdf", + default_target: True + + include: "rules/common.smk" include: "rules/collect.smk" include: "rules/retrieve.smk" diff --git a/rules/collect.smk b/rules/collect.smk index 74f26ccb..0c713e5a 100644 --- a/rules/collect.smk +++ b/rules/collect.smk @@ -14,12 +14,6 @@ localrules: plot_networks, -rule all: - input: - RESULTS + "graphs/costs.pdf", - default_target: True - - rule cluster_networks: input: expand(RESOURCES + "networks/elec_s{simpl}_{clusters}.nc", **config["scenario"]), From 138584ecf7ded6bb67f1b796127db7cfd668c28f Mon Sep 17 00:00:00 2001 From: chrstphtrs Date: Fri, 22 Sep 2023 09:01:12 +0200 Subject: [PATCH 2/6] Move all rule down to other rules --- Snakefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Snakefile b/Snakefile index 4bdc40f3..bc77b0df 100644 --- a/Snakefile +++ b/Snakefile @@ -46,12 +46,6 @@ wildcard_constraints: sector_opts="[-+a-zA-Z0-9\.\s]*", -rule all: - input: - RESULTS + "graphs/costs.pdf", - default_target: True - - include: "rules/common.smk" include: "rules/collect.smk" include: "rules/retrieve.smk" @@ -72,6 +66,12 @@ if config["foresight"] == "myopic": include: "rules/solve_myopic.smk" +rule all: + input: + RESULTS + "graphs/costs.pdf", + default_target: True + + rule purge: message: "Purging generated resources, results and docs. Downloads are kept." From 5006bc487757fe972ff9d912ee5952f068f5182d Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Tue, 26 Sep 2023 15:12:39 +0200 Subject: [PATCH 3/6] build_biomass_potentials: link to planning_horizons wildcard, interpolate missing years --- doc/release_notes.rst | 4 +++ rules/build_sector.smk | 12 +++++---- scripts/build_biomass_potentials.py | 40 ++++++++++++++++++++++++++--- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/doc/release_notes.rst b/doc/release_notes.rst index e343953f..9720b664 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -20,6 +20,10 @@ Upcoming Release * Files extracted from sector-coupled data bundle have been moved from ``data/`` to ``data/sector-bundle``. +* It is now possible to specify years for biomass potentials which do not exist + in the JRC-ENSPRESO database, e.g. 2037. These are linearly interpolated. + +* In pathway mode, the biomass potential is linked to the investment year. **Bugs and Compatibility** diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 10a5f821..47c5a4d9 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -280,15 +280,15 @@ rule build_biomass_potentials: country_shapes=RESOURCES + "country_shapes.geojson", output: biomass_potentials_all=RESOURCES - + "biomass_potentials_all_s{simpl}_{clusters}.csv", - biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}.csv", + + "biomass_potentials_all_s{simpl}_{clusters}_{planning_horizons}.csv", + biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", threads: 1 resources: mem_mb=1000, log: - LOGS + "build_biomass_potentials_s{simpl}_{clusters}.log", + LOGS + "build_biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.log", benchmark: - BENCHMARKS + "build_biomass_potentials_s{simpl}_{clusters}" + BENCHMARKS + "build_biomass_potentials_s{simpl}_{clusters}_{planning_horizons}" conda: "../envs/environment.yaml" script: @@ -735,7 +735,9 @@ rule prepare_sector_network: dsm_profile=RESOURCES + "dsm_profile_s{simpl}_{clusters}.csv", co2_totals_name=RESOURCES + "co2_totals.csv", co2="data/bundle-sector/eea/UNFCCC_v23.csv", - biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}.csv", + biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}_" + "{}.csv".format(config["biomass"]["year"]) + if config["foresight"] == "overnight" + else RESOURCES + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", heat_profile="data/heat_load_profile_BDEW.csv", costs="data/costs_{}.csv".format(config["costs"]["year"]) if config["foresight"] == "overnight" diff --git a/scripts/build_biomass_potentials.py b/scripts/build_biomass_potentials.py index d200a78e..5c1eb31d 100644 --- a/scripts/build_biomass_potentials.py +++ b/scripts/build_biomass_potentials.py @@ -7,9 +7,15 @@ Compute biogas and solid biomass potentials for each clustered model region using data from JRC ENSPRESO. """ +import logging + +logger = logging.getLogger(__name__) import geopandas as gpd +import numpy as np import pandas as pd +AVAILABLE_BIOMASS_YEARS = [2010, 2020, 2030, 2040, 2050] + def build_nuts_population_data(year=2013): pop = pd.read_csv( @@ -208,13 +214,41 @@ if __name__ == "__main__": if "snakemake" not in globals(): from _helpers import mock_snakemake - snakemake = mock_snakemake("build_biomass_potentials", simpl="", clusters="5") + snakemake = mock_snakemake( + "build_biomass_potentials", + simpl="", + clusters="5", + planning_horizons=2050, + ) + overnight = snakemake.config["foresight"] == "overnight" params = snakemake.params.biomass - year = params["year"] + investment_year = int(snakemake.wildcards.planning_horizons) + year = params["year"] if overnight else investment_year scenario = params["scenario"] - enspreso = enspreso_biomass_potentials(year, scenario) + if year > 2050: + logger.info("No biomass potentials for years after 2050, using 2050.") + max_year = max(AVAILABLE_BIOMASS_YEARS) + enspreso = enspreso_biomass_potentials(max_year, scenario) + + elif year not in AVAILABLE_BIOMASS_YEARS: + before = int(np.floor(year / 10) * 10) + after = int(np.ceil(year / 10) * 10) + logger.info( + f"No biomass potentials for {year}, interpolating linearly between {before} and {after}." + ) + + enspreso_before = enspreso_biomass_potentials(before, scenario) + enspreso_after = enspreso_biomass_potentials(after, scenario) + + fraction = (year - before) / (after - before) + + enspreso = enspreso_before + fraction * (enspreso_after - enspreso_before) + + else: + logger.info(f"Using biomass potentials for {year}.") + enspreso = enspreso_biomass_potentials(year, scenario) enspreso = disaggregate_nuts0(enspreso) From 9424ec1bb8ef599ed7b766831b3823718b388219 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Sep 2023 13:13:22 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- rules/build_sector.smk | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rules/build_sector.smk b/rules/build_sector.smk index 47c5a4d9..21a588be 100644 --- a/rules/build_sector.smk +++ b/rules/build_sector.smk @@ -281,7 +281,8 @@ rule build_biomass_potentials: output: biomass_potentials_all=RESOURCES + "biomass_potentials_all_s{simpl}_{clusters}_{planning_horizons}.csv", - biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", + biomass_potentials=RESOURCES + + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", threads: 1 resources: mem_mb=1000, @@ -735,9 +736,12 @@ rule prepare_sector_network: dsm_profile=RESOURCES + "dsm_profile_s{simpl}_{clusters}.csv", co2_totals_name=RESOURCES + "co2_totals.csv", co2="data/bundle-sector/eea/UNFCCC_v23.csv", - biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}_" + "{}.csv".format(config["biomass"]["year"]) + biomass_potentials=RESOURCES + + "biomass_potentials_s{simpl}_{clusters}_" + + "{}.csv".format(config["biomass"]["year"]) if config["foresight"] == "overnight" - else RESOURCES + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", + else RESOURCES + + "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv", heat_profile="data/heat_load_profile_BDEW.csv", costs="data/costs_{}.csv".format(config["costs"]["year"]) if config["foresight"] == "overnight" From 834f7ea14485e4031b129294fed3da7f6858574f Mon Sep 17 00:00:00 2001 From: Lukas Franken Date: Thu, 28 Sep 2023 16:19:13 +0100 Subject: [PATCH 5/6] Add dialogue to rule purge to prevent accidents (#745) --- Snakefile | 17 ++++++++++++----- doc/release_notes.rst | 1 + 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Snakefile b/Snakefile index bc77b0df..32a1b125 100644 --- a/Snakefile +++ b/Snakefile @@ -73,12 +73,19 @@ rule all: rule purge: - message: - "Purging generated resources, results and docs. Downloads are kept." run: - rmtree("resources/", ignore_errors=True) - rmtree("results/", ignore_errors=True) - rmtree("doc/_build", ignore_errors=True) + import builtins + + do_purge = builtins.input( + "Do you really want to delete all generated resources, \nresults and docs (downloads are kept)? [y/N] " + ) + if do_purge == "y": + rmtree("resources/", ignore_errors=True) + rmtree("results/", ignore_errors=True) + rmtree("doc/_build", ignore_errors=True) + print("Purging generated resources, results and docs. Downloads are kept.") + else: + raise Exception(f"Input {do_purge}. Aborting purge.") rule dag: diff --git a/doc/release_notes.rst b/doc/release_notes.rst index e343953f..4d8c4b58 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -20,6 +20,7 @@ Upcoming Release * Files extracted from sector-coupled data bundle have been moved from ``data/`` to ``data/sector-bundle``. +* Rule ``purge`` now initiates a dialog to confirm if purge is desired. **Bugs and Compatibility** From 4422bf48dab681fbbc0dba119865422dfa215442 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 00:42:10 +0000 Subject: [PATCH 6/6] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/codespell-project/codespell: v2.2.5 → v2.2.6](https://github.com/codespell-project/codespell/compare/v2.2.5...v2.2.6) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42ade435..803eb61f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,7 @@ repos: # Find common spelling mistakes in comments and docstrings - repo: https://github.com/codespell-project/codespell - rev: v2.2.5 + rev: v2.2.6 hooks: - id: codespell args: ['--ignore-regex="(\b[A-Z]+\b)"', '--ignore-words-list=fom,appartment,bage,ore,setis,tabacco,berfore'] # Ignore capital case words, e.g. country codes