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, output_weights=False, create_nan_mask=False, **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, output_weights=False, create_nan_mask=False, **options)[source]#
Extension of
xESMFregridder.This method extends
xESMFby automatically constructing byxesmf.XESMFRegridderobject and ensuring bounds and metadata are preserved in the output dataset.The
methodargument 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_methodargument can take any of the following values: inverse_dist or nearest_s2d. This argument along withextrap_dist_exponentandextrap_num_src_pntscan be used to configure how extrapolation is applied.The
**optionsarguments are additional values passed to thexesmf.XESMFRegridderconstructor. 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 (
str | None) – Extrapolation method, useful when moving from a fine to coarse grid.extrap_dist_exponent (
float | None) – The exponent to raise the distance to when calculating weights for the extrapolation method.extrap_num_src_pnts (
int | None) – 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).output_weights (
bool | str) – If True, output weights are added to the output dataset as weights. If str, the name of the variable to store the weights. Default is False.create_nan_mask (
bool) – If True, a mask is created using the nan values from source variable. If a mask already exists in the Dataset it will be ignored. Default is False.**options (
Any) – Additional arguments passed to the underlyingxesmf.XESMFRegridderconstructor.
- Raises:
KeyError – If data variable does not exist in the Dataset.
ValueError – If
methodis not valid.ValueError – If
extrap_methodis 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
xESMFregridder.horizontal(data_var, ds)See documentation in
xcdat.regridder.xesmf.XESMFRegridder()vertical(data_var, ds)Placeholder for base class.
- horizontal(data_var, ds)[source]#
See documentation in
xcdat.regridder.xesmf.XESMFRegridder()
- _abc_impl = <_abc._abc_data object>#