xcdat.regridder.xgcm.XGCMRegridder#

class xcdat.regridder.xgcm.XGCMRegridder(input_grid, output_grid, method='linear', target_data=None, grid_positions=None, periodic=False, extra_init_options=None, **options)[source]#
__init__(input_grid, output_grid, method='linear', target_data=None, grid_positions=None, periodic=False, extra_init_options=None, **options)[source]#

Extension of xgcm regridder.

The XGCMRegridder extends xgcm by automatically constructing the Grid object, transposing the output data to match the dimensional order of the input data, and ensuring bounds and metadata are preserved in the output dataset.

Linear and log methods require a single dimension position, which can usually be automatically derived. A custom position can be specified using the grid_positions argument.

Conservative regridding requires multiple dimension positions, e.g., {“center”: “xc”, “left”: “xg”} which can be passed using the grid_positions argument.

xgcm.Grid can be passed additional arguments using extra_init_options. These arguments can be found on XGCM’s Grid documentation.

xgcm.Grid.transform can be passed additional arguments using options. These arguments can be found on XGCM’s Grid.transform documentation.

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

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

  • method (XGCMVerticalMethods) –

    Regridding method, by default “linear”. Options are
    • linear (default)

    • log

    • conservative

  • target_data (Optional[Union[str, xr.DataArray]]) – Data to transform target data onto, either the key of a variable in the input dataset or an xr.DataArray, by default None.

  • grid_positions (Optional[Dict[str, str]]) – Mapping of dimension positions, by default None. If None then an attempt is made to derive this argument.

  • periodic (Optional[bool]) – Whether the grid is periodic, by default False.

  • extra_init_options (Optional[Dict[str, Any]]) – Extra options passed to the xgcm.Grid constructor, by default None.

  • options (Optional[Dict[str, Any]]) – Extra options passed to the xgcm.Grid.transform method.

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

  • ValueError – If method is not valid.

Examples

Import xCDAT:

>>> import xcdat

Open a dataset:

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

Create output grid:

>>> output_grid = xcdat.create_grid(lev=np.linspace(1000, 1, 5))

Regrid data to output_grid:

>>> output_data = ds.regridder.vertical(
>>>     "so", output_grid, tool="xgcm", method="linear"
>>> )

Create pressure variable:

>>> ds["pressure"] = (ds["hyam"] * ds["P0"] + ds["hybm"] * ds["PS"]).transpose(
>>>     **ds["T"].dims
>>> )

Regrid data to output_grid in pressure space:

>>> output_data = ds.regridder.vertical(
>>>     "so", output_grid, tool="xgcm", method="linear", target_data="pressure"
>>> )

Passing additional arguments to xgcm.Grid and xgcm.Grid.transform:

>>> regridder = xgcm.XGCMRegridder(
>>>     ds,
>>>     output_grid,
>>>     method="linear",
>>>     extra_init_options={"boundary": "fill", "fill_value": 1e27},
>>>     mask_edges=True
>>> )

Methods

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

Extension of xgcm regridder.

horizontal(data_var, ds)

Placeholder for base class.

vertical(data_var, ds)

See documentation in xcdat.regridder.xgcm.XGCMRegridder()

horizontal(data_var, ds)[source]#

Placeholder for base class.

vertical(data_var, ds)[source]#

See documentation in xcdat.regridder.xgcm.XGCMRegridder()

_get_grid_positions()[source]#
_abc_impl = <_abc._abc_data object>#