select

function of dascore.proc.coords source

select(
    patch: Patch ,
    copy = False,
    relative = False,
    samples = False,
    **kwargs ,
)-> ‘PatchType’

Return a subset of the patch.

Any dimension name can be passed as key, and the values can be: - a tuple of (min, max) for that dimension, or an equivalent slice. None and … both indicate open intervals, as does an infinite bound pointing away from the data, eg (min, np.inf). - an integer, when samples=True, to select a single row or column. - an array of values to select, which must be a subset of the coordinate array. - an array of booleans of the same length as the coordinate where True indicates values to keep. This form does not support samples=True.

For xarray-compatible indexing, use Patch.sel for labels or Patch.isel for sample positions. These methods preserve indexer order and repetitions and remove dimensions selected with scalar indexers. select preserves dimensions and filters values in source order.

Parameters

Parameter Description
patch The patch object.
copy Copy the result so it does not retain the original data array.
relative If True, select ranges are relative to the start of coordinate, if
positive, or the end of the coordinate, if negative.
samples If True, the query meaning is in samples.
**kwargs Used to specify the coordinate on which data are selected.

Examples

import numpy as np
from dascore.examples import get_example_patch
patch = get_example_patch()

# Coordinate values and open bounds.
new_distance = patch.select(distance=(50, 300))
lt_dist = patch.select(distance=(..., 300))

# One second from the start through one second before the end.
new_time = patch.select(time=(1, -1), relative=True)

# Sample ranges and scalar sample indices.
new_distance1 = patch.select(distance=(..., 10), samples=True)
new_distance2 = patch.select(time=-1, samples=True)

# Boolean masks and explicit coordinate values.
time = patch.get_array("time")
new_time_5 = patch.select(time=time > time[2])
distance = patch.get_array("distance")
new_distance_3 = patch.select(distance=distance[1::2])
Note

Selection filters values without reordering or repeating them; use Patch.order for those operations.

Value ranges include both endpoints. Sample ranges are half-open like Python slices, so -1 as a range end excludes the final sample while the scalar -1 selects it:

import dascore as dc patch = dc.get_example_patch() len(patch.select(distance=(0, 10)).get_array(“distance”)) 11 len(patch.select(time=(0, 10), samples=True).get_array(“time”)) 10 len(patch.select(time=(0, -1), samples=True).get_array(“time”)) 1999 len(patch.select(time=-1, samples=True).get_array(“time”)) 1

See Also

Patch.sel : Xarray-compatible label indexing. Patch.isel : Xarray-compatible positional indexing.