From feb2856755f587633fc4f4b59e90d6d3ab5d088f Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Thu, 12 Dec 2024 11:05:18 +0100 Subject: [PATCH] decomissioning via flow shares for mimo --- data_adapter_oemof/calculations.py | 48 ++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/data_adapter_oemof/calculations.py b/data_adapter_oemof/calculations.py index fdeb441..3b37d6d 100644 --- a/data_adapter_oemof/calculations.py +++ b/data_adapter_oemof/calculations.py @@ -93,29 +93,47 @@ def decommission( return adapter_dict # I: - if max_column not in adapter_dict[input_output_parameters].keys(): + if change_parameter not in ["input_parameters", "output_parameters"]: + # this occurs e.g. for flow_share_max of mimo + # still max might be set in parameters + parameter = "output_parameters" + else: + parameter = change_parameter + if max_column not in adapter_dict[parameter].keys(): max = list(adapter_dict[column] / np.nanmax(adapter_dict[column])) # II: else: max = list(multiply_two_lists( - adapter_dict[input_output_parameters][max_column], + adapter_dict[parameter][max_column], adapter_dict[column] ) / np.nanmax(adapter_dict[column])) + if change_parameter != parameter: + # drop max output_parameters, as max_column is saved in `change_parameter` + del adapter_dict[parameter][max_column] - # max must be extended to time series over all time steps of each period - column_name = [f"max_timeseries_{process_name}"] - timeseries = pd.DataFrame(columns=column_name) - for y in adapter_dict["year"]: - ts = pd.DataFrame(data=[1 for i in range(8760)], columns=column_name, - index=pd.date_range(f"1/1/{y}", periods=8760, freq="h"), - dtype="float64") - timeseries = ts.copy() if timeseries.empty else pd.concat([timeseries, ts]) - max_time_series = adapt_profile_with_yearly_value(profile=timeseries, value=max) - - adapter_dict["max_profile"] = max_time_series - adapter_dict[input_output_parameters][max_column] = list(max_time_series[column_name[0]].values) - adapter_dict[input_output_parameters] = json.dumps(adapter_dict[input_output_parameters]) + if change_parameter != parameter: + # e.g. flow_share_max_ + adapter_dict[change_parameter] = max + else: + # max must be extended to time series over all time steps of each + # period as output_parameters are not extended in oemof.tabular + column_name = [f"max_timeseries_{process_name}"] + timeseries = pd.DataFrame(columns=column_name) + for y in adapter_dict["year"]: + ts = pd.DataFrame(data=[1 for i in range(8760)], + columns=column_name, + index=pd.date_range(f"1/1/{y}", periods=8760, + freq="h"), + dtype="float64") + timeseries = ts.copy() if timeseries.empty else pd.concat( + [timeseries, ts]) + max_time_series = adapt_profile_with_yearly_value(profile=timeseries, + value=max) + + max_time_series = reduce_data_frame(max_time_series) # todo delete + adapter_dict[change_parameter][max_column] = list(max_time_series[column_name[0]].values) + adapter_dict[change_parameter] = json.dumps(adapter_dict[change_parameter]) # set `column` value to maximum value adapter_dict[column] = np.nanmax(adapter_dict[column])