Skip to content

Commit

Permalink
update total discounted cost calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorb1 committed Nov 8, 2024
1 parent 5f13fc2 commit f5ff217
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
24 changes: 23 additions & 1 deletion src/otoole/results/result_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,36 @@ def total_discounted_cost(self) -> pd.DataFrame:
- SalvageValueStorage[r,s,y] / ((1+DiscountRateStorage[r,s])^(max{yy in YEAR} max(yy)-min{yy in YEAR} min(yy)+1))
)
) ~VALUE;
Alternatively, can be written as::
r~REGION, y~YEAR,
TotalDiscountedCost[r,y] :=
sum{t in TECHNOLOGY} TotalDiscountedCostByTechnology[r,t,y] + sum{s in STORAGE} TotalDiscountedStorageCost[r,s,y]
"""
try:
discounted_cost_by_technology = self["DiscountedCostByTechnology"]
discounted_cost_by_storage = self["DiscountedCostByStorage"]

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

data = discounted_cost_by_technology
discounted_tech = (
discounted_cost_by_technology.droplevel("TECHNOLOGY")
.reset_index()
.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)

data = total_discounted_cost

if not data.empty:
data = data.groupby(by=["REGION", "YEAR"]).sum()
Expand Down
26 changes: 13 additions & 13 deletions tests/results/test_results_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,15 +444,15 @@ def discounted_salvage_value_storage():
def discounted_storage_cost():
data = pd.DataFrame(
data=[
["SIMPLICITY", "DUMMY", 2014, 111],
["SIMPLICITY", "DUMMY", 2015, 222],
["SIMPLICITY", "DUMMY", 2016, 333],
["SIMPLICITY", "GAS_EXTRACTION", 2014, 444],
["SIMPLICITY", "GAS_EXTRACTION", 2015, 555],
["SIMPLICITY", "GAS_EXTRACTION", 2016, 666],
["SIMPLICITY", "DAM", 2014, 11.1],
["SIMPLICITY", "DAM", 2015, 22.2],
["SIMPLICITY", "DAM", 2016, 33.3],
["SIMPLICITY", "BATTERY", 2014, 44.4],
["SIMPLICITY", "BATTERY", 2015, 55.5],
["SIMPLICITY", "BATTERY", 2016, 66.6],
],
columns=["REGION", "TECHNOLOGY", "YEAR", "VALUE"],
).set_index(["REGION", "TECHNOLOGY", "YEAR"])
columns=["REGION", "STORAGE", "YEAR", "VALUE"],
).set_index(["REGION", "STORAGE", "YEAR"])
return data


Expand Down Expand Up @@ -1217,21 +1217,21 @@ def test_null(self, null: ResultsPackage):

class TestTotalDiscountedCost:
def test_calculate_total_discounted_cost(
self,
discounted_technology_cost,
self, discounted_technology_cost, discounted_storage_cost
):

results = {
"DiscountedCostByTechnology": discounted_technology_cost,
"DiscountedCostByStorage": discounted_storage_cost,
}

package = ResultsPackage(results)
actual = package.total_discounted_cost()
expected = pd.DataFrame(
data=[
["SIMPLICITY", 2014, 555],
["SIMPLICITY", 2015, 777],
["SIMPLICITY", 2016, 999],
["SIMPLICITY", 2014, 610.5],
["SIMPLICITY", 2015, 854.7],
["SIMPLICITY", 2016, 1098.9],
],
columns=["REGION", "YEAR", "VALUE"],
).set_index(["REGION", "YEAR"])
Expand Down

0 comments on commit f5ff217

Please sign in to comment.