xarray.DataArray.qsel¶
- DataArray.qsel(self, indexers=None, *, func='mean', **indexers_kwargs)[source]¶
Select and aggregate data along specified dimensions.
- Parameters:
indexers (
Mapping[Hashable,float|slice] |None, default:None) –Dictionary specifying the dimensions and their values or slices. Position along a dimension can be specified in three ways:
As a scalar value or a collection of scalar values:
alpha=-1.2oralpha=[-1.2, 0.0, 1.2]:If no width is specified, the data is selected along the nearest value for each element. It is equivalent to calling
xarray.DataArray.sel()withmethod='nearest'. When a collection is provided, multiple selections are made and concatenated along the dimension. In this case, the width may also be provided as a collection with the same length.As a value and width:
alpha=5, alpha_width=0.5The data is aggregated over a slice of width
alpha_width, centered atalpha. Ifalphais a collection, the data is aggregated over multiple slices and concatenated along the dimension.As a slice:
alpha=slice(-10, 10)The data is selected over the specified slice. No averaging is performed. This is equivalent to calling
xarray.DataArray.sel()with a slice.
One of
indexersorindexers_kwargsmust be provided.**indexers_kwargs – The keyword arguments form of
indexers. One ofindexersorindexers_kwargsmust be provided.func (
{"mean", "min", "max", "sum"}, optional) – Function used when qsel aggregates over width-based selections. Must be one of"mean","min","max", or"sum"."mean"by default. This argument only affects reduced data; reduced numeric coordinates are still represented by their mean.
- Returns:
DataArray– The selected and aggregated data.
Note
Unlike
xarray.DataArray.sel(), this method treats all dimensions without coordinates as equivalent to having coordinates assigned from 0 ton-1, wherenis the size of the dimension. For example:da = xr.DataArray(np.random.rand(10), dims=("x",)) da.sel(x=slice(2, 3)) # This works da.sel(x=slice(2.0, 3.0)) # This raises a TypeError da.qsel(x=slice(2.0, 3.0)) # This works