Dask-aware regridding

To apply a regridding you will need a set of weights mapping from the source grid to the target grid.

Regridding weights can be generated online using ESMF_RegridWeightGen (esmf_generate_weights()) or CDO (cdo_generate_weights()), or offline by calling these programs externally (this is recommended especially for large grids, using ESMF_REgridWeightGen in MPI mode).

Once calculated regrid() will apply these weights using a Dask sparse matrix multiply, maintaining chunking in dimensions other than lat and lon.

Regrid can create basic weights and store them to apply the weights to multiple datasets.

class climtas.regrid.Regridder(source_grid=None, target_grid=None, weights=None)[source]#

Set up the regridding operation

Supply either both source_grid and dest_grid or just weights.

For large grids you may wish to pre-calculate the weights using ESMF_RegridWeightGen, if not supplied weights will be calculated from source_grid and dest_grid using CDO’s genbil function.

Weights may be pre-computed by an external program, or created using cdo_generate_weights() or esmf_generate_weights()

  • source_grid (coecms.grid.Grid or xarray.DataArray) – Source grid / sample dataset

  • target_grid (coecms.grid.Grid or xarray.DataArray) – Target grid / sample dataset

  • weights (xarray.Dataset) – Pre-computed interpolation weights


Regrid source_data to match the target grid


xarray.DataArray or xarray.Dataset with a regridded version of the source variable

climtas.regrid.apply_weights(source_data, weights, weights_matrix=None)[source]#

Apply the CDO weights weights to source_data, performing a regridding operation


Regridded version of the source dataset

Return type


climtas.regrid.cdo_generate_weights(source_grid, target_grid, method='bil', extrapolate=True, remap_norm='fracarea', remap_area_min=0.0)[source]#

Generate weights for regridding using CDO

Available weight generation methods are:

  • bic: SCRIP Bicubic

  • bil: SCRIP Bilinear

  • con: SCRIP First-order conservative

  • con2: SCRIP Second-order conservative

  • dis: SCRIP Distance-weighted average

  • laf: YAC Largest area fraction

  • ycon: YAC First-order conservative

  • nn: Nearest neighbour

Run cdo gen${method} --help for details of each method

  • source_grid (xarray.DataArray) – Source grid

  • target_grid (xarray.DataArray) – Target grid description

  • method (str) – Regridding method

  • extrapolate (bool) – Extrapolate output field

  • remap_norm (str) – Normalisation method for conservative methods

  • remap_area_min (float) – Minimum destination area fraction


xarray.Dataset with regridding weights


Convert the weights from CDO/ESMF to a numpy array

climtas.regrid.esmf_generate_weights(source_grid, target_grid, method='bilinear', extrap_method='nearestidavg', norm_type='dstarea', line_type=None, pole=None, ignore_unmapped=False)[source]#

Generate regridding weights with ESMF

  • source_grid (xarray.Dataarray) – Source grid. If masked the mask will be used in the regridding

  • target_grid (xarray.Dataarray) – Target grid. If masked the mask will be used in the regridding

  • method (str) – ESMF Regridding method, see ESMF_RegridWeightGen --help

  • extrap_method (str) – ESMF Extrapolation method, see ESMF_RegridWeightGen --help


xarray.Dataset with regridding information from


climtas.regrid.regrid(source_data, target_grid=None, weights=None)[source]#

A simple regrid. Inefficient if you are regridding more than one dataset to the target grid because it re-generates the weights each time you call the function.

To save the weights use Regridder.


xarray.DataArray with a regridded version of the source variable