Using UK Met Office PP files

We fetch the input data as a sample source.

[1]:
import earthkit.data as ekd

d = ekd.from_source("sample", "hadslp2.pp")
d
[1]:
PP file

path/var/folders/93/w0p869rx17q98wxk83gn9ys40000gn/T/earthkit-data-cgr/url-183fd439041d5a7ad2ba82b0bb1d766e42513b8d7fdfbfa3ddb18e5071abeaa4.pp
size19.4 MiB
typesxarray, fieldlist

We can convert the data to an Xarray dataset. It is doen by using the Iris <https://scitools-iris.readthedocs.io/en/latest/>_ library under the hood. Please note, PP file support requires the scitools-iris and ncdata packages to be installed.

[2]:
d.to_xarray()
/Users/cgr/venv/dev/lib/python3.13/site-packages/iris/fileformats/netcdf/saver.py:2877: 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)
[2]:
<xarray.Dataset> Size: 20MB
Dimensions:                     (time: 1860, grid_latitude: 37,
                                 grid_longitude: 72)
Coordinates:
    time                        (time) datetime64[ns] 15kB dask.array<chunksize=(1860,), meta=np.ndarray>
    grid_latitude               (grid_latitude) float32 148B dask.array<chunksize=(37,), meta=np.ndarray>
    grid_longitude              (grid_longitude) float32 288B dask.array<chunksize=(72,), meta=np.ndarray>
Data variables:
    unknown                     (time, grid_latitude, grid_longitude) float32 20MB dask.array<chunksize=(1, 37, 72), meta=np.ndarray>
    rotated_latitude_longitude  int32 4B dask.array<chunksize=(), meta=numpy.ma.MaskedArray>
Attributes:
    Conventions:  CF-1.7

We can also load PP data into a fieldlist.

[3]:
fl = d.to_fieldlist()
/Users/cgr/venv/dev/lib/python3.13/site-packages/iris/fileformats/netcdf/saver.py:2877: 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)
[4]:
fl.ls()
[4]:
parameter.variable time.valid_datetime time.base_datetime time.step vertical.level vertical.level_type ensemble.member geography.grid_type
0 unknown 1850-01-01 1850-01-01 0 days None unknown 0 None
1 unknown 1850-02-01 1850-02-01 0 days None unknown 0 None
2 unknown 1850-03-01 1850-03-01 0 days None unknown 0 None
3 unknown 1850-04-01 1850-04-01 0 days None unknown 0 None
4 unknown 1850-05-01 1850-05-01 0 days None unknown 0 None
... ... ... ... ... ... ... ... ...
1855 unknown 2004-08-01 2004-08-01 0 days None unknown 0 None
1856 unknown 2004-09-01 2004-09-01 0 days None unknown 0 None
1857 unknown 2004-10-01 2004-10-01 0 days None unknown 0 None
1858 unknown 2004-11-01 2004-11-01 0 days None unknown 0 None
1859 unknown 2004-12-01 2004-12-01 0 days None unknown 0 None

1860 rows × 8 columns

[5]:
fl[0].shape
[5]:
(37, 72)
[6]:
fl[0].values[:5]
[6]:
array([1028.6418, 1028.6418, 1028.6418, 1028.6418, 1028.6418],
      dtype=float32)
[7]:
fl[0].geography.latlons()
[7]:
(array([[ 90.,  90.,  90., ...,  90.,  90.,  90.],
        [ 85.,  85.,  85., ...,  85.,  85.,  85.],
        [ 80.,  80.,  80., ...,  80.,  80.,  80.],
        ...,
        [-80., -80., -80., ..., -80., -80., -80.],
        [-85., -85., -85., ..., -85., -85., -85.],
        [-90., -90., -90., ..., -90., -90., -90.]],
       shape=(37, 72), dtype=float32),
 array([[-180., -175., -170., ...,  165.,  170.,  175.],
        [-180., -175., -170., ...,  165.,  170.,  175.],
        [-180., -175., -170., ...,  165.,  170.,  175.],
        ...,
        [-180., -175., -170., ...,  165.,  170.,  175.],
        [-180., -175., -170., ...,  165.,  170.,  175.],
        [-180., -175., -170., ...,  165.,  170.,  175.]],
       shape=(37, 72), dtype=float32))
[ ]: