xcdat.regridder.accessor.RegridderAccessor#

class xcdat.regridder.accessor.RegridderAccessor(dataset)[source]#

An accessor class that provides regridding attributes and methods on xarray Datasets through the .regridder attribute.

Examples

Import RegridderAccessor class:

>>> import xcdat  # or from xcdat import regridder

Use RegridderAccessor class:

>>> ds = xcdat.open_dataset("/path/to/file")
>>>
>>> ds.regridder.<attribute>
>>> ds.regridder.<method>
>>> ds.regridder.<property>
Parameters

dataset (xr.Dataset) – A Dataset object.

__init__(dataset)[source]#

Methods

__init__(dataset)

horizontal(data_var, output_grid[, tool])

Apply horizontal regridding to data_var of the current xr.Dataset to output_grid.

horizontal_regrid2(data_var, output_grid, ...)

Pure python implementation of CDAT's regrid2 horizontal regridder.

horizontal_xesmf(data_var, output_grid, ...)

Wraps the xESMF library providing access to regridding between structured rectilinear and curvilinear grids.

Attributes

grid

Returns xr.Dataset containing grid information.

_ds#
property grid#

Returns xr.Dataset containing grid information.

Returns

xr.Dataset – With data variables describing the grid.

Raises
  • ValueError – If axis dimension coordinate variable is not correctly identified.

  • ValueError – If axis has multiple dimensions (only one is expected).

_get_axis_data(name)[source]#
horizontal_xesmf(data_var, output_grid, **options)[source]#

Wraps the xESMF library providing access to regridding between structured rectilinear and curvilinear grids.

Regrids data_var in dataset to output_grid.

Option documentation xcdat.regridder.xesmf.XESMFRegridder()

Parameters
  • data_var (str) – Name of the variable in the xr.Dataset to regrid.

  • output_grid (xr.Dataset) – Dataset containing output grid.

  • options (Dict[str, Any]) – Dictionary with extra parameters for the regridder.

Returns

xr.Dataset – With the data_var variable on the grid defined in output_grid.

Raises

ValueError – If tool is not supported.

Examples

Generate output grid:

>>> output_grid = xcdat.create_gaussian_grid(32)

Regrid data to output grid using xesmf:

>>> ds.regridder.horizontal_xesmf("ts", output_grid)
horizontal_regrid2(data_var, output_grid, **options)[source]#

Pure python implementation of CDAT’s regrid2 horizontal regridder.

Regrids data_var in dataset to output_grid using regrid2’s algorithm.

Options documentation xcdat.regridder.regrid2.Regrid2Regridder()

Parameters
  • data_var (str) – Name of the variable in the xr.Dataset to regrid.

  • output_grid (xr.Dataset) – Dataset containing output grid.

  • options (Dict[str, Any]) – Dictionary with extra parameters for the regridder.

Returns

xr.Dataset – With the data_var variable on the grid defined in output_grid.

Raises

ValueError – If tool is not supported.

Examples

Generate output grid:

>>> output_grid = xcdat.create_gaussian_grid(32)

Regrid data to output grid using regrid2:

>>> ds.regridder.horizontal_regrid2("ts", output_grid)
horizontal(data_var, output_grid, tool='xesmf', **options)[source]#

Apply horizontal regridding to data_var of the current xr.Dataset to output_grid.

Supported tools:

Parameters
  • data_var (str) – Name of the variable in the xr.Dataset to regrid.

  • output_grid (xr.Dataset) – Dataset containing output grid.

  • tool (str) – Name of the regridding tool.

  • **options (Dict[str, Any]) – These options are passed to the tool being used for regridding. See specific regridder documentation for available options.

Returns

xr.Dataset – With the data_var variable on the grid defined in output_grid.

Raises

ValueError – If tool is not supported.

Examples

Create destination grid:

>>> output_grid = xcdat.create_uniform_grid(-90, 90, 4.0, -180, 180, 5.0)

Regrid variable using “xesmf”:

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

Regrid variable using “regrid2”:

>>> ds.regridder.horizontal("ts", output_grid, tool="regrid2")

Use convenience methods:

>>> ds.regridder.horizontal_xesmf("ts", output_grid, method="bilinear")
>>> ds.regridder.horizontal_regrid2("ts", output_grid)