Skip to content

Commit

Permalink
Depreciation updates (#16)
Browse files Browse the repository at this point in the history
* Correct default for pv plus battery in debt fraction calculator, update depreciation assumptions for 2024 atb

* Update test data for latest tax credit assumptions

* Fix CRP as string bug (#15)

* Fix CRP as string bug

* rename self._crp to remove ambiguity

* add missing docstring

---------

Co-authored-by: Mike Bannister <[email protected]>
  • Loading branch information
brtietz and mikebannis authored Apr 12, 2024
1 parent 78ef620 commit cdeb16a
Show file tree
Hide file tree
Showing 616 changed files with 13,509 additions and 13,493 deletions.
3 changes: 1 addition & 2 deletions debt_fraction_calculator/debt_fraction_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def calculate_all_debt_fractions(data_workbook_filename: str, output_filename: s
click.echo(f"Processing tech {Tech.tech_name} and financial case {fin_case}")
debt_fracs = [Tech.tech_name, fin_case] # First two columns are metadata

proc = Tech(data_workbook_filename, crp=crp, case=fin_case)
proc = Tech(data_workbook_filename, crp=crp, case=fin_case, tcc=PTC_PLUS_ITC_CASE_PVB)
proc.run()

d = proc.flat
Expand Down Expand Up @@ -290,7 +290,6 @@ def calculate_all_debt_fractions(data_workbook_filename: str, output_filename: s
if Tech.has_tax_credit and fin_case == 'Market':
if Tech.sheet_name == "Utility-Scale PV-Plus-Battery":
if proc.tax_credit_case is PTC_PLUS_ITC_CASE_PVB and year > 2022:

ncf = proc.df_ncf.loc[Tech.default_tech_detail + '/Moderate'][year]
pvcf = proc.df_pvcf.loc[Tech.default_tech_detail + '/Moderate'][year]

Expand Down
13 changes: 5 additions & 8 deletions example_notebooks/Process ATB electricity technology.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"outputs": [],
"source": [
"# The below line MUST be updated to reflect the location of the ATB workbook on your computer\n",
"atb_electricity_workbook = 'path/to/2023_v2_Workbook_Corrected_07_20_23.xlsx'"
"atb_electricity_workbook = 'path/to/2024-ATB-Data_Workbook.xlsx'"
]
},
{
Expand All @@ -80,9 +80,7 @@
"cell_type": "code",
"execution_count": null,
"id": "0be06180",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# The CRP may be one of 20, 30, or 'TechLife' in quotes\n",
Expand All @@ -99,6 +97,7 @@
"# Microsoft Excel may open and ask for permission to view the workbook. \n",
"proc = OffShoreWindProc(atb_electricity_workbook, crp=crp, case=financial_case)\n",
"\n",
"# proc = NuclearProc(atb_electricity_workbook, crp=crp, case=financial_case)\n",
"# proc = UtilityPvProc(atb_electricity_workbook, crp=crp, case=financial_case)\n",
"# proc = NaturalGasProc(atb_electricity_workbook, crp=crp, case=financial_case)\n",
"# proc = NuclearProc(atb_electricity_workbook, crp=crp, case=financial_case)"
Expand Down Expand Up @@ -136,9 +135,7 @@
"cell_type": "code",
"execution_count": null,
"id": "d152b8d3",
"metadata": {
"scrolled": false
},
"metadata": {},
"outputs": [],
"source": [
"# Run the pipeline\n",
Expand Down Expand Up @@ -238,7 +235,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
37 changes: 28 additions & 9 deletions lcoe_calculator/base_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def __init__(
@param data_workbook_fname - name of workbook
@param case - financial case to run: 'Market' or 'R&D'
@param crp - capital recovery period: 20, 30, or 'TechLife'
@param tcc - tax credit case: 'ITC only' or 'PV PTC and Battery ITC' Only required for the PV plus battery technology.
@param extractor - Extractor class to use to obtain source data.
"""
assert case in FINANCIAL_CASES, (f'Financial case must be one of {FINANCIAL_CASES},'
Expand All @@ -126,7 +127,7 @@ def __init__(

self._data_workbook_fname = data_workbook_fname
self._case = case
self._crp = crp
self._requested_crp = crp
self._crp_years = self.tech_life if crp == 'TechLife' else crp
self._tech_years = range(self.base_year, END_YEAR + 1, 1)

Expand Down Expand Up @@ -342,11 +343,12 @@ def _calc_fcr(wacc, crp, pff, scenario):

def _extract_data(self):
""" Pull all data from the workbook """
crp_msg = self._crp if self._crp != 'TechLife' else f'TechLife ({self.tech_life})'
crp_msg = self._requested_crp if self._requested_crp != 'TechLife' \
else f'TechLife ({self.tech_life})'

print(f'Loading data from {self.sheet_name}, for {self._case} and {crp_msg}')
extractor = self._ExtractorClass(self._data_workbook_fname, self.sheet_name,
self._case, self._crp, self.scenarios, self.base_year)
self._case, self._requested_crp, self.scenarios, self.base_year)

print('\tLoading metrics')
for metric, var_name in self.metrics:
Expand Down Expand Up @@ -421,11 +423,7 @@ def _calc_con_fin_cost(self):
return df_cfc

def _calc_crf(self):
crp = self.df_fin.loc['Capital Recovery Period (Years)', 'Value']
assert isinstance(crp, (int, float, np.number)) and not np.isnan(crp),\
f'CRP must be a number, got "{crp}"'

df_crf = self.df_just_wacc/(1-(1/(1+self.df_just_wacc))**crp)
df_crf = self.df_just_wacc/(1-(1/(1+self.df_just_wacc))**self.crp)

# Relabel WACC index as CRF
df_crf = df_crf.reset_index()
Expand All @@ -435,6 +433,26 @@ def _calc_crf(self):

return df_crf

@property
def crp(self) -> float:
"""
Get CRP value from financial assumptions
@returns: CRP
"""
raw_crp = self.df_fin.loc['Capital Recovery Period (Years)', 'Value']

try:
crp = float(raw_crp)
except ValueError as err:
msg = f'Error converting CRP value ({raw_crp}) to a float: {err}.'
print(f'{msg} self.df_fin is:')
print(self.df_fin)
raise ValueError(msg) from err

assert not np.isnan(crp), f'CRP must be a number, got "{crp}", type is "{type(crp)}"'
return crp

def _calc_itc(self, itc_type=''):
"""
Calculate ITC if used
Expand Down Expand Up @@ -478,7 +496,8 @@ def _calc_pff(self, itc_type=''):

itc_schedule = self._calc_itc(itc_type=itc_type)

df_pff = (1 - df_tax_rate.values*df_pvd*(1-itc_schedule/2) - itc_schedule)/(1-df_tax_rate.values)
df_pff = (1 - df_tax_rate.values*df_pvd*(1-itc_schedule/2)
- itc_schedule)/(1-df_tax_rate.values)
df_pff.index = [f'PFF - {scenario}' for scenario in self.scenarios]
return df_pff

Expand Down
9 changes: 5 additions & 4 deletions lcoe_calculator/tech_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ def _calc_lcoe(self):

def _extract_data(self):
""" Pull all data from the workbook """
crp_msg = self._crp if self._crp != 'TechLife' else f'TechLife ({self.tech_life})'
crp_msg = self._requested_crp if self._requested_crp != 'TechLife' \
else f'TechLife ({self.tech_life})'

print(f'Loading data from {self.sheet_name}, for {self._case} and {crp_msg}')
extractor = self._ExtractorClass(self._data_workbook_fname, self.sheet_name,
self._case, self._crp, self.scenarios, self.base_year,
self._case, self._requested_crp, self.scenarios, self.base_year,
self.tax_credit_case)

print('\tLoading metrics')
Expand Down Expand Up @@ -260,7 +261,7 @@ class HydropowerProc(TechProcessor):
dscr = 1.35

def get_depreciation_schedule(self, year):
if self._case is MARKET_FIN_CASE and (year < 2025 or year > 2045):
if self._case is MARKET_FIN_CASE and (year < 2025):
return MACRS_21
else:
return MACRS_6
Expand Down Expand Up @@ -488,7 +489,7 @@ def _calc_lcoe(self):
return df_lcoe

def get_depreciation_schedule(self, year):
if self._case is MARKET_FIN_CASE and (year < 2025 or year > 2045):
if self._case is MARKET_FIN_CASE and (year < 2025):
return MACRS_16
else:
return MACRS_6
Expand Down
6 changes: 3 additions & 3 deletions tests/data/Biopower/Market/20/df_capex.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tech_detail-scenario,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047,2048,2049,2050
Biopower - Dedicated/Advanced,5536.752209646431,5349.6018277413195,5162.451445836207,5013.530952458399,4922.365910860245,4874.0872874229235,4842.732601570261,4813.686228972017,4785.495097090659,4749.265620883151,4715.754141250931,4687.665038076443,4658.282349854457,4629.742024622757,4597.048815618196,4564.639503710362,4534.9771882427085,4500.27726616069,4470.162637583919,4443.202117047325,4411.35426890079,4383.2134668585195,4352.77158601805,4320.3520428262345,4288.590689990121,4258.486734509347,4226.488929038134,4192.682044837858,4141.864709511577
Biopower - Dedicated/Moderate,5536.752209646431,5349.6018277413195,5162.451445836207,5013.530952458399,4922.365910860245,4874.0872874229235,4842.732601570261,4813.686228972017,4785.495097090659,4749.265620883151,4715.754141250931,4687.665038076443,4658.282349854457,4629.742024622757,4597.048815618196,4564.639503710362,4534.9771882427085,4500.27726616069,4470.162637583919,4443.202117047325,4411.35426890079,4383.2134668585195,4352.77158601805,4320.3520428262345,4288.590689990121,4258.486734509347,4226.488929038134,4192.682044837858,4141.864709511577
Biopower - Dedicated/Conservative,5536.752209646431,5349.6018277413195,5162.451445836207,5013.530952458399,4922.365910860245,4874.0872874229235,4842.732601570261,4813.686228972017,4785.495097090659,4749.265620883151,4715.754141250931,4687.665038076443,4658.282349854457,4629.742024622757,4597.048815618196,4564.639503710362,4534.9771882427085,4500.27726616069,4470.162637583919,4443.202117047325,4411.35426890079,4383.2134668585195,4352.77158601805,4320.3520428262345,4288.590689990121,4258.486734509347,4226.488929038134,4192.682044837858,4141.864709511577
Biopower - Dedicated/Advanced,5528.187826509868,5341.326933372557,5154.466040235246,5005.775900702775,4914.751875410813,4866.547930523799,4835.241744862692,4806.240301900855,4778.09277674874,4741.919341177209,4708.459697917681,4680.414043651947,4651.076805287564,4622.580626925884,4589.937988573084,4557.578808178067,4527.962375102251,4493.316127704643,4463.248081168639,4436.329263821694,4404.530678702161,4376.433405537711,4346.038612939778,4313.669217086782,4281.956993484617,4251.899603535205,4219.951293048635,4186.1967021600285,4135.457972325422
Biopower - Dedicated/Moderate,5528.187826509868,5341.326933372557,5154.466040235246,5005.775900702775,4914.751875410813,4866.547930523799,4835.241744862692,4806.240301900855,4778.09277674874,4741.919341177209,4708.459697917681,4680.414043651947,4651.076805287564,4622.580626925884,4589.937988573084,4557.578808178067,4527.962375102251,4493.316127704643,4463.248081168639,4436.329263821694,4404.530678702161,4376.433405537711,4346.038612939778,4313.669217086782,4281.956993484617,4251.899603535205,4219.951293048635,4186.1967021600285,4135.457972325422
Biopower - Dedicated/Conservative,5528.187826509868,5341.326933372557,5154.466040235246,5005.775900702775,4914.751875410813,4866.547930523799,4835.241744862692,4806.240301900855,4778.09277674874,4741.919341177209,4708.459697917681,4680.414043651947,4651.076805287564,4622.580626925884,4589.937988573084,4557.578808178067,4527.962375102251,4493.316127704643,4463.248081168639,4436.329263821694,4404.530678702161,4376.433405537711,4346.038612939778,4313.669217086782,4281.956993484617,4251.899603535205,4219.951293048635,4186.1967021600285,4135.457972325422
6 changes: 3 additions & 3 deletions tests/data/Biopower/Market/20/df_lcoe.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tech_detail-scenario,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,2039,2040,2041,2042,2043,2044,2045,2046,2047,2048,2049,2050
Biopower - Dedicated/Advanced,196.70809305132286,176.94537683934004,174.30043627059362,171.90955555438734,170.43861004440842,169.65946274617437,169.1533770422553,168.68450145090392,168.22938685306144,167.64443641127076,167.1033028657282,166.64967761436432,166.1751112432227,165.71409989426422,165.18594518973873,164.6623102889513,164.182999206063,163.6222125348806,163.13546361130454,162.69964265420703,162.1847521302715,161.7297343149476,160.14879925726322,158.54988633552196,155.7512390634456,155.26947419414088,154.75740173131825,154.21637838080434,153.4031317535629
Biopower - Dedicated/Moderate,196.70809305132286,176.94537683934004,174.30043627059362,171.90955555438734,170.43861004440842,169.65946274617437,169.1533770422553,168.68450145090392,168.22938685306144,167.64443641127076,167.1033028657282,166.64967761436432,166.1751112432227,165.71409989426422,165.18594518973873,164.6623102889513,164.182999206063,163.6222125348806,163.13546361130454,162.69964265420703,162.1847521302715,161.7297343149476,160.14879925726322,158.54988633552196,155.7512390634456,155.26947419414088,154.75740173131825,154.21637838080434,153.4031317535629
Biopower - Dedicated/Conservative,196.70809305132286,176.94537683934004,174.30043627059362,171.90955555438734,170.43861004440842,169.65946274617437,169.1533770422553,168.68450145090392,168.22938685306144,167.64443641127076,167.1033028657282,166.64967761436432,166.1751112432227,165.71409989426422,165.18594518973873,164.6623102889513,164.182999206063,163.6222125348806,163.13546361130454,162.69964265420703,162.1847521302715,161.7297343149476,160.14879925726322,158.54988633552196,155.7512390634456,155.26947419414088,154.75740173131825,154.21637838080434,153.4031317535629
Biopower - Dedicated/Advanced,195.5297923884716,175.55933587455655,172.9514235835736,170.59363475501513,169.14305712240252,168.37470576400844,167.87563521022776,167.41326097142468,166.96445878400075,166.38762431602098,165.8540016070626,165.4066747113147,164.9386995581252,164.48409325972094,163.96327904738496,163.4469246000562,162.97428017921308,162.42129646142416,161.94132303555938,161.51157085593098,161.00385286648526,160.55517604209982,160.0697499395909,159.55271706528902,159.0461086452038,158.5658688649116,158.05534336106817,157.51586969700983,156.7047843225006
Biopower - Dedicated/Moderate,195.5297923884716,175.55933587455655,172.9514235835736,170.59363475501513,169.14305712240252,168.37470576400844,167.87563521022776,167.41326097142468,166.96445878400075,166.38762431602098,165.8540016070626,165.4066747113147,164.9386995581252,164.48409325972094,163.96327904738496,163.4469246000562,162.97428017921308,162.42129646142416,161.94132303555938,161.51157085593098,161.00385286648526,160.55517604209982,160.0697499395909,159.55271706528902,159.0461086452038,158.5658688649116,158.05534336106817,157.51586969700983,156.7047843225006
Biopower - Dedicated/Conservative,195.5297923884716,175.55933587455655,172.9514235835736,170.59363475501513,169.14305712240252,168.37470576400844,167.87563521022776,167.41326097142468,166.96445878400075,166.38762431602098,165.8540016070626,165.4066747113147,164.9386995581252,164.48409325972094,163.96327904738496,163.4469246000562,162.97428017921308,162.42129646142416,161.94132303555938,161.51157085593098,161.00385286648526,160.55517604209982,160.0697499395909,159.55271706528902,159.0461086452038,158.5658688649116,158.05534336106817,157.51586969700983,156.7047843225006
Loading

0 comments on commit cdeb16a

Please sign in to comment.