regrid (high-level) with precomputed weights

regrid(data, in_grid=None, out_grid=None, in_dims=None, out_dims=None, interpolation='linear', backend='precomputed', inventory='ecmwf')

Regrid the high-level data object (with geography information) using precomputed weights.

Parameters:
  • data (FieldList, Field, xarray.DataArray, xarray.Dataset, bytes, io.BytesIO) –

    The data to be regridded. The following input data types are supported:

  • in_grid (dict, str, eckit.geo.Grid) – the gridspec describing the input grid. It is only needed when the input grid cannot be automatically inferred from the input data. This can be the case for Xarray, where at present the grid information can only be accessed via the “earthkit.grid_spec” attribute, and if it is missing or does not contain the necessary information in_grid needs to be provided. When in_grid is provided, it takes precedence over the metadata of the input data. For the list of supported grids, please refer to the gridspec documentation.

  • out_grid (dict, str, eckit.geo.Grid) – the gridspec describing the target grid that data will be interpolated onto. For the list of supported grids, please refer to the gridspec documentation.

  • in_dims (list, tuple, None) – the names of the geographical dimensions in the Xarray input data. It is only needed when the dimension names cannot be automatically inferred. When it is provided, it takes precedence over the metadata of the input data.

  • out_dims (list, tuple, None) – the names of the geographical dimensions in the Xarray output data. It is only needed when the dimension names cannot be automatically inferred. When it is provided, it takes precedence over the metadata of the input data.

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

  • inventory (str) –

    the path to the inventory of the precomputed weights. The interpolation only works when the weights are available for the given input grid (automatically determined from the data), target grid and interpolation combination. At present, two inventory types are available:

    • If inventory is “ecmwf” on None, the remote inventory managed by ECMWF is used. In this case the weights are automatically downloaded and stored in a local cache (at "~/.cache/earthkit-geo") and when it is needed again the cached version is used. See the inventory for the list of supported grid to grid combinations with this backend.

    • If inventory is a local path, a local inventory is used. Please note this in experimental feature only used for development purposes.

Returns:

Return the regridded data with the same type as data but with the grid changed to the output grid.

Return type:

The same type of data as data.

Raises:

ValueError – if the precomputed weights are not available

The regridding is performed by multiplying the data vector with the interpolation weights, which forms a sparse matrix (sparse matrix-vector multiplication).

Notes

The interpolation only works when the weights are available for the given input grid (automatically determined from the data), target grid and interpolation combination. See the inventory for the available combinations with the “ecmwf” inventory.

The regridding is performed by multiplying the data vector with the interpolation weights, which forms a sparse matrix (sparse matrix-vector multiplication).

Examples