diff --git a/cases.csv b/cases.csv index 71c731b2..3fc2e2bd 100644 --- a/cases.csv +++ b/cases.csv @@ -61,7 +61,6 @@ inflation_suffix,File suffix for historical inflation schedule,default,default, ivt_suffix,File suffix for ivt csv file,default; small; step,default, reg_cap_cost_diff_suffix,File suffix for regional capital cost differences,default,default, techs_suffix,File suffix for master list of technologies,default; subsetForTesting,default, -dollar_year,DO NOT CHANGE FROM 2004 UNTIL ALL FINANCIAL INPUTS HAVE DOLLAR YEAR ADJUSTMENT - Real dollar year for model to calculate and report,2004,2004, sys_eval_years,Number of years that the model evaluates investments on,int,30, numhintage,"number of hintage bins. Enter 'unit' for unit level bins. Enter 'group' to group by unique technology, region, and heatrate combinations",int,6, numbins_windons,Number of interconnection supply curve bins for onshore wind; options are 5 and 1300 (for individual sites lite),int,10, diff --git a/docs/sources.csv b/docs/sources.csv index 456c17fe..4b309b7f 100644 --- a/docs/sources.csv +++ b/docs/sources.csv @@ -225,7 +225,6 @@ RelativeFilePath,RelativeFolderPath,FileName_new,FileExtension,Description_new,I /inputs/financials/construction_schedules_default.csv,/inputs/financials,construction_schedules_default,.csv,,,,,, /inputs/financials/construction_times_default.csv,/inputs/financials,construction_times_default,.csv,,,,,, /inputs/financials/currency_incentives.csv,/inputs/financials,currency_incentives,.csv,,,,,, -/inputs/financials/deflator.csv,/inputs/financials,deflator,.csv,Dollar year deflator to convert values to 2004$,,,,, /inputs/financials/depreciation_schedules_default.csv,/inputs/financials,depreciation_schedules_default,.csv,,,,,, /inputs/financials/energy_communities.csv,/inputs/financials,energy_communities,.csv,,,,,, /inputs/financials/financials_hydrogen.csv,/inputs/financials,financials_hydrogen,.csv,,,,,, diff --git a/inputs/financials/deflator.csv b/inputs/financials/deflator.csv deleted file mode 100644 index ecb55187..00000000 --- a/inputs/financials/deflator.csv +++ /dev/null @@ -1,23 +0,0 @@ -*Dollar.Year,Deflator -2004,1 -2005,0.967211529 -2006,0.936857351 -2007,0.910896792 -2008,0.877211857 -2009,0.880345888 -2010,0.866482174 -2011,0.839614509 -2012,0.822345259 -2013,0.810192373 -2014,0.797433438 -2015,0.796636802 -2016,0.786413427 -2017,0.77023842 -2018,0.752185957 -2019,0.738886009 -2020,0.730124515 -2021,0.697349107 -2022,0.645693617 -2023,0.620262841 -2024,0.602782158 -2025,0.587506977 diff --git a/inputs/scalars.csv b/inputs/scalars.csv index bf68a35a..97bd60a6 100644 --- a/inputs/scalars.csv +++ b/inputs/scalars.csv @@ -24,6 +24,7 @@ csp_sm_3,1.3,"--fraction-- solar multiple for csp3" csp_sm_4,1.0,"--fraction-- solar multiple for csp4" csp_sm_baseline,2.4,"--fraction-- baseline solar multiple to normalize other CSP solar multiples by" distloss,0.05,"--fraction-- distribution loss rate from bus to final consumption. A generic estimate of distribution losses taken many years ago from AEO 2006" +dollar_year,2004,"--year-- real dollar year for model to calculate and report - DO NOT CHANGE FROM 2004 UNTIL ALL FINANCIAL INPUTS HAVE DOLLAR YEAR ADJUSTMENT --" euros_dollar,1.124,"--USD/Euro-- dollars per euro exchange rate from treasury department (https://fiscal.treasury.gov/files/reports-statements/treasury-reporting-rates-exchange/ratesofexchangeasofdecember312019.pdf)" forced_outage_rate_h2_smr,0.1,"--fraction-- forced outage rate of steam methane reforming" gas_elasticity,0.76,"--fraction-- gas supply curve elasticity. long run price elasticity as estimated by: https://www.diw.de/documents/publikationen/73/diw_01.c.441773.de/dp1372.pdf" diff --git a/postprocessing/bokehpivot/reeds2.py b/postprocessing/bokehpivot/reeds2.py index dcb86cfc..04bf866d 100644 --- a/postprocessing/bokehpivot/reeds2.py +++ b/postprocessing/bokehpivot/reeds2.py @@ -16,12 +16,14 @@ import core import copy from itertools import product +from math import prod ## Inherit the default present value year to use in plot definitions from defaults import DEFAULT_PV_YEAR rb_globs = {'output_subdir':'/outputs/', 'test_file':['cap.csv','outputs.h5'], 'report_subdir':'/reeds2'} this_dir_path = os.path.dirname(os.path.realpath(__file__)) -df_deflator = pd.read_csv(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'inputs/financials/deflator.csv')), index_col=0) +df_inflation = pd.read_csv(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'inputs/financials/inflation_default.csv')), index_col=0) +scalars = pd.read_csv(os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, 'inputs/scalars.csv'))) coststreams = ['eq_gasaccounting_regional','eq_gasaccounting_national','eq_bioused','eq_gasused','eq_objfn_inv','eq_objfn_op'] vf_valstreams = ['eq_supply_demand_balance','eq_reserve_margin','eq_opres_requirement','eq_rec_requirement','eq_curt_gen_balance','eq_curtailment','eq_storage_in_max','eq_storage_in_min'] # valuestreams = ['eq_supply_demand_balance','eq_reserve_margin','eq_opres_requirement','eq_rec_requirement','eq_national_gen','eq_annual_cap','eq_curt_gen_balance','eq_curtailment','eq_storage_in_max','eq_storage_in_min','eq_emit_accounting','eq_mingen_lb','eq_mingen_ub','eq_rps_ofswind'] @@ -70,8 +72,12 @@ def apply_inflation(df, **kw): return df def inflate_series(ser_in): - return ser_in * 1/df_deflator.loc[int(core.GL['widgets']['var_dollar_year'].value), 'Deflator'] - + inflation_dict = dict(zip(df_inflation.index, df_inflation['inflation_rate'])) + REEDS_DOLLAR_YEAR=scalars.loc[scalars['scalar']=='dollar_year','value'].values[0] + deflator_multiplier = prod( inflation_dict[y] + for y in range(int(REEDS_DOLLAR_YEAR) + 1, int(core.GL['widgets']['var_dollar_year'].value) + 1 )) + return ser_in * deflator_multiplier + def gather_cost_types(df): #Gather lists of capital and operation labels cost_cats_df = df['cost_cat'].unique().tolist() diff --git a/postprocessing/compare_cases.py b/postprocessing/compare_cases.py index 57e21efb..82399b65 100644 --- a/postprocessing/compare_cases.py +++ b/postprocessing/compare_cases.py @@ -138,9 +138,8 @@ discountrate_scghg = 0.02 assert discountrate_scghg in [0.015, 0.02, 0.025] central_health = {'cr':'ACS', 'model':'EASIUR'} -reeds_dollaryear = 2004 -output_dollaryear = DEFAULT_DOLLAR_YEAR startyear_notes = DEFAULT_PV_YEAR +dollar_year = int(reeds.io.get_scalars().dollar_year) colors_social = { 'CO2': plt.cm.tab20b(4), @@ -317,7 +316,7 @@ def plot_bars_abs_stacked( inflatable = reeds.io.get_inflatable(os.path.join( reeds_path,'inputs','financials','inflation_default.csv')) -inflator = inflatable[reeds_dollaryear, output_dollaryear] +inflator = inflatable[dollar_year, DEFAULT_DOLLAR_YEAR] scghg = pd.read_csv( os.path.join(reeds_path, 'postprocessing', 'plots', 'scghg_annual.csv'), @@ -331,7 +330,7 @@ def plot_bars_abs_stacked( }).set_index(['e','t']) scghg_central = ( scghg[f'2020_{discountrate_scghg*100:.1f}%'].unstack('e') - * inflatable[2020, output_dollaryear] + * inflatable[2020, DEFAULT_DOLLAR_YEAR] ) #%% Colors and mapping @@ -527,7 +526,7 @@ def plot_bars_abs_stacked( .xs(central_health['model'], level='model') .groupby('year').sum() ['damage_$'] - ### Inflate from reeds_dollaryear (2004) to bokeh output_dollaryear (2021) + ### Inflate from dollar_year (2004) to bokeh DEFAULT_DOLLAR_YEAR (2024) * inflator ### Convert to $B / 1e9 diff --git a/postprocessing/input_plots.py b/postprocessing/input_plots.py index db82273d..88b1bb22 100644 --- a/postprocessing/input_plots.py +++ b/postprocessing/input_plots.py @@ -799,6 +799,7 @@ def map_supplycurves( """ ### Get inputs sw = reeds.io.get_switches(case) + scalars = reeds.io.get_scalars(case) dfmap = reeds.io.get_dfmap(case=case) for key in dfmap: if dfmap[key].crs != crs: @@ -844,7 +845,7 @@ def map_supplycurves( ).to_crs(crs) if include_techneutral_adder: inflatable = reeds.io.get_inflatable() - costadder = float(sw.GSw_TransIntraCost) * inflatable[2004, dollaryear] + costadder = float(sw.GSw_TransIntraCost) * inflatable[int(scalars['dollar_year']), dollaryear] else: costadder = 0 ## Convert from point to polygons if desired (raster is 11.52 km but include a little extra) diff --git a/postprocessing/retail_rate_module/ferc_distadmin.py b/postprocessing/retail_rate_module/ferc_distadmin.py index 3ffbe161..a8c17e5e 100644 --- a/postprocessing/retail_rate_module/ferc_distadmin.py +++ b/postprocessing/retail_rate_module/ferc_distadmin.py @@ -10,6 +10,13 @@ import pandas as pd import numpy as np import os +import sys + +from pathlib import Path +sys.path.append(str(Path(__file__).parent.parent.parent)) +import reeds + +dollar_year = int(reeds.io.get_scalars().dollar_year) ################# @@ -172,7 +179,7 @@ def inflatifier(inyear, outyear=2019, inflation=inflation): inflatable = pd.Series(inflatable) return inflatable -def get_excluded_costs(excludecells=excludecells, inflationpath=None, dollar_year=2004): +def get_excluded_costs(excludecells=excludecells, inflationpath=None, dollar_year=dollar_year): """ Get subtracted cells so we can add them back in with special treatment. Returns monetary values in dollar_year dollars. diff --git a/postprocessing/retail_rate_module/mean_bias_error.py b/postprocessing/retail_rate_module/mean_bias_error.py index d51fdf49..cd674b13 100644 --- a/postprocessing/retail_rate_module/mean_bias_error.py +++ b/postprocessing/retail_rate_module/mean_bias_error.py @@ -12,9 +12,14 @@ import pandas as pd import os import io +import sys import argparse import retail_rate_calculations +from pathlib import Path +sys.path.append(str(Path(__file__).parent.parent.parent)) +import reeds + pd.options.display.max_columns = 200 pd.options.display.max_rows = 50 @@ -40,16 +45,16 @@ #%% Inputs ### validationyears = list(range(2010,2020)) -data_dollar_year = 2004 retailmodulepath = os.path.join(reeds_path,'postprocessing','retail_rate_module','') inputs_default_path = retailmodulepath+'inputs_default.csv' +dollar_year = int(reeds.io.get_scalars().dollar_year) inflation = pd.read_csv( os.path.join(reeds_path,'inputs','financials','inflation_default.csv'), index_col=['t']) inf_adjust = inflation.loc[ - data_dollar_year+1:out_dollar_year, + dollar_year+1:out_dollar_year, 'inflation_rate' ].cumprod()[out_dollar_year] diff --git a/postprocessing/retail_rate_module/retail_rate_calculations.py b/postprocessing/retail_rate_module/retail_rate_calculations.py index f29c6422..c6d243fa 100644 --- a/postprocessing/retail_rate_module/retail_rate_calculations.py +++ b/postprocessing/retail_rate_module/retail_rate_calculations.py @@ -13,6 +13,7 @@ ### Local imports import ferc_distadmin import calculate_historical_capex + sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) import reeds from reeds import plots @@ -371,6 +372,7 @@ def main(run_dir, inputpath='inputs.csv', write=True, verbose=0): modeled_years = load_rt['t'].drop_duplicates() non_modeled_years = list(set(np.arange(first_year,last_year,1)) - set(modeled_years)) years_reeds = np.arange(first_year, last_year+1) + reeds_dollar_year=reeds.io.get_scalars().dollar_year # Ingest inflation inflation = pd.read_csv( @@ -1018,7 +1020,7 @@ def main(run_dir, inputpath='inputs.csv', write=True, verbose=0): mdir, 'calc_historical_capex', 'existing_transmission_cost_bystate_USD2024.csv'), index_col='state', - ).squeeze(1).rename('init_trans_capex') * inflatable[2024, 2004] + ).squeeze(1).rename('init_trans_capex') * inflatable[2024, reeds_dollar_year] # This approach assumes the existing transmission capacity was built evently # over the trans_timeframe years prior to 2010 init_trans_capex = pd.concat( diff --git a/reeds/input_processing/calc_financial_inputs.py b/reeds/input_processing/calc_financial_inputs.py index f2611a52..e154c1af 100644 --- a/reeds/input_processing/calc_financial_inputs.py +++ b/reeds/input_processing/calc_financial_inputs.py @@ -64,7 +64,7 @@ def calc_financial_inputs(inputs_case): # Set up scen_settings object scen_settings = reeds.financials.scen_settings( - dollar_year=int(sw['dollar_year']), tech_groups=tech_groups, inputs_case=inputs_case, + dollar_year=int(scalars['dollar_year']), tech_groups=tech_groups, inputs_case=inputs_case, sw=sw) diff --git a/reeds/input_processing/copy_files.py b/reeds/input_processing/copy_files.py index 642d2ebc..71c3410e 100644 --- a/reeds/input_processing/copy_files.py +++ b/reeds/input_processing/copy_files.py @@ -148,7 +148,7 @@ def read_runfiles(reeds_path, inputs_case, sw, agglevel_variables): return runfiles, non_region_files, region_files -def get_source_deflator_map(reeds_path): +def get_source_deflator_map(reeds_path,inputs_case,write_out=True): """ Get the deflator for each input file """ @@ -157,9 +157,29 @@ def get_source_deflator_map(reeds_path): os.path.join(reeds_path,'docs','sources.csv'), usecols=["RelativeFilePath", "DollarYear"] ) - deflator = pd.read_csv( - os.path.join(reeds_path,'inputs','financials','deflator.csv'), - header=0, names=['Dollar.Year','Deflator'], index_col='Dollar.Year').squeeze(1) + + ### Deflator Calculation + # The deflator values are calculated relative to the reeds dollar year to most recent + # inputs dollar year by using inflatable. + # Define the base year and current year for the deflator calculation. + scalars = reeds.io.get_scalars(full=True) + reeds_dollar_year=int(scalars.loc['dollar_year', 'value']) + max_dollar_year = pd.to_numeric(sources_dollaryear['DollarYear'], errors='coerce').max() + + # Define the deflator + inflatable = reeds.io.get_inflatable() + deflator =( 1 / inflatable[reeds_dollar_year].loc[reeds_dollar_year:max_dollar_year]).reset_index() + deflator.columns = ['*Dollar.Year', 'Deflator'] + + # if get_source_deflator_map function is being called from mcs_sampler, + # we do not want to write out the deflator.csv file as it is only used for + # the copy_files function. + + if write_out: + deflator.to_csv(os.path.join(inputs_case, 'deflator.csv'), index=False) + + deflator.rename(columns={'*Dollar.Year': 'Dollar.Year'}, inplace=True) + # Create a mapping between inputs' relative filepaths and their deflation # multipliers based on the dollar years their monetary values are in sources_dollaryear = ( @@ -172,7 +192,7 @@ def get_source_deflator_map(reeds_path): .rename(columns={"DollarYear": "Dollar.Year"}) .merge(deflator,on="Dollar.Year",how="left") ) - + source_deflator_map = dict(zip(sources_dollaryear["RelativeFilePath"], sources_dollaryear["Deflator"])) return source_deflator_map @@ -1623,7 +1643,7 @@ def main(reeds_path, inputs_case): # (gswitches.csv is first written at runreeds.py) scalar_csv_to_txt(os.path.join(inputs_case,'gswitches.csv')) - source_deflator_map = get_source_deflator_map(reeds_path) + source_deflator_map = get_source_deflator_map(reeds_path,inputs_case) # Copy non-region files write_non_region_files(non_region_files, sw, inputs_case, regions_and_agglevel, source_deflator_map) diff --git a/reeds/input_processing/mcs_sampler.py b/reeds/input_processing/mcs_sampler.py index 605b2bfc..5d80276f 100644 --- a/reeds/input_processing/mcs_sampler.py +++ b/reeds/input_processing/mcs_sampler.py @@ -611,7 +611,7 @@ def get_dist_instructions(reeds_path: str, inputs_case: str) -> Tuple[pd.DataFra regions_and_agglevel = copy_files.get_regions_and_agglevel( reeds_path, inputs_case, save_regions_and_agglevel=False, overwrite=True) - source_deflator_map = copy_files.get_source_deflator_map(reeds_path) + source_deflator_map = copy_files.get_source_deflator_map(reeds_path,inputs_case,False) hierarchy_file = get_hierarchy_file(inputs_case, sw['GSw_RegionResolution']) diff --git a/reeds/input_processing/runfiles.csv b/reeds/input_processing/runfiles.csv index ac9f66ea..a56df954 100644 --- a/reeds/input_processing/runfiles.csv +++ b/reeds/input_processing/runfiles.csv @@ -56,7 +56,7 @@ csapr_ozone_season.csv,inputs/emission_constraints/csapr_ozone_season.csv,int(sw currency_incentives.csv,inputs/financials/currency_incentives.csv,1,ignore,ignore,,,,,0,,,,,, dac_elec.csv,inputs/consume/dac_elec_{dacscen}.csv,int(sw.GSw_DAC) != 0,ignore,ignore,,,,1,0,,,,,, dac_gas.csv,inputs/consume/dac_gas_{GSw_DAC_Gas_Case}.csv,int(sw.GSw_DAC) != 0,ignore,ignore,,,,1,0,,1,,,, -deflator.csv,inputs/financials/deflator.csv,1,ignore,ignore,,,,,0,,,,,, +deflator.csv,,1,ignore,ignore,,,,,0,,1,,,, degradation_annual.csv,inputs/degradation/degradation_annual_{degrade_suffix}.csv,1,ignore,ignore,,,,,0,,,,,, demonstration_plants.csv,inputs/capacity_exogenous/demonstration_plants.csv,int(sw.GSw_NuclearDemo) != 0,sum,ignore,r,"t,i,coolingwatertech,ctt,wst,notes",i,0,0,,,,,, depreciation_schedules.csv,inputs/financials/depreciation_schedules_{depreciation_schedules_suffix}.csv,1,ignore,ignore,,,,1,0,,,,,, diff --git a/reeds/input_processing/transmission.py b/reeds/input_processing/transmission.py index 88f32895..9489062d 100644 --- a/reeds/input_processing/transmission.py +++ b/reeds/input_processing/transmission.py @@ -32,11 +32,8 @@ decimals = 5 drop_canmex = True -dollar_year = 2004 weight = 'cost' -costcol = f'USD{dollar_year}perMW' - #%% Set up logger log = reeds.log.makelog( scriptname=__file__, @@ -46,6 +43,10 @@ #%% Inputs from switches sw = reeds.io.get_switches(inputs_case) +scalars = reeds.io.get_scalars(inputs_case) + +dollar_year = int(scalars['dollar_year']) +costcol = f'USD{dollar_year}perMW' ## networksource must end in a 4-digit year indicating the year represented by the network trans_init_year = int(sw.GSw_TransNetworkSource[-4:]) diff --git a/reeds/results.py b/reeds/results.py index a475cfe5..c2f5f35c 100644 --- a/reeds/results.py +++ b/reeds/results.py @@ -213,13 +213,13 @@ def calc_h2prod(case): return df -def inflate_series(dfin, to_dollar_year=DEFAULT_DOLLAR_YEAR): +def inflate_series(inputs_case,dfin, to_dollar_year=DEFAULT_DOLLAR_YEAR): """ Inflate a series of financial data to a specified dollar year. """ df_deflator = pd.read_csv( - os.path.join(reeds_path, 'inputs', 'financials', 'deflator.csv'), - index_col=0, + os.path.join(inputs_case, 'deflator.csv'), + index_col=0 ) return dfin * 1 / df_deflator.loc[to_dollar_year, 'Deflator'] @@ -342,7 +342,7 @@ def calc_systemcost( df = systemcost.copy() # Apply inflation - df['Value'] = inflate_series(df['Value']) + df['Value'] = inflate_series(inputs_case,df['Value']) df.rename(columns={'Value':'Cost (Bil $)'}, inplace=True) cost_cat_map, cap_type_ls, op_type_ls = gather_cost_types(df) @@ -388,7 +388,7 @@ def calc_systemcost( df_capex_hist=df_capex_hist.loc[:firstmodelyear-1,:] # Convert to output dollar year - df_capex_hist = pd.DataFrame(inflate_series(df_capex_hist)) + df_capex_hist = pd.DataFrame(inflate_series(inputs_case,df_capex_hist)) # Insert into full cost table df = df.join(df_capex_hist, on=['year','r'])