MIR: regridding numpy arrays

This example shows how to interpolate numpy arrays using the mir backend.

[1]:
from earthkit.regrid.array import regrid
import numpy as np

First, we generate random data matching the size of an O32 octahedral reduced Gaussian grid.

[2]:
values = np.random.random(5248)

Next, interpolate the array onto a 1x1 degree global regular latitude-longitude grid using regrid(). The input and output grids are defined by a gridspec. Both the input and the output values are numpy arrays.

[3]:
res, res_grid = regrid(values, in_grid={"grid": "O32"}, out_grid={"grid": [1,1]})
res.shape, res_grid
[3]:
((181, 360),
 {'east': 359, 'grid': [1, 1], 'north': 90, 'south': -90, 'west': 0})

regrid() returns a tuple with the regridded array and the resulting gridspec. This latter might be different than the one specified in out_grid because MIR can perform normalisation and other adjustments on it.

[ ]: