1- import os , gc , time
1+ from dscim .menu .simple_storage import Climate , EconVars
2+ import dscim .menu .baseline
3+ import dscim .menu .risk_aversion
4+ import dscim .menu .equity
5+
6+ import os , gc , time , yaml
27
38USER = os .getenv ("USER" )
49import numpy as np
1015from dscim import ProWaiter
1116from itertools import product
1217
18+ MENU_OPTIONS = {
19+ "adding_up" : dscim .menu .baseline .Baseline ,
20+ "risk_aversion" : dscim .menu .risk_aversion .RiskAversionRecipe ,
21+ "equity" : dscim .menu .equity .EquityRecipe ,
22+ }
23+
1324
14- def run_AR6_epa_ssps (
25+ def run_ssps (
1526 sectors ,
1627 pulse_years ,
1728 menu_discs ,
1829 eta_rhos ,
1930 config ,
20- results_root ,
21- reduced_damages_library ,
22- ssp_damage_function_library ,
31+ USA ,
32+ AR ,
2333 global_cons = False ,
2434 factors = False ,
2535 marginal_damages = False ,
2636 order = "damage_function" ,
2737):
2838
29- w = ProWaiter (path_to_config = config )
39+ with open (config , "r" ) as stream :
40+ conf = yaml .safe_load (stream )
3041
3142 for sector , pulse_year , menu_disc , eta_rho in product (
3243 sectors , pulse_years , menu_discs , eta_rhos .items ()
3344 ):
3445
35- menu_option = menu_disc [0 ]
36- discount_type = menu_disc [1 ]
37-
38- save_path = f"{ results_root } /{ sector } /{ pulse_year } /"
39-
40- kwargs = {
46+ menu_option , discount_type = menu_disc
47+ save_path = f"{ conf ['paths' ][f'AR{ AR } _ssp_results' ]} /{ sector } /{ pulse_year } /"
48+
49+ if USA == True :
50+ econ = EconVars (path_econ = conf ["econdata" ]["USA_ssp" ])
51+ else :
52+ econ = EconVars (path_econ = conf ["econdata" ]["global_ssp" ])
53+
54+ add_kwargs = {
55+ "econ_vars" : econ ,
56+ "climate_vars" : Climate (
57+ ** conf [f"AR{ AR } _ssp_climate" ], pulse_year = pulse_year
58+ ),
59+ "formula" : conf ["sectors" ][sector if USA == False else sector [:- 4 ]][
60+ "formula"
61+ ],
4162 "discounting_type" : discount_type ,
4263 "sector" : sector ,
43- "ce_path" : f"{ reduced_damages_library } /{ sector } /" ,
64+ "ce_path" : f"{ conf [ 'paths' ][ ' reduced_damages_library' ] } /{ sector } /" ,
4465 "save_path" : save_path ,
45- "pulse_year" : pulse_year ,
4666 "eta" : eta_rho [0 ],
4767 "rho" : eta_rho [1 ],
4868 }
4969
70+ kwargs = conf ["global_parameters" ].copy ()
71+ for k , v in add_kwargs .items ():
72+ assert (
73+ k not in kwargs .keys ()
74+ ), f"{ k } already set in config. Please check `global_parameters`."
75+ kwargs .update ({k : v })
76+
5077 if "CAMEL" in sector :
5178 kwargs .update (
5279 {
53- "damage_function_path" : f"{ ssp_damage_function_library } /{ sector } /2020/" ,
80+ "damage_function_path" : f"{ conf [ 'paths' ][ ' ssp_damage_function_library' ] } /{ sector } /2020/" ,
5481 "save_files" : [
5582 "damage_function_points" ,
5683 "marginal_damages" ,
@@ -61,7 +88,8 @@ def run_AR6_epa_ssps(
6188 }
6289 )
6390
64- menu_item = w .menu_factory (menu_key = menu_option , sector = sector , kwargs = kwargs )
91+ menu_item = MENU_OPTIONS [menu_option ](** kwargs )
92+ menu_item .order_plate (order )
6593
6694 if global_cons == True :
6795 menu_item .global_consumption_no_pulse .to_netcdf (
@@ -124,49 +152,66 @@ def run_AR6_epa_ssps(
124152 mode = "w" ,
125153 )
126154
127- menu_item .order_plate (order )
128-
129155
130- def run_epa_rff (
156+ def run_rff (
131157 sectors ,
132158 pulse_years ,
133159 menu_discs ,
134160 eta_rhos ,
135161 config ,
136- results_root ,
137- rff_damage_function_library ,
162+ USA ,
138163 global_cons = True ,
139164 factors = True ,
140165 marginal_damages = True ,
141166 order = "scc" ,
142167):
143168
144- w = ProWaiter (path_to_config = config )
169+ with open (config , "r" ) as stream :
170+ conf = yaml .safe_load (stream )
145171
146172 for sector , pulse_year , menu_disc , eta_rho in product (
147173 sectors , pulse_years , menu_discs , eta_rhos .items ()
148174 ):
149175
150- menu_option = menu_disc [ 0 ]
151- discount_type = menu_disc [ 1 ]
176+ menu_option , discount_type = menu_disc
177+ save_path = f" { conf [ 'paths' ][ 'rff_results' ] } / { sector } / { pulse_year } /"
152178
153- save_path = f"{ results_root } /{ sector } /{ pulse_year } /"
154- os .makedirs (save_path , exist_ok = True )
179+ if USA == True :
180+ econ = EconVars (
181+ path_econ = f"{ conf ['rffdata' ]['socioec_output' ]} /rff_USA_socioeconomics.nc4"
182+ )
183+ else :
184+ econ = EconVars (
185+ path_econ = f"{ conf ['rffdata' ]['socioec_output' ]} /rff_global_socioeconomics.nc4"
186+ )
155187
156- kwargs = {
188+ add_kwargs = {
189+ "econ_vars" : econ ,
190+ "climate_vars" : Climate (** conf ["rff_climate" ], pulse_year = pulse_year ),
191+ "formula" : conf ["sectors" ][sector if USA == False else sector [:- 4 ]][
192+ "formula"
193+ ],
157194 "discounting_type" : discount_type ,
158195 "sector" : sector ,
159- "damage_function_path " : f" { rff_damage_function_library } / { sector } /2020" ,
196+ "ce_path " : None ,
160197 "save_path" : save_path ,
198+ "eta" : eta_rho [0 ],
199+ "rho" : eta_rho [1 ],
200+ "damage_function_path" : f"{ conf ['paths' ]['rff_damage_function_library' ]} /{ sector } /2020" ,
161201 "save_files" : ["uncollapsed_sccs" ],
162- "pulse_year" : pulse_year ,
163202 "ecs_mask_path" : None ,
164203 "ecs_mask_name" : None ,
165- "eta" : eta_rho [0 ],
166- "rho" : eta_rho [1 ],
167204 }
168205
169- menu_item = w .menu_factory (menu_key = menu_option , sector = sector , kwargs = kwargs )
206+ kwargs = conf ["global_parameters" ].copy ()
207+ for k , v in add_kwargs .items ():
208+ assert (
209+ k not in kwargs .keys ()
210+ ), f"{ k } already set in config. Please check `global_parameters`."
211+ kwargs .update ({k : v })
212+
213+ menu_item = MENU_OPTIONS [menu_option ](** kwargs )
214+ menu_item .order_plate (order )
170215
171216 if global_cons == True :
172217 menu_item .global_consumption_no_pulse .to_netcdf (
@@ -228,6 +273,3 @@ def run_epa_rff(
228273 consolidated = True ,
229274 mode = "w" ,
230275 )
231- print ("done saving discount factor" )
232-
233- menu_item .order_plate (order )
0 commit comments