MIR: regridding octahedral GRIB fieldlist

This example shows how to interpolate GRIB data defined on an octahedral reduced Gaussian grid using the mir backend. We will also see how to inspect and plot the resulting data and how to convert it to xarray.

To make this notebook work earthkit-data and earthkit-plots have to be installed. The data will be represented as an earthkit-data GRIB FieldList.

Regridding

We perform the regridding with the regrid() method.

[1]:
from earthkit.regrid import regrid
import earthkit.data as ekd

# Get octahedral reduced Gaussian GRIB data containing two fields.
ds = ekd.from_source("sample", "O32_t2.grib2")

# the target grid is a global 5x5 degree regular latitude-longitude grid
grid = {"grid": [5,5]}

# perform interpolation for each field and add results
# to a new fieldlist stored in memory
r = regrid(ds, grid=grid, interpolation="linear")
Cache file /tmp/cache/mir/weights/17/linear/1/R32-98df937a38e9495da1d994b0eeb43e8b-87.8638:0:-87.8638:357.5/LL-5x5-90:0:-90:355-f23fea85e9a43f8f5d45557c5b6a2f8b.mat does not exist
Creating cache file /tmp/cache/mir/weights/17/linear/1/R32-98df937a38e9495da1d994b0eeb43e8b-87.8638:0:-87.8638:357.5/LL-5x5-90:0:-90:355-f23fea85e9a43f8f5d45557c5b6a2f8b.mat
CacheManager creating file /tmp/cache/mir/weights/17/linear/1/R32-98df937a38e9495da1d994b0eeb43e8b-87.8638:0:-87.8638:357.5/LL-5x5-90:0:-90:355-f23fea85e9a43f8f5d45557c5b6a2f8b.mat

Plotting the results

We use earthkit-plots to visualise the results.

[2]:
import earthkit.plots as ekp

ekp.quickplot(r).show()
../_images/examples_mir_octahedral_fieldlist_7_0.png

Converting the results to xarray

[3]:
r.to_xarray()
[3]:
<xarray.Dataset> Size: 44kB
Dimensions:    (step: 2, latitude: 37, longitude: 72)
Coordinates:
  * step       (step) timedelta64[ns] 16B 00:00:00 12:00:00
  * latitude   (latitude) float64 296B 90.0 85.0 80.0 75.0 ... -80.0 -85.0 -90.0
  * longitude  (longitude) float64 576B 0.0 5.0 10.0 15.0 ... 345.0 350.0 355.0
Data variables:
    2t         (step, latitude, longitude) float64 43kB ...
Attributes:
    param:        2t
    paramId:      167
    class:        od
    stream:       oper
    levtype:      sfc
    type:         fc
    expver:       0001
    date:         20240323
    time:         1200
    domain:       g
    Conventions:  CF-1.8
    institution:  ECMWF

Writing the results to disk

Write the resulting fieldlist to disk:

[4]:
out_file = "_res_O32_to_5x5.grib"
r.to_target("file", out_file)
[ ]: