cf.Field.regridc

Field.regridc(dst, axes, method='auto', use_dst_mask=False, fracfield=False, axis_order=None, ignore_degenerate=True, i=False, _compute_field_mass=None)[source]

Returns the field with the specified Cartesian axes regridded onto a new grid. Between 1 and 3 dimensions may be regridded.

Regridding, also called remapping or interpolation, is the process of changing the grid underneath field data values while preserving the qualities of the original data.

By default the the regridding is a first-order conservative interpolation, but bilinear and nearest neighbour interpolation is available.

Metadata

The field’s domain must have axes matching those specified in src_axes. The same is true for the destination grid, if it provided as part of another field. Optionally the axes to use from the destination grid may be specified separately in dst_axes.

The output field’s coordinate objects which span the specified axes are replaced with those from the destination grid. Any fields contained in coordinate reference objects will also be regridded, if possible.

Mask

The data array mask of the field is automatically taken into account, such that the regridded data array will be masked in regions where the input data array is masked. By default the mask of the destination grid is not taken into account. If the destination field data has more dimensions than the number of axes specified then, if used, its mask is taken from the 1-3 dimensional section of the data where the indices of all axes other than X and Y are zero.

Method

The interpolation is carried by out using the ESMF package - a Python interface to the Earth System Modeling Framework (ESMF) regridding utility.

Logging

Whether ESMF logging is enabled or not is determined by cf.REGRID_LOGGING. If it is logging takes place after every call. By default logging is disabled.

Examples 1:

Regrid the time axes of field f conservatively onto a grid contained in field g:

>>> h = f.regridc(g, axes='T')
Parameters:
dst: cf.Field or dict

The field containing the new grid or a dictionary with the axes specifiers as keys referencing dimension coordinates. If dst is a field list the first field in the list is used.

axes:

Select dimension coordinates from the source and destination fields for regridding. See cf.Field.axes for options for selecting specific axes. However, the number of axes returned by cf.Field.axes must be the same as the number of specifiers passed in.

method: str, optional

By default the regridding method is set to ‘auto’. In this case conservative regridding will be used unless one or both of the fields does not have contiguous bounds, in which case bilinear regridding will be used. If a 1D dimension coordinate does not have bounds then contiguous bounds will be created automatically. If this parameter is set to conservative then first-order conservative regridding is used. If it is set to ‘bilinear’ then multilinear interpolation is used. If it is set to ‘nearest_stod’ then nearest neighbor interpolation is used where each destination point is mapped to the closest source point. A given source point may map to multiple destination points, but no destination point will receive input from more than one source point. If it is set to ‘nearest_dtos’ then nearest neighbor interpolation is used where each source point is mapped to the closest destination point. A given destination point may receive input from multiple source points, but no source point will map to more than one destination point.

use_dst_mask: bool, optional

By default the mask of the data on the destination grid is not taken into account when performing regridding. If this option is set to true then it is.

fracfield: bool, optional

If the method of regridding is conservative the fraction of each destination grid cell involved in the regridding is returned instead of the regridded data if this is True. Otherwise this is ignored.

axis_order: sequence, optional

A sequence of items specifying dimension coordinates as retrieved by the dim method. These determine the order in which to iterate over the other axes of the field when regridding slices. The slowest moving axis will be the first one specified. Currently the regridding weights are recalculated every time the mask of a slice changes with respect to the previous one, so this option allows the user to minimise how frequently the mask changes.

ignore_degenerate: bool, optional

True by default. Instructs ESMPy to ignore degenerate cells when checking the grids for errors. Regridding will proceed and degenerate cells will be skipped, not producing a result, when set to True. Otherwise an error will be produced if degenerate cells are found. This will be present in the ESMPy log files if cf.REGRID_LOGGING is set to True. As of ESMF 7.0.0 this only applies to conservative regridding. Other methods always skip degenerate cells.

i: bool, optional

If True then update the field in place. By default a new field is created. In either case, a field is returned.

_compute_field_mass: dict, optional

If this is a dictionary then the field masses of the source and destination fields are computed and returned within the dictionary. The keys of the dictionary indicates the lat/long slice of the field and the corresponding value is a tuple containing the source field’s mass and the destination field’s mass. The calculation is only done if conservative regridding is being performed. This is for debugging purposes.

Returns:
out: cf.Field

The regridded field.

Examples 2:

Regrid the T axis of field f conservatively onto the grid specified in the dimension coordinate t:

>>> h = f.regridc({'T': t}, axes=('T'))

Regrid the T axis of field f using bilinear interpolation onto a grid contained in field g:

>>> h = f.regridc(g, axes=('T'), method='bilinear')

Regrid the X and Y axes of field f conservatively onto a grid contained in field g:

>>> h = f.regridc(g, axes=('X','Y'))

Regrid the X and T axes of field f conservatively onto a grid contained in field g using the destination mask:

>>> h = f.regridc(g, axes=('X','Y'), use_dst_mask=True)