core.interpolate
- class core.interpolate.Linear(values: DataArray, bounds: Literal['error', 'nan', 'clip', 'cycle'] = 'error', spacing: Literal['regular', 'irregular', 'auto'] | Callable[[float], float] = 'auto', period: float | None = None)[source]
Bases:
object
- class core.interpolate.Linear_Indexer(coords: ndarray[tuple[Any, ...], dtype[_ScalarT]], bounds: str, spacing, period=None)[source]
Bases:
object
- class core.interpolate.Locator(coords: ndarray[tuple[Any, ...], dtype[_ScalarT]], bounds: str)[source]
Bases:
objectThe purpose of these classes is to locate values in coordinate axes.
- class core.interpolate.Locator_Regular(coords, bounds: str, inversion_func: Callable | None = None, period=None)[source]
Bases:
Locator
- class core.interpolate.Nearest(values: DataArray, tolerance: float | None = None, spacing: Literal['auto'] | Callable[[float], float] = 'auto')[source]
Bases:
object
- class core.interpolate.Nearest_Indexer(coords: ndarray[tuple[Any, ...], dtype[_ScalarT]], tolerance: float | None, spacing: str | Callable = 'auto')[source]
Bases:
object
- class core.interpolate.Spline(values, tension=0.5, bounds: Literal['error', 'nan', 'clip'] = 'error', spacing: Literal['regular', 'irregular', 'auto'] | Callable[[float], float] = 'auto')[source]
Bases:
object
- class core.interpolate.Spline_Indexer(coords: ndarray[tuple[Any, ...], dtype[_ScalarT]], bounds: str, spacing, tension: float)[source]
Bases:
object
- core.interpolate.broadcast_numpy(ds: Dataset) Dict[source]
Returns all data variables in ds as numpy arrays broadcastable against each other (with new single-element dimensions)
This requires the input to be broadcasted to common dimensions.
- core.interpolate.broadcast_shapes(ds: Dataset, dims) Dict[source]
For each data variable in ds, returns the shape for broadcasting in the dimensions defined by dims
- core.interpolate.create_locator(coords, bounds: str, spacing, period: float | None = None) Locator[source]
Locator factory
The purpose of this method is to instantiate the appropriate “Locator” class.
The args are passed from the indexers.
- core.interpolate.determine_output_dimensions(data: DataArray, ds_dims: list, dims_sel_interp: Iterable) list[source]
Determine output dimensions for interpolated/selected DataArray.
This function implements numpy’s advanced indexing rules to determine the final dimension ordering of the output DataArray after interpolation/selection operations.
The key principle is that when advanced indexing is applied to some dimensions of an array, those dimensions are replaced by the dimensions of the indexing arrays, and these new dimensions are inserted at the position of the first indexed dimension.
- Parameters:
data (xr.DataArray) – The input DataArray being interpolated/selected
ds_dims (list) – List of dimension names from the indexing Dataset (the new dimensions that will replace the indexed dimensions)
dims_sel_interp (set or list) – Set/list of dimension names from data that are being interpolated or selected (i.e., dimensions with advanced indexing)
- Returns:
Ordered list of dimension names for the output DataArray
- Return type:
list
- core.interpolate.find_indices(grid, xi) tuple[ndarray, ndarray][source]
Multi-dimensional grid interpolation preprocessing.
- Parameters:
grid – Tuple of 1D arrays defining grid coordinates for each dimension
xi – 2D array where each row represents a dimension and each column a query point
- Returns:
Grid interval indices for each query point in each dimension distances: Normalized distances within each interval
- Return type:
indices
- core.interpolate.interp(da: DataArray, **kwargs)[source]
Interpolate/select a DataArray onto new coordinates.
- This function is similar to xr.interp and xr.sel, but:
Supports dask-based coordinates inputs without triggering immediate computation as is done by xr.interp
Supports combinations of selection and interpolation. This is faster and more memory efficient than performing independently the selection and interpolation.
Supports pointwise indexing/interpolation using dask arrays (see https://docs.xarray.dev/en/latest/user-guide/indexing.html#more-advanced-indexing)
Supports per-dimension options (nearest neighbour selection, linear/spline interpolation, out-of-bounds behaviour, cyclic dimensions…)
- Parameters:
da (xr.DataArray) – The input DataArray
**kwargs –
definition of the selection/interpolation coordinates for each dimension, using the following classes:
Linear: linear interpolation (like xr.DataArray.interp)
Nearest: nearest neighbour selection (like xr.DataArray.sel)
Index: integer index selection (like xr.DataArray.isel)
These classes store the coordinate data in their .values attribute and have a .get_indexer method which returns an indexer for the passed coordinates.
Example
>>> interp( ... data, # input DataArray with dimensions (a, b, c) ... a = Linear( # perform linear interpolation along dimension `a` ... a_values, # `a_values` is a DataArray with dimension (x, y); ... bounds='clip'), # clip out-of-bounds values to the axis min/max. ... b = Nearest(b_values), # perform nearest neighbour selection along ... # dimension `b`; `b_values` is a DataArray ... # with dimension (x, y) ... ) # returns a DataArray with dimensions (x, y, c) No interpolation or selection is performed along dimension `c` thus it is left as-is.
- Returns:
DataArray on the new coordinates.
- Return type:
xr.DataArray
- core.interpolate.interp_block(ds: Dataset, da: DataArray, out_dims, indexers: Dict) DataArray[source]
This function is called by map_blocks in function interp, and performs the indexing and interpolation at the numpy level.
It relies on the indexers to perform index searching and weight calculation, and performs a linear combination of the sub-arrays.