[Bug]: Error calculating overnight capital cost when CRP is 0
gschivley opened this issue · comments
Bug description
When running multi-period foresight, GenX throws an error when calculating the overnight capital cost if the Capital_Recovery_Period
value is 0 for any resources. The parameter payment_yrs_remaining
has a value of 0 for those resources and the code is unable to iterate over p=1:payment_yrs_remaining[I]
. The error given is ERROR: LoadError: MethodError: reducing over an empty collection is not allowed; consider supplying
init to the reducer
.
Since existing resources usually don't have an investment cost in GenX inputs, it doesn't make sense to require that they have a non-zero Capital_Recovery_Period
. A blunt fix would be to change zeros to ones.
payment_yrs_remaining = min.(crp, model_yrs_remaining)
payment_yrs_remaining = max.(payment_yrs_remaining, 1)
Another possible fix would be to only calculate occ
if investment costs are non-zero.
occ = zeros(length(inv_costs_yr))
for i in 1:length(occ)
if inv_costs_yr[i] > 0
occ[i] = sum(inv_costs_yr[i]/(1+tech_wacc[i]) .^ (p) for p=1:payment_yrs_remaining[i])
end
end
This would still raise an error if a resource with non-zero investment costs has a crp of 0. Either way, it would be helpful if the code checked for this sort of condition and alerted the user that there might be a problem.
Environment and Version
MacOS, Julia 1.9, GenX 3.6
Relevant error messages
No response
Additional context
No response
@gschivley , the draft PR #666 when completed will fix this. I am bringing in the init=0 in the sum expression to fix the bug. We have dome this elsewhere in the DDP code.
This is now fixed on the release branch.