From 813babd070536e57afa5efbece1f3a71ceb6591c Mon Sep 17 00:00:00 2001 From: SabineHaas Date: Tue, 10 Dec 2024 14:18:10 +0100 Subject: [PATCH] Put max parameter back to output_parameters --- data_adapter_oemof/adapters.py | 9 +++++++-- data_adapter_oemof/build_datapackage.py | 6 ------ data_adapter_oemof/calculations.py | 10 ++++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/data_adapter_oemof/adapters.py b/data_adapter_oemof/adapters.py index 30dd030..2a5bf95 100644 --- a/data_adapter_oemof/adapters.py +++ b/data_adapter_oemof/adapters.py @@ -79,8 +79,6 @@ def get_default_parameters(self) -> dict: ) defaults = self.default_post_mapping_calculations(defaults) - if "max_profile" in defaults: - defaults["profile"] = defaults["max_profile"].columns[0] if not defaults["input_parameters"]: defaults.pop("input_parameters") if not defaults["output_parameters"]: @@ -356,12 +354,18 @@ def default_post_mapping_calculations(self, mapped_defaults): ------- """ + if len(self.structure["outputs"]) == 0: + change_parameter = "input_parameters" + else: + change_parameter = "output_parameters" + # I: if self.process_name[-1] == "0": mapped_defaults = calculations.decommission( process_name=self.process_name, adapter_dict=mapped_defaults, column="capacity", + input_output_parameters=change_parameter, ) elif self.process_name[-1] == "1" or self.process_name[-1] == "2": mapped_defaults["expandable"] = True @@ -389,6 +393,7 @@ def default_post_mapping_calculations(self, mapped_defaults): process_name=self.process_name, adapter_dict=mapped_defaults, column="amount", + input_output_parameters=change_parameter, ) # III: diff --git a/data_adapter_oemof/build_datapackage.py b/data_adapter_oemof/build_datapackage.py index 6044593..020f62f 100644 --- a/data_adapter_oemof/build_datapackage.py +++ b/data_adapter_oemof/build_datapackage.py @@ -560,12 +560,6 @@ def _reduce_lists(x): constraint_parameters = pd.DataFrame(components) else: parametrized_elements[process_name] = pd.DataFrame(components) - - # if 'max_profile' exists the time series is added in `timeseries` and removed from `parametrized_elements` - # todo un-hard-code --> max_profile is set in calculations.decommission() which is called by Adapter.default_post_mapping_calculations() - if "max_profile" in parametrized_elements[process_name]: - timeseries = parametrized_elements[process_name]["max_profile"][0] - parametrized_elements[process_name].drop(columns=["max_profile"], inplace=True) if not timeseries.empty: parametrized_sequences.update({process_name: timeseries}) # Create Bus Element from all unique `busses` found in elements diff --git a/data_adapter_oemof/calculations.py b/data_adapter_oemof/calculations.py index dfb971f..9073faf 100644 --- a/data_adapter_oemof/calculations.py +++ b/data_adapter_oemof/calculations.py @@ -46,7 +46,7 @@ def get_capacity_cost(overnight_cost, fixed_cost, lifetime, wacc): def decommission( - process_name, adapter_dict: dict, column: str = "capacity", max_column: str = "max", + process_name, adapter_dict: dict, column: str = "capacity", max_column: str = "max", input_output_parameters: str = "output_parameters", ) -> dict: """ @@ -93,18 +93,18 @@ def decommission( return adapter_dict # I: - if max_column not in adapter_dict["output_parameters"].keys(): + if max_column not in adapter_dict[input_output_parameters].keys(): max = list(adapter_dict[column] / np.nanmax(adapter_dict[column])) # II: else: max = list(multiply_two_lists( - adapter_dict["output_parameters"][max_column], + adapter_dict[input_output_parameters][max_column], adapter_dict[column] ) / np.nanmax(adapter_dict[column])) # max must be extended to time series over all time steps of each period - column_name = ["max_timeseries"] + 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, @@ -114,6 +114,8 @@ def decommission( 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]) # set `column` value to maximum value adapter_dict[column] = np.nanmax(adapter_dict[column])