Skip to content

Commit 040105d

Browse files
committed
update calculate_climatology.py to compute and save std of climatology alongside mean
1 parent 302765f commit 040105d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

experiments/calculate_climatology.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from pathlib import Path
33

4+
import dask
45
import xarray as xr
56
from dask.distributed import Client
67

@@ -15,6 +16,7 @@
1516
base_path = Path("data")
1617
era5_slice_path = base_path / "era5_slice_2010-01-01_2022-12-31.zarr"
1718
climatology_path = base_path / f"climatology_{start_year}-{end_year}.zarr"
19+
climatology_std_path = base_path / f"climatology_std_{start_year}-{end_year}.zarr"
1820

1921
client = Client(processes=False, local_directory=dask_spill_folder)
2022
logging.info("Dask dashboard: %s", client.dashboard_link)
@@ -23,7 +25,7 @@
2325
X = X.sel(time=slice(str(start_year), str(end_year)))
2426

2527
logging.info("Calculating climatology...")
26-
climatology = compute_climatology(X)
28+
climatology, climatology_std = compute_climatology(X, probabilistic=True)
2729
logging.info("Done.")
2830

2931
logging.info("Rechunking...")
@@ -40,11 +42,20 @@
4042

4143
logging.info("Saving to disk...")
4244
climatology_path.parent.mkdir(exist_ok=True)
43-
climatology.to_zarr(
45+
delayed_mean = climatology.to_zarr(
4446
climatology_path,
4547
zarr_format=2,
4648
mode="w",
49+
compute=False,
4750
)
51+
delayed_std = climatology_std.to_zarr(
52+
climatology_std_path,
53+
zarr_format=2,
54+
mode="w",
55+
compute=False,
56+
)
57+
dask.compute(delayed_mean, delayed_std)
58+
4859
logging.info("Done.")
4960

5061
client.close()

0 commit comments

Comments
 (0)