interpolate

interpolate(values, in_grid=None, out_grid=None, matrix_source=None, method='linear')

Interpolate the values from the in_grid onto the out_grid.

Parameters:
  • values (ndarray, fieldlist) – the input data. It can be an ndarray or an earthkit-data GRIB fieldlist. ndarrays are assumed to be defined on the in_grid. The fieldlist support requires earthkit-data >= 0.6.0 and only works when the out_grid is a regular latitude-longitude grid.

  • in_grid (dict) – the gridspec describing the grid that values are defined on. When values is a fieldlist the input grid is automatically detected and in_grid cannot be specified.

  • out_grid (dict) – the gridspec describing the target grid that values will be interpolated onto

  • method (str) – the interpolation method. Possible values are linear and nearest-neighbour. For nearest-neighbour the following aliases are also supported: nn, nearest-neighbor.

  • matrix_source (str, None) – (experimental) the location of a user specified pre-generated matrix inventory. When it is None the default matrix inventory hosted on an ECMWF download server is used.

Returns:

The same type of data as values containing the interpolated values.

Return type:

ndarray, fieldlist

Raises:
  • ValueError – if a pre-generated interpolation matrix is not available

  • ValueError – if in_grid is specified for a fieldlist input

The interpolation only works when a pre-generated interpolation matrix is available for the given in_grid, out_grid and method combination.

When matrix_source is None (default) the interpolation matrix is automatically downloaded and stored in a local cache and when it is needed again the cached version is used.

Once the matrix is available the interpolation is performed by multiplying the values vector with it.

Note

Please see the inventory for the list of available matrices.

Examples