Skip to content

Commit

Permalink
correct total cost for missing storage
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Nov 8, 2024
1 parent 941bbf2 commit 4e2a6ab
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/otoole/results/result_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,6 @@ def total_discounted_cost(self) -> pd.DataFrame:
"""
try:
discounted_cost_by_technology = self["DiscountedCostByTechnology"]
discounted_cost_by_storage = self["DiscountedCostByStorage"]

except KeyError as ex:
raise KeyError(self._msg("TotalDiscountedCost", str(ex)))

Expand All @@ -963,14 +961,26 @@ def total_discounted_cost(self) -> pd.DataFrame:
.groupby(["REGION", "YEAR"])
.sum()
)
discounted_storage = (
discounted_cost_by_storage.droplevel("STORAGE")
.reset_index()
.groupby(["REGION", "YEAR"])
.sum()
)

total_discounted_cost = discounted_tech.add(discounted_storage, fill_value=0)
try:
discounted_cost_by_storage = self["DiscountedCostByStorage"]

discounted_storage = (
discounted_cost_by_storage.droplevel("STORAGE")
.reset_index()
.groupby(["REGION", "YEAR"])
.sum()
)
except KeyError as ex: # storage not always included
LOGGER.debug(ex)

discounted_storage = pd.DataFrame(
columns=["REGION", "YEAR", "VALUE"]
).set_index(["REGION", "YEAR"])

total_discounted_cost = discounted_tech.add(
discounted_storage, fill_value=0
).astype(float)

data = total_discounted_cost

Expand Down
22 changes: 22 additions & 0 deletions tests/results/test_results_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,28 @@ def test_calculate_total_discounted_cost(

assert_frame_equal(actual, expected)

def test_calculate_total_discounted_cost_no_storage(
self, discounted_technology_cost
):
"""Situations where NewStorageCapacity not available"""

results = {
"DiscountedCostByTechnology": discounted_technology_cost,
}

package = ResultsPackage(results)
actual = package.total_discounted_cost()
expected = pd.DataFrame(
data=[
["SIMPLICITY", 2014, 555.0],
["SIMPLICITY", 2015, 777.0],
["SIMPLICITY", 2016, 999.0],
],
columns=["REGION", "YEAR", "VALUE"],
).set_index(["REGION", "YEAR"])

assert_frame_equal(actual, expected)

def test_null(self, null: ResultsPackage):
""" """
package = null
Expand Down

0 comments on commit 4e2a6ab

Please sign in to comment.