MIR: regridding HEALPix GRIB fieldlist

This example shows how to interpolate GRIB data defined on a HEALPix nested 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 a :ref:~earthkit.data.core.fieldlist.FieldList`.

Regridding

We perform the regridding with the regrid() method.

[1]:
import earthkit.data as ekd

import earthkit.geo as ekg

# Get HEALPix nested GRIB data containing two fields.
ds = ekd.from_source("sample", "H8_nested_t2.grib2").to_fieldlist()

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

# perform interpolation for each field and add results
# to a new fieldlist stored in memory
r = ekg.regrid(ds, out_grid=out_grid, interpolation="linear")

Plotting the results

[2]:
import earthkit.plots as ekp

ekp.quickplot(r)
[2]:
<earthkit.plots.components.figures.Figure at 0x12896f4d0>
../../_images/how-tos_mir_mir_healpix_fieldlist_6_1.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:
    Conventions:  CF-1.8
    institution:  ECMWF

Writing the results to disk

Write the resulting fieldlist to disk:

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