Skip to content

Commit

Permalink
calc_cost: return peak_power_in_windows
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan.schirmeister committed Nov 1, 2024
1 parent 5d44561 commit 2fdcf31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 9 additions & 6 deletions spice_ev/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
}
12 changes: 6 additions & 6 deletions tests/test_calculate_costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 2fdcf31

Please sign in to comment.