xoa.regrid.regrid1d#
- xoa.regrid.regrid1d(da, coord, method=None, dim=None, coord_in_name=None, edges=None, conserv=False, extrap='no', bias=0.0, tension=0.0, drop_na=False, maxgap=0, dask='parallelized')[source]#
Regrid along a single dimension
The input and output coordinates may vary along other dimensions, which useful for instance for vertical interpolation in coastal ocean models. Since it uses
xarray.apply_ufunc(), it supports dask arrays. The core computation is performed by the numba-accelerated routines ofxoa.core.regrid.- Parameters:
da (xarray.DataArray) – Array to regrid.
coord (xarray.DataArray) – Output coordinate.
method (str, int) – Regridding method as one of the following:
1|"linear"|"interp",0|"nearest",2|"cubic",3|"hermit"|"hermitian",-1|"cellave",-2|"cellerr"dim (str, tuple(str), None) – Dimension on which to operate. If a string, it is expected to be the same dimension for both input and output coordinates. Else, provide a two-element tuple:
(dim_in, dim_out). It is inferred by default from output coordinate et input data array.coord_in_name (str, None) – Name of the input coordinate array, which must be known of
da. It is inferred from the input data array and dimension name by default.edges (dict, None) – Grid edge coordinates along the interpolation dimension, for the conservative regridding. When not provided, edges are computed with
xoa.grid.get_edges(). Keys are “in” and/or “out” and values are arrays with the same shape as coordinates except along the interpolation dimension on which 1 is added.conserv (bool) – Use conservative regridding when using
cellavemethod.extrap (str, int) – Extrapolation mode as one of the following:
0|"no"|"none"|"false",1|"top"|"above"|"after",-1|"bottom"|"below",2|"both"|"all"|"yes"|"true"drop_na (bool) – Drop input inner NaNs during interpolation. Note that outer NaNs are always ignored.
cellaveandcellerrmethods don’t support the parameter.maxgap (int) – Max size for a gap to be interpolated when
drop_nais True. Size is not checked whenmaxgapis zero.dask (str) – See
xarray.apply_ufunc().
- Returns:
xarray.DataArray – Regridded array with
coordas new coordinate array. Name and attributes are preserved fromda.
Example
Linear interpolation from 4 depth levels to 7:
zi = xr.DataArray(np.arange(4.), dims="z") vi = xr.DataArray(np.arange(4.), dims="z", coords=dict(z=zi)) zo = xr.DataArray(np.linspace(0, 3, 7), dims="z") vo = regrid1d(vi, zo, method="linear")