From 2fdcf31e5beb2deb6b2a3a5a4f0e2707cbd776f5 Mon Sep 17 00:00:00 2001 From: "stefan.schirmeister" Date: Fri, 1 Nov 2024 14:03:25 +0100 Subject: [PATCH] calc_cost: return peak_power_in_windows --- spice_ev/costs.py | 15 +++++++++------ tests/test_calculate_costs.py | 12 ++++++------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/spice_ev/costs.py b/spice_ev/costs.py index 0abd2512..e3b47303 100644 --- a/spice_ev/costs.py +++ b/spice_ev/costs.py @@ -217,6 +217,12 @@ def calculate_costs(cc_type, voltage_level, interval, # only consider positive values of fixed load for cost calculation power_fix_load_list = [max(v, 0) for v in power_fix_load_list] + # get peak power inside time windows + peak_power_in_windows = None + if window_signal_list is not None: + window_loads = [l for (l, w) in zip(power_grid_supply_list, window_signal_list) if w] + peak_power_in_windows = max(window_loads + [0]) + energy_supply_sim = sum(power_grid_supply_list) * interval.total_seconds() / 3600 energy_supply_pa = energy_supply_sim / fraction_year @@ -275,14 +281,10 @@ def calculate_costs(cc_type, voltage_level, interval, if cc_type.endswith("w_plw"): # peak load windows: adjust capacity costs by changing max_power_grid_supply - # get peak power inside time windows if window_signal_list is None: # no time windows: no window loads -> peak power is set to 0 - window_loads = [] - else: - window_loads = [l for (l, w) in - zip(power_grid_supply_list, window_signal_list) if w] - peak_power_in_windows = max(window_loads + [0]) + warnings.warn("PLW without window signal list, setting peak power to zero") + peak_power_in_windows = 0 # check if cost calculation for peak_load_window can be applied significance_threshold = 0 if max_power_grid_supply > 0: @@ -905,4 +907,5 @@ def calculate_costs(cc_type, voltage_level, interval, "power_procurement_costs_per_year": power_procurement_costs_per_year, "levies_fees_and_taxes_per_year": levies_fees_and_taxes_per_year, "feed_in_remuneration_per_year": feed_in_remuneration_per_year, + "peak_power_in_windows": peak_power_in_windows, } diff --git a/tests/test_calculate_costs.py b/tests/test_calculate_costs.py index a39c295d..e94cd0e6 100644 --- a/tests/test_calculate_costs.py +++ b/tests/test_calculate_costs.py @@ -106,12 +106,12 @@ def test_calculate_costs_basic(self): def test_calculate_costs_advanced(self): scenarios = { - "scenario_A.json": [2522.67, 776.54, 65.7, 799.38, 881.06, 0.0], - "scenario_B.json": [99.63, 6.81, 65.7, 7.01, 20.1, 0.0], - "scenario_C1.json": [99.63, 6.81, 65.7, 7.01, 20.1, 0.0], - "scenario_C2.json": [2792.23, 862.17, 65.7, 887.53, 976.85, 0.0], - "scenario_C3.json": [1887.55, 574.78, 65.7, 591.68, 655.39, 0.0], - "scenario_PV_Bat.json": [-2166.39, 0.0, 65.7, 0.0, 12.48, 2244.58], + "scenario_A.json": [2522.67, 776.54, 65.7, 799.38, 881.06, 0.0, 0.0], + "scenario_B.json": [99.63, 6.81, 65.7, 7.01, 20.1, 0.0, 0.0], + "scenario_C1.json": [99.63, 6.81, 65.7, 7.01, 20.1, 0.0, 0.063], + "scenario_C2.json": [2792.23, 862.17, 65.7, 887.53, 976.85, 0.0, 22.0], + "scenario_C3.json": [1887.55, 574.78, 65.7, 591.68, 655.39, 0.0, 0.0], + "scenario_PV_Bat.json": [-2166.39, 0.0, 65.7, 0.0, 12.48, 2244.58, 0.0], } for scenario_name, expected in scenarios.items():