Skip to content

Commit

Permalink
Fix invested (storage) capacity for multi-period simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
henhuy committed Jul 26, 2023
1 parent 08fbe49 commit f933242
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions src/oemof/tabular/postprocessing/calculations.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from abc import abstractmethod
from typing import List

Expand Down Expand Up @@ -114,11 +115,11 @@ class Investment(core.Calculation):
name = "investment"

def calculate_result(self):
return (
pd.Series(dtype="object")
if (self.scalars is None or self.scalars.empty)
else helper.filter_by_var_name(self.scalars, "invest")
)
if self.scalars is None or self.scalars.empty:
if self.calculator.is_multi_period:
return pd.DataFrame(dtype="object")
return pd.Series(dtype="object")
return helper.filter_by_var_name(self.scalars, "invest")


class EPCosts(core.Calculation):
Expand All @@ -142,7 +143,7 @@ class InvestedCapacity(core.Calculation):

def calculate_result(self):
if self.dependency("investment").empty:
return pd.Series(dtype="object")
return self.dependency("investment")
target_is_none = (
self.dependency("investment").index.get_level_values(1).isnull()
)
Expand All @@ -157,7 +158,7 @@ class InvestedStorageCapacity(core.Calculation):

def calculate_result(self):
if self.dependency("investment").empty:
return pd.Series(dtype="object")
return self.dependency("investment")
target_is_none = (
self.dependency("investment").index.get_level_values(1).isnull()
)
Expand All @@ -172,11 +173,22 @@ class InvestedCapacityCosts(core.Calculation):
}

def calculate_result(self):
invested_capacity_costs = helper.multiply_var_with_param(
self.dependency("invested_capacity"), self.dependency("ep_costs")
)
if self.calculator.is_multi_period:
warnings.warn(
"Multi period investment not implemented for varying "
"costs per period"
)
invested_capacity_costs = helper.multiply_var_with_param(
self.dependency("invested_capacity").sum(axis=1),
self.dependency("ep_costs"),
)
else:
invested_capacity_costs = helper.multiply_var_with_param(
self.dependency("invested_capacity"),
self.dependency("ep_costs"),
)
if invested_capacity_costs.empty:
return pd.Series(dtype="object")
return invested_capacity_costs
invested_capacity_costs.index = (
invested_capacity_costs.index.set_levels(
invested_capacity_costs.index.levels[2] + "_costs", level=2
Expand All @@ -193,10 +205,20 @@ class InvestedStorageCapacityCosts(core.Calculation):
}

def calculate_result(self):
invested_storage_capacity_costs = helper.multiply_var_with_param(
self.dependency("invested_storage_capacity"),
self.dependency("ep_costs"),
)
if self.calculator.is_multi_period:
warnings.warn(
"Multi period investment not implemented for varying "
"costs per period"
)
invested_storage_capacity_costs = helper.multiply_var_with_param(
self.dependency("invested_storage_capacity").sum(axis=1),
self.dependency("ep_costs"),
)
else:
invested_storage_capacity_costs = helper.multiply_var_with_param(
self.dependency("invested_storage_capacity"),
self.dependency("ep_costs"),
)
if invested_storage_capacity_costs.empty:
return pd.Series(dtype="object")
invested_storage_capacity_costs.index = (
Expand Down Expand Up @@ -300,8 +322,6 @@ def run_postprocessing(es) -> pd.DataFrame:
aggregated_flows = AggregatedFlows(calculator).result
storage_losses = StorageLosses(calculator).result
transmission_losses = TransmissionLosses(calculator).result
invested_capacity = InvestedCapacity(calculator).result
invested_storage_capacity = InvestedStorageCapacity(calculator).result
invested_capacity_costs = InvestedCapacityCosts(calculator).result
invested_storage_capacity_costs = InvestedStorageCapacityCosts(
calculator
Expand All @@ -315,8 +335,6 @@ def run_postprocessing(es) -> pd.DataFrame:
aggregated_flows,
storage_losses,
transmission_losses,
invested_capacity,
invested_storage_capacity,
invested_capacity_costs,
invested_storage_capacity_costs,
summed_carrier_costs,
Expand Down

0 comments on commit f933242

Please sign in to comment.