Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Incorrect Total Discounted Cost Calculation #237

Closed
trevorb1 opened this issue Oct 26, 2024 · 1 comment
Closed

[Bug]: Incorrect Total Discounted Cost Calculation #237

trevorb1 opened this issue Oct 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@trevorb1
Copy link
Member

trevorb1 commented Oct 26, 2024

The Issue

I believe the otoole total discounted cost calculation is not currently taking into account storage costs.

def total_discounted_cost(self) -> pd.DataFrame:
"""TotalDiscountedCost
Notes
-----
From the formulation::
r~REGION, y~YEAR,
sum{t in TECHNOLOGY}
(
(
(
(
sum{yy in YEAR: y-yy < OperationalLife[r,t] && y-yy>=0}
NewCapacity[r,t,yy]
)
+ ResidualCapacity[r,t,y]
)
* FixedCost[r,t,y]
+ sum{l in TIMESLICE, m in MODEperTECHNOLOGY[t]}
RateOfActivity[r,l,t,m,y] * YearSplit[l,y] * VariableCost[r,t,m,y]
)
/ (DiscountFactorMid[r,y])
+ CapitalCost[r,t,y] * NewCapacity[r,t,y] * CapitalRecoveryFactor[r,t] * PvAnnuity[r,t] / (DiscountFactor[r,y])
+ DiscountedTechnologyEmissionsPenalty[r,t,y] - DiscountedSalvageValue[r,t,y])
+ sum{s in STORAGE}
(
CapitalCostStorage[r,s,y] * NewStorageCapacity[r,s,y] / (DiscountFactorStorage[r,s,y])
- CapitalCostStorage[r,s,y] * NewStorageCapacity[r,s,y] / (DiscountFactorStorage[r,s,y]
)
) ~VALUE;
"""
try:
discount_rate = self["DiscountRate"]
year_df = self["YEAR"].copy(deep=True)
region_df = self["REGION"].copy(deep=True)
years = year_df["VALUE"].tolist()
regions = region_df["VALUE"].tolist()
annual_fixed_operating_cost = self["AnnualFixedOperatingCost"]
annual_variable_operating_cost = self["AnnualVariableOperatingCost"]
capital_investment = self["CapitalInvestment"]
discounted_emissions_penalty = self["DiscountedTechnologyEmissionsPenalty"]
discounted_salvage_value = self["DiscountedSalvageValue"]
# capital_cost_storage = self["CapitalCostStorage"]
except KeyError as ex:
raise KeyError(self._msg("TotalDiscountedCost", str(ex)))
df_start = discount_factor(regions, years, discount_rate, 0.0)
df_mid = discount_factor(regions, years, discount_rate, 0.5)
undiscounted_operational_costs = annual_fixed_operating_cost.add(
annual_variable_operating_cost, fill_value=0.0
)
discounted_operational_costs = undiscounted_operational_costs.div(
df_mid, fill_value=0.0
)
discounted_capital_costs = capital_investment.div(df_start, fill_value=0.0)
discounted_total_costs = discounted_operational_costs.add(
discounted_capital_costs, fill_value=0.0
)
discounted_total_costs = discounted_total_costs.add(
discounted_emissions_penalty, fill_value=0.0
)
discounted_total_costs = discounted_total_costs.sub(
discounted_salvage_value, fill_value=0.0
)
data = discounted_total_costs
if not data.empty:
data = data.groupby(by=["REGION", "YEAR"]).sum()
return data[(data != 0).all(1)].dropna()

This issue originated from a bug in the OSeMOSYS objective equation, as described here, with fixes here and here. However, the otoole calc has not been updated to reflect these updates.

Expected Behavior

No response

Steps To Reproduce

No response

Log output

No response

Operating System

Linux

What version of otoole are you running?

1.1.3

Possible Solution

No response

Anything else?

No response

@trevorb1
Copy link
Member Author

closes with #240

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant