From 8a49697a51ee4148a565d2937cdd69d9a761810b Mon Sep 17 00:00:00 2001 From: martacki Date: Fri, 29 Apr 2022 15:09:10 +0200 Subject: [PATCH] bugfixes for manual load adjustments --- config.default.yaml | 2 +- config.tutorial.yaml | 2 +- scripts/build_load_data.py | 24 ++++++++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/config.default.yaml b/config.default.yaml index d2bf6159..8ac51ee8 100755 --- a/config.default.yaml +++ b/config.default.yaml @@ -26,7 +26,7 @@ clustering: snapshots: start: "2013-01-01" end: "2014-01-01" - closed: 'left' # end is not inclusive + inclusive: 'left' # end is not inclusive enable: prepare_links_p_nom: false diff --git a/config.tutorial.yaml b/config.tutorial.yaml index 225d8f78..2ac96ee3 100755 --- a/config.tutorial.yaml +++ b/config.tutorial.yaml @@ -26,7 +26,7 @@ clustering: snapshots: start: "2013-03-01" end: "2013-04-01" - closed: 'left' # end is not inclusive + inclusive: 'left' # end is not inclusive enable: prepare_links_p_nom: false diff --git a/scripts/build_load_data.py b/scripts/build_load_data.py index 10921782..3c11b947 100755 --- a/scripts/build_load_data.py +++ b/scripts/build_load_data.py @@ -116,14 +116,20 @@ def nan_statistics(df): keys=['total', 'consecutive', 'max_total_per_month'], axis=1) -def copy_timeslice(load, cntry, start, stop, delta): +def copy_timeslice(load, cntry, start, stop, delta, fn_load=None): start = pd.Timestamp(start) stop = pd.Timestamp(stop) - if start-delta in load.index and stop in load.index and cntry in load: - load.loc[start:stop, cntry] = load.loc[start-delta:stop-delta, cntry].values + if (start in load.index and stop in load.index): + if start-delta in load.index and stop-delta in load.index and cntry in load: + load.loc[start:stop, cntry] = load.loc[start-delta:stop-delta, cntry].values + elif fn_load is not None: + duration = pd.date_range(freq='h', start=start-delta, end=stop-delta) + load_raw = load_timeseries(fn_load, duration, [cntry], powerstatistics) + if start-delta in load_raw.index and stop-delta in load_raw.index and cntry in load_raw: + load.loc[start:stop, cntry] = load_raw.loc[start-delta:stop-delta, cntry].values -def manual_adjustment(load, powerstatistics): +def manual_adjustment(load, fn_load, powerstatistics): """ Adjust gaps manual for load data from OPSD time-series package. @@ -150,6 +156,8 @@ def manual_adjustment(load, powerstatistics): powerstatistics: bool Whether argument load comprises the electricity consumption data of the ENTSOE power statistics or of the ENTSOE transparency map + load_fn: str + File name or url location (file format .csv) Returns ------- @@ -175,7 +183,11 @@ def manual_adjustment(load, powerstatistics): copy_timeslice(load, 'CH', '2010-11-04 04:00', '2010-11-04 22:00', Delta(days=1)) copy_timeslice(load, 'NO', '2010-12-09 11:00', '2010-12-09 18:00', Delta(days=1)) # whole january missing - copy_timeslice(load, 'GB', '2009-12-31 23:00', '2010-01-31 23:00', Delta(days=-364)) + copy_timeslice(load, 'GB', '2010-01-01 00:00', '2010-01-31 23:00', Delta(days=-365), fn_load) + # 1.1. at midnight gets special treatment + copy_timeslice(load, 'IE', '2016-01-01 00:00', '2016-01-01 01:00', Delta(days=-366), fn_load) + copy_timeslice(load, 'PT', '2016-01-01 00:00', '2016-01-01 01:00', Delta(days=-366), fn_load) + copy_timeslice(load, 'GB', '2016-01-01 00:00', '2016-01-01 01:00', Delta(days=-366), fn_load) else: if 'ME' in load: @@ -206,7 +218,7 @@ if __name__ == "__main__": load = load_timeseries(snakemake.input[0], years, countries, powerstatistics) if snakemake.config['load']['manual_adjustments']: - load = manual_adjustment(load, powerstatistics) + load = manual_adjustment(load, snakemake.input[0], powerstatistics) logger.info(f"Linearly interpolate gaps of size {interpolate_limit} and less.") load = load.interpolate(method='linear', limit=interpolate_limit)