From 6d260435a633d18e049715b741ae1e0e4a4e7c65 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Wed, 15 Jun 2022 13:49:37 +0200 Subject: [PATCH] allow fixed load data year deviating from snapshots --- Snakefile | 4 ++-- config.default.yaml | 2 +- scripts/build_load_data.py | 20 ++++++++++++++++++-- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Snakefile b/Snakefile index 518f5619..94ad7926 100644 --- a/Snakefile +++ b/Snakefile @@ -77,8 +77,8 @@ rule retrieve_load_data: rule build_load_data: input: "data/load_raw.csv" - output: "resources/load.csv" - log: "logs/build_load_data.log" + output: "resources/load{weather_year}.csv" + log: "logs/build_load_data{weather_year}.log" script: 'scripts/build_load_data.py' diff --git a/config.default.yaml b/config.default.yaml index 9c986494..c1dbd8b7 100755 --- a/config.default.yaml +++ b/config.default.yaml @@ -196,7 +196,7 @@ load: time_shift_for_large_gaps: 1w # data gaps up until this size are copied by copying from manual_adjustments: true # false scaling_factor: 1.0 - fallback_year: 2013 + fixed_year: false # false or year costs: year: 2030 diff --git a/scripts/build_load_data.py b/scripts/build_load_data.py index 10921782..0cad8ddf 100755 --- a/scripts/build_load_data.py +++ b/scripts/build_load_data.py @@ -196,11 +196,23 @@ if __name__ == "__main__": configure_logging(snakemake) + weather_year = snakemake.wildcard.weather_year + if weather_year: + snapshots = dict( + start=weather_year, + end=str(int(weather_year)+1), + closed="left" + ) + else: + snapshots = snakemake.config['snapshots'] + snapshots = pd.date_range(freq='h', **snapshots) + + fixed_year = snakemake.config["load"].get("fixed_year", False) + years = slice(fixed_year, fixed_year) if fixed_year else slice(snapshots[0], snapshots[-1]) + powerstatistics = snakemake.config['load']['power_statistics'] interpolate_limit = snakemake.config['load']['interpolate_limit'] countries = snakemake.config['countries'] - snapshots = pd.date_range(freq='h', **snakemake.config['snapshots']) - years = slice(snapshots[0], snapshots[-1]) time_shift = snakemake.config['load']['time_shift_for_large_gaps'] load = load_timeseries(snakemake.input[0], years, countries, powerstatistics) @@ -220,5 +232,9 @@ if __name__ == "__main__": '`time_shift_for_large_gaps` or modify the `manual_adjustment` function ' 'for implementing the needed load data modifications.') + # need to reindex load time series to target year + if fixed_year: + load.index = load.index.map(lambda t: t.replace(year=snapshots.year[0])) + load.to_csv(snakemake.output[0])