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, **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, **options)[source]#

Wrapper class for xESMF regridder class.

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

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

  • method (str) –

    Regridding method. Options are
    • bilinear

    • conservative

    • conservative_normed

    • patch

    • nearest_s2d

    • nearest_d2s

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

  • extrap_method (Optional[str]) –

    Extrapolation method. Options are
    • inverse_dist

    • nearest_s2d

  • 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.

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
>>> from xcdat.regridder import xesmf

Open a dataset:

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

Create output grid:

>>> output_grid = xcdat.create_gaussian_grid(32)

Create regridder:

>>> regridder = xesmf.XESMFRegridder(ds, output_grid, method="bilinear")

Regrid data:

>>> data_new_grid = regridder.horizontal("ts", ds, periodic=True)

Methods

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

Wrapper class for xESMF regridder class.

horizontal(data_var, ds)

Regrid data_var in ds to output grid.

horizontal(data_var, ds)[source]#

Regrid data_var in ds to output grid.

Parameters
  • data_var (str) – The name of the data variable inside the dataset to regrid.

  • ds (xr.Dataset) – The dataset containing data_var.

Returns

xr.Dataset – Dataset with variable on the destination grid.

Raises

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

Examples

Create output grid:

>>> output_grid = xcdat.create_gaussian_grid(32)

Create regridder:

>>> regridder = xesmf.XESMFRegridder(ds, output_grid, method="bilinear")

Regrid data:

>>> data_new_grid = regridder.horizontal("ts", ds)
_abc_impl = <_abc._abc_data object>#