Using UK Met Office PP files
This example uses a small PP file containing global temperature data.
We can read this data as a file source using the Iris library under the hood.
Please note, PP file support requires the scitools-iris and ncdata packages to be installed.
[1]:
import earthkit.data as ekd
# we ensure the example file is available.
ekd.download_example_file("air_temp.pp")
ds = ekd.from_source("file", "air_temp.pp")
/Users/cgr/venv/dev/lib/python3.13/site-packages/array_api_compat/torch/_info.py:361: UserWarning: 'mkldnn' is no longer used as device type. So torch.device('mkldnn') will be deprecated and removed in the future. Please use other valid device types instead. (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/c10/core/Device.cpp:42.)
a = torch.empty((0,), device=torch.device(device_name, index=i))
/Users/cgr/venv/dev/lib/python3.13/site-packages/iris/fileformats/netcdf/saver.py:2857: IrisDeprecation: Saving to netcdf with legacy-style attribute handling for backwards compatibility.
This mode is deprecated since Iris 3.8, and will eventually be removed.
Please consider enabling the new split-attributes handling mode, by setting 'iris.FUTURE.save_split_attrs = True'.
warn_deprecated(message)
/Users/cgr/venv/dev/lib/python3.13/site-packages/ncdata/xarray.py:165: FutureWarning: In a future version, xarray will not decode the variable 'forecast_period' into a timedelta64 dtype based on the presence of a timedelta-like 'units' attribute by default. Instead it will rely on the presence of a timedelta64 'dtype' attribute, which is now xarray's default way of encoding timedelta64 values.
To continue decoding into a timedelta64 dtype, either set `decode_timedelta=True` when opening this dataset, or add the attribute `dtype='timedelta64[ns]'` to this variable on disk.
To opt-in to future behavior, set `decode_timedelta=False`.
ds = store_entrypoint.open_dataset(self, **xr_load_kwargs)
The resulting object is an Xarray fieldList.
[2]:
ds.ls()
[2]:
| variable | level | valid_datetime | units | |
|---|---|---|---|---|
| 0 | air_temperature | None | 1998-12-01T00:00:00 | K |
[3]:
ds[0].shape
[3]:
(73, 96)
[4]:
ds[0].values[:5]
[4]:
array([254.644, 254.644, 254.644, 254.644, 254.644], dtype=float32)
[5]:
ds[0].to_latlon()
[5]:
{'lat': array([[ 89.999985, 89.999985, 89.999985, ..., 89.999985, 89.999985,
89.999985],
[ 87.499985, 87.499985, 87.499985, ..., 87.499985, 87.499985,
87.499985],
[ 84.999985, 84.999985, 84.999985, ..., 84.999985, 84.999985,
84.999985],
...,
[-84.999954, -84.999954, -84.999954, ..., -84.999954, -84.999954,
-84.999954],
[-87.499954, -87.499954, -87.499954, ..., -87.499954, -87.499954,
-87.499954],
[-89.999954, -89.999954, -89.999954, ..., -89.999954, -89.999954,
-89.999954]], shape=(73, 96), dtype=float32),
'lon': array([[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,
356.2499 ],
[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,
356.2499 ],
[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,
356.2499 ],
...,
[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,
356.2499 ],
[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,
356.2499 ],
[ 0. , 3.749999, 7.499998, ..., 348.7499 , 352.4999 ,
356.2499 ]], shape=(73, 96), dtype=float32)}
[ ]: