sel

function of dascore.proc.coords source

sel(
    patch: Patch ,
    indexers: collections.abc.Mapping[collections.abc.Mapping[str, Any], None] = None,
    method: Literal[‘nearest’] | None = None,
    tolerance: Any = None,
    drop: bool = False,
    **indexers_kwargs: Any ,
)-> ‘PatchType’

Select coordinate labels with xarray-compatible dimension indexing.

This method is provided for compatibility with xarray’s DataArray.sel for the supported indexing operations described below. Use Patch.select for DASCore’s tuple range notation, relative selections, and filtering that preserves dimensions and source order.

Parameters

Parameter Description
patch Patch to index.
indexers Mapping of dimension names to scalar labels, slices, or 1D label arrays.
Supply this or keyword indexers. Quantities convert to coordinate units.
method None requires exact matches; "nearest" selects the nearest label.
tolerance Maximum distance allowed for nearest matches, in coordinate units or as
a quantity. Datetime tolerances are durations. Not supported with slices.
drop Drop coordinates made scalar by indexing instead of retaining them.
Scalar indexers remove their dimension regardless of this option.
**indexers_kwargs Dimension indexers supplied as keywords.
Note

Label slices include both endpoints. Arrays preserve order and repetitions, selecting every combination when several dimensions have array indexers. Missing scalar or array labels raise KeyError. Slices follow coordinate order, including descending coordinates, and require sliceable labels. Datetime strings follow pandas’ partial-date selection rules. Evenly sampled coordinates stay compact during lookup and slicing. Floating slice labels can differ from xarray by rounding relative to the original range. Array/nearest lookup on long grids below floating-point resolution raises instead of expanding the grid to check whether every label is unique.

This supports dimension coordinates, not arbitrary auxiliary coordinates or MultiIndexes. Labelled xarray indexers and multidimensional indexer arrays are not supported. Dimensions without labels use positional indexing.

Examples

import dascore as dc
patch = dc.get_example_patch()
window = patch.sel(distance=slice(10, 20))
assert window.shape[0] == 11
channel = patch.sel(distance=10.2, method="nearest", tolerance=0.5)
assert channel.get_array("distance") == 10

See Also

Patch.isel : Xarray-compatible positional indexing. Patch.select : Range filtering and relative selections.