Skip to content

Commit 1fb6214

Browse files
refactor: add accumulated precip to dataset postprocessing
1 parent b8eab1b commit 1fb6214

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

scripts_for_plotting/src/load_ensemble_datasets.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@ def postprocess_cleo_dataset(ds, config, gbxs, precip_rolling_window, is_ensembl
159159
)
160160
ds = ds.assign(**{arr.name: arr})
161161

162+
arr = xr.DataArray(
163+
ds.surfprecip_rate.cumsum(dim="time") * config["OBSTSTEP"] / 3600,
164+
name="surfprecip_cumulative",
165+
dims=["ensemble", "time"] if is_ensemble else ["time"],
166+
attrs={
167+
"units": "mm",
168+
"long_name": "accumulated surface precipitation",
169+
},
170+
)
171+
ds = ds.assign(**{arr.name: arr})
172+
162173
arr = xr.DataArray(
163174
calcs.mean_rolling_window(ds.surfprecip_rate, precip_rolling_window),
164175
name="surfprecip_rolling",
@@ -497,6 +508,18 @@ def postprocess_pysdm_dataset(ds, precip_rolling_window, is_ensemble=True):
497508
},
498509
)
499510
ds = ds.assign(**{arr.name: arr})
511+
512+
delta_time = np.mean(ds.time.values[1:] - ds.time.values[:-1])
513+
arr = xr.DataArray(
514+
ds.surfprecip_rate.cumsum(dim="time") * delta_time / 3600,
515+
name="surfprecip_cumulative",
516+
dims=["ensemble", "time"] if is_ensemble else ["time"],
517+
attrs={
518+
"units": "mm",
519+
"long_name": "accumulated surface precipitation",
520+
},
521+
)
522+
ds = ds.assign(**{arr.name: arr})
500523
except AttributeError:
501524
print("no precipitation in dataset")
502525

0 commit comments

Comments
 (0)