xcdat.regridder.xesmf.XESMFRegridder#

class xcdat.regridder.xesmf.XESMFRegridder(input_grid, output_grid, method, periodic=False, extrap_method=None, extrap_dist_exponent=None, extrap_num_src_pnts=None, ignore_degenerate=True, unmapped_to_nan=True, **options)[source]#
__init__(input_grid, output_grid, method, periodic=False, extrap_method=None, extrap_dist_exponent=None, extrap_num_src_pnts=None, ignore_degenerate=True, unmapped_to_nan=True, **options)[source]#

Extension of xESMF regridder.

This method extends xESMF by automatically constructing by xesmf.XESMFRegridder object and ensuring bounds and metadata are preserved in the output dataset.

The method argument can take any of the following values: bilinear, conservative, conservative_normed, patch, nearest_s2d, or nearest_d2s. You can find a comparison of the methods here.

The extrap_method argument can take any of the following values: inverse_dist or nearest_s2d. This argument along with extrap_dist_exponent and extrap_num_src_pnts can be used to configure how extrapolation is applied.

The **options arguments are additional values passed to the xesmf.XESMFRegridder constructor. A description of these arguments can be found on xESMF’s documentation.

Parameters:
  • input_grid (xr.Dataset) – Contains source grid coordinates.

  • output_grid (xr.Dataset) – Contains desintation grid coordinates.

  • method (str) – The regridding method to apply, defaults to “bilinear”.

  • periodic (bool) – Treat longitude as periodic, used for global grids.

  • extrap_method (Optional[str]) – Extrapolation method, useful when moving from a fine to coarse grid.

  • extrap_dist_exponent (Optional[float]) – The exponent to raise the distance to when calculating weights for the extrapolation method.

  • extrap_num_src_pnts (Optional[int]) – The number of source points to use for the extrapolation methods that use more than one source point.

  • ignore_degenerate (bool) – Ignore degenerate cells when checking the input_grid for errors. If set False, a degenerate cell produces an error.

    This only applies to “conservative” and “conservative_normed” regridding methods.

  • unmapped_to_nan (bool) – Sets values of unmapped points to np.nan instead of 0 (ESMF default).

  • **options (Any) – Additional arguments passed to the underlying xesmf.XESMFRegridder constructor.

Raises:
  • KeyError – If data variable does not exist in the Dataset.

  • ValueError – If method is not valid.

  • ValueError – If extrap_method is not valid.

Examples

Import xCDAT:

>>> import xcdat

Open a dataset:

>>> ds = xcdat.open_dataset("...")

Create output grid:

>>> output_grid = xcdat.create_gaussian_grid(32)

Regrid the “ts” variable using the “bilinear” method:

>>> output_data = ds.regridder.horizontal(
>>>     "ts", output_grid, tool="xesmf", method="bilinear"
>>> )

Passing additional values to xesmf.XESMFRegridder:

>>> output_data = ds.regridder.horizontal(
>>>     "ts", output_grid, tool="xesmf", method="bilinear", unmapped_to_nan=True
>>> )

Methods

__init__(input_grid, output_grid, method[, ...])

Extension of xESMF regridder.

horizontal(data_var, ds)

See documentation in xcdat.regridder.xesmf.XESMFRegridder()

vertical(data_var, ds)

Placeholder for base class.

vertical(data_var, ds)[source]#

Placeholder for base class.

horizontal(data_var, ds)[source]#

See documentation in xcdat.regridder.xesmf.XESMFRegridder()

_abc_impl = <_abc._abc_data object>#