Skip to content

Commit 880ff85

Browse files
committed
add vsl to the variables that are condensed to segment in collapse_econ_inputs_to_seg
1 parent f68f821 commit 880ff85

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

pyCIAM/utils.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def spherical_nearest_neighbor(df1, df2, x1="lon", y1="lat", x2="lon", y2="lat")
116116
return pd.Series(df2.index[ixs[:, 0]], index=df1.index)
117117

118118

119-
def add_attrs_to_result(ds, seg_var):
119+
def add_attrs_to_result(ds, seg_var, mc_dim=None):
120120
attr_dict = {
121121
"case": {
122122
"long_name": "Adaptation Strategy",
@@ -180,7 +180,18 @@ def add_attrs_to_result(ds, seg_var):
180180
"long_name": "Shared Socioeconomic Pathway",
181181
"description": "Socioeconomic growth model used",
182182
},
183+
"refA": {
184+
"long_name": "Initial adaptation height",
185+
"description": (
186+
"Initial retreat height assumed in model. Determined by choosing "
187+
"optimal adaptation pathway under a 'no-climate-change' scenario and "
188+
"selecting the initial height. Retreat is assumed regardless of "
189+
"whether optimal path is retreat or protect."
190+
),
191+
},
183192
}
193+
if mc_dim is not None:
194+
attr_dict[mc_dim] = {"long_name": "Monte carlo sample index"}
184195
extra_vars = [
185196
v
186197
for v in ds.variables
@@ -205,7 +216,7 @@ def collapse_econ_inputs_to_seg(
205216
seg_var_subset=None,
206217
output_chunksize=100,
207218
seg_var="seg_adm",
208-
storage_options={},
219+
storage_options=None,
209220
):
210221
sliiders = subset_econ_inputs(
211222
xr.open_zarr(
@@ -265,8 +276,10 @@ def weighted_avg(varname, wts_in):
265276
("pc", sliiders.length),
266277
("ypcc", sliiders[pop_var].sum("elev")),
267278
("wetlandservice", sliiders.wetland.sum("elev")),
279+
("vsl", sliiders[pop_var].sum("elev")),
268280
]:
269-
weighted_avg(v, w)
281+
if v in sliiders.data_vars:
282+
weighted_avg(v, w)
270283

271284
out["rho"] = out.ypcc / (out.ypcc + usa_ypcc_ref.sel(year=2000, drop=True))
272285

0 commit comments

Comments
 (0)