Skip to content

Commit d40b4e9

Browse files
authored
Add IFS cloud ice water content dataset (#31)
1 parent 7703af6 commit d40b4e9

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

src/climatebenchpress/data_loader/datasets/all.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .cmip6.all import *
55
from .era5 import *
66
from .esa_biomass_cci import *
7+
from .ifs_cloud_ice_water_content import *
78
from .ifs_humidity import *
89
from .ifs_uncompressed import *
910
from .nextgems import *
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
__all__ = ["IFSCloudIceWaterContentDataset"]
2+
3+
import argparse
4+
from pathlib import Path
5+
6+
import xarray as xr
7+
8+
from .. import (
9+
monitor,
10+
open_downloaded_canonicalized_dataset,
11+
open_downloaded_tiny_canonicalized_dataset,
12+
)
13+
from .abc import Dataset
14+
from .ifs_uncompressed import load_hplp_data, regrid_to_regular
15+
16+
17+
class IFSCloudIceWaterContentDataset(Dataset):
18+
"""Dataset for the cloud ice water content field of the uncompressed IFS data.
19+
20+
Contains data from the [hplp](https://apps.ecmwf.int/ifs-experiments/rd/hplp/)
21+
experiment from the Integrated Forecasting System (IFS) model. Crucially,
22+
this dataset contains uncompressed 64-bit floating point data.
23+
"""
24+
25+
name = "ifs-cloud-ice-water-content"
26+
27+
@staticmethod
28+
def download(download_path: Path, progress: bool = True):
29+
donefile = download_path / "download.done"
30+
if donefile.exists():
31+
return
32+
33+
ds = load_hplp_data(leveltype="ml", gridtype="reduced_gg", step=0)
34+
ds = ds[["ciwc"]]
35+
ds_regridded = regrid_to_regular(
36+
ds,
37+
in_grid={"grid": "O400"},
38+
out_grid={"grid": [0.25, 0.25]},
39+
)
40+
downloadfile = download_path / "ifs_cloud_ice_water_content.zarr"
41+
with monitor.progress_bar(progress):
42+
ds_regridded.to_zarr(downloadfile, mode="w", compute=False).compute()
43+
44+
@staticmethod
45+
def open(download_path: Path) -> xr.Dataset:
46+
ds = xr.open_zarr(
47+
download_path / "ifs_cloud_ice_water_content.zarr"
48+
).drop_encoding()
49+
num_levels = ds["level"].size
50+
ds = ds.isel(time=slice(0, 1)).chunk(
51+
{
52+
"latitude": -1,
53+
"longitude": -1,
54+
"time": -1,
55+
"level": (num_levels // 2) + 1,
56+
}
57+
)
58+
59+
# Needed to make the dataset CF-compliant.
60+
ds.longitude.attrs["axis"] = "X"
61+
ds.latitude.attrs["axis"] = "Y"
62+
ds.level.attrs["axis"] = "Z"
63+
ds.time.attrs["standard_name"] = "time"
64+
return ds
65+
66+
67+
if __name__ == "__main__":
68+
parser = argparse.ArgumentParser()
69+
parser.add_argument("--basepath", type=Path, default=Path())
70+
args = parser.parse_args()
71+
72+
ds = open_downloaded_canonicalized_dataset(
73+
IFSCloudIceWaterContentDataset, basepath=args.basepath
74+
)
75+
open_downloaded_tiny_canonicalized_dataset(
76+
IFSCloudIceWaterContentDataset, basepath=args.basepath
77+
)
78+
79+
for v, da in ds.items():
80+
print(f"- {v}: {da.dims}")

0 commit comments

Comments
 (0)