@@ -14,16 +14,28 @@ def clean_simulation(
1414 draw ,
1515 root ,
1616):
17+ """
18+ Clean the weights csvs generated by the RFF emulator.
19+ This produces a file of the weights.
20+
21+ Parameters
22+ ----------
23+ draw : int, weight draw
24+ root : str, root directory
25+ """
26+
1727 ds = pd .read_csv (
1828 f"{ root } /emulate-fivebean-{ draw } .csv" ,
1929 skiprows = 9 ,
2030 )
2131
32+ # cleaning columns
2233 for i , name in enumerate (["model" , "ssp" ]):
2334 ds [name ] = ds ["name" ].str .split ("/" , expand = True )[i ]
2435 for i , name in enumerate (["year" , "model" ]):
2536 ds [name ] = ds ["model" ].str .split (":" , expand = True )[i ]
2637
38+ # dropping error rows and keeping only weights rows
2739 ds = ds .loc [ds .param != "error" ]
2840
2941 ds ["model" ] = ds .model .replace ({"low" : "IIASA GDP" , "high" : "OECD Env-Growth" })
@@ -41,15 +53,26 @@ def clean_error(
4153 draw ,
4254 root ,
4355):
56+ """
57+ Clean the weights csvs generated by the RFF emulator.
58+ This produces a file of the errors (for diagnostics).
59+
60+ Parameters
61+ ----------
62+ draw : int, weight draw
63+ root : str, root directory
64+ """
4465
4566 ds = pd .read_csv (
4667 f"{ root } /emulate-fivebean-{ draw } .csv" ,
4768 skiprows = 9 ,
4869 )
4970
71+ # cleaning columns
5072 for i , name in enumerate (["iso" , "year" ]):
5173 ds [name ] = ds ["name" ].str .split (":" , expand = True )[i ]
5274
75+ # dropping weights rows and keeping only error rows
5376 ds = ds .loc [ds .param == "error" ]
5477
5578 ds ["rff_sp" ] = draw
@@ -76,6 +99,9 @@ def weight_df(
7699 pulse_year ,
77100 fractional = False ,
78101):
102+ """Weight, fractionalize, and combine SSP damage functions,
103+ then multiply by RFF GDP to return RFF damage functions.
104+ """
79105
80106 # get damage function as share of global GDP
81107 df = (
@@ -121,6 +147,7 @@ def rff_damage_functions(
121147 weights_path ,
122148 pulse_year ,
123149):
150+ """Wrapper function for `weight_df()`."""
124151
125152 # ssp GDP for fractionalizing damage functions
126153 ssp_gdp = xr .open_zarr (ssp_gdp , consolidated = True ).sum ("region" ).gdp
@@ -169,6 +196,7 @@ def prep_rff_socioeconomics(
169196 out_path ,
170197 USA ,
171198):
199+ """Generate the global or domestic RFF socioeconomics file for use with the `dscim` MainRecipe."""
172200
173201 # Load Fed GDP deflator
174202 fed_gdpdef = pd .read_csv (inflation_path ).set_index ("year" )["gdpdef" ].to_dict ()
@@ -212,6 +240,9 @@ def aggregate_rff_weights(
212240 root ,
213241 output ,
214242):
243+ """Wrapper function for `clean_simulation()` and `clean_error()`.
244+ Generates an aggregated file of RFF emulator weights.
245+ """
215246
216247 # clean simulation files
217248 datasets = p_map (partial (clean_simulation , root = root ), range (1 , 10001 , 1 ))
0 commit comments