From 4bc19ead1eb4dd43b6f4c48c5dbb1d0723e25077 Mon Sep 17 00:00:00 2001 From: LukasFrankenQ Date: Sun, 13 Aug 2023 13:57:41 +0100 Subject: [PATCH] fixed bug in weekly plotting --- config/config.yaml | 22 ++++++++++++---------- scripts/plot_timeseries.py | 29 +++++++++++++++++++++++------ scripts/prepare_network.py | 2 +- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 9e6cca6d..96b06231 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -27,8 +27,8 @@ scenario: - 'eso' # regions can be 'eso' zones (emphasizing grid conjestion), or 'dno' fes: # Future energy scenario considered, can be # - 'CT' # Consumer Transformation - - 'FS' # Falling Short - # - 'LW' # Leading the Way + # - 'FS' # Falling Short + - 'LW' # Leading the Way # - 'ST' # System Transformation year: # investment years for myopic and perfect; for overnight, year of cost assumptions can be different and is defined under 'costs' - 2023 @@ -65,7 +65,7 @@ flexibility: winter_months: [12, 1, 2] event_start_hour: 17 event_end_hour: 19 - heat_share_smart_tariff: 0.5 # share of consumers with heat pumps that have a smart tariff + smart_heat_rollout_completion: 2030 # year where all heat pumps contribute to smart heat heat_shift_size: 3 # hours heat_flex_windows: morning: @@ -122,15 +122,17 @@ flexibility: freq: h month: 1 year: - freq: d + freq: w shortweek: - freq: h - start: 2022-01-21 - end: 2022-01-27 + start_month: 1 + start_day: 21 + end_month: 1 + end_day: 27 longweek: - freq: h - start: 2022-10-28 - end: 2022-11-04 + start_month: 10 + start_day: 28 + end_month: 11 + end_day: 4 do_group: true do_group_flex: false add_kirchhoff: true diff --git a/scripts/plot_timeseries.py b/scripts/plot_timeseries.py index 57eb0622..97e1776c 100644 --- a/scripts/plot_timeseries.py +++ b/scripts/plot_timeseries.py @@ -187,14 +187,14 @@ def make_co2_barplot(n): plt.show() -def get_timeseries_subset(*args , timeseries_mode="month", config=None): +def get_timeseries_subset(*args, timeseries_mode="month", config=None): + + assert args, "No dataframes passed" assert sum( [isinstance(arg, pd.DataFrame) or isinstance(arg, pd.Series) for arg in args]) == len(args), "Only one DataFrame can be passed as argument" - assert config is not None, "kwarg config has to be passed as non-None value" - if (mode := timeseries_mode) in ["month", "year"]: freq = config["flexibility"]["timeseries_params"][mode].get("freq", "1H") month = config["flexibility"]["timeseries_params"][mode].get("month", range(1, 13)) @@ -207,15 +207,29 @@ def get_timeseries_subset(*args , timeseries_mode="month", config=None): elif mode in ["shortweek", "longweek"]: - start = config["flexibility"]["timeseries_params"][mode]["start"] - end = config["flexibility"]["timeseries_params"][mode]["end"] - s = args[0].index[(args[0].index >= pd.Timestamp(start)) & (args[0].index <= pd.Timestamp(end))] + frame = config["flexibility"]["timeseries_params"][mode] + + start = pd.Timestamp( + year=2022, + month=frame["start_month"], + day=frame["start_day"] + ) + + end = pd.Timestamp( + year=2022, + month=frame["end_month"], + day=frame["end_day"] + ) + + s = args[0].index[(args[0].index >= start) & (args[0].index <= end)] args = list(map(lambda x: x.loc[s], args)) else: raise ValueError(f"Unknown mode {mode}, should be one of 'month', 'year', 'shortweek', 'longweek'") + + return args if __name__ == "__main__": @@ -274,6 +288,9 @@ def get_timeseries_subset(*args , timeseries_mode="month", config=None): # def get_timeseries_subset(*args , timeseries_mode="month", config=None): ts_mode = snakemake.wildcards["timeseries_mode"] + + logger.info(f"Found time series mode {ts_mode}.") + inflow, outflow = get_timeseries_subset(inflow, outflow, timeseries_mode=ts_mode, config=snakemake.config, diff --git a/scripts/prepare_network.py b/scripts/prepare_network.py index 03c41847..45a6889e 100755 --- a/scripts/prepare_network.py +++ b/scripts/prepare_network.py @@ -560,7 +560,7 @@ def add_heat_pump_load( complete_rollout_year = snakemake.config["flexibility"]["heat_shift_size"] share_smart_tariff = np.interp( - year, + year, [2023, complete_rollout_year], [0., 1.] )