import numpy as np
import dascore as dc
from dascore.examples import get_example_patch
= get_example_patch()
patch # select meters 50 to 300
= patch.select(distance=(50, 300))
new_distance # select channels less than 300
= patch.select(distance=(..., 300))
lt_dist # select time (1 second from start to -1 second from end)
= patch.attrs.time_min + dc.to_timedelta64(1)
t1 = patch.attrs.time_max - dc.to_timedelta64(1)
t2 = patch.select(time=(t1, t2))
new_time1 # this can be accomplished more simply using the relative keyword
= patch.select(time=(1, -1), relative=True)
new_time2 # filter 1 second from start time to 3 seconds from start time
= patch.select(time=(1, 3), relative=True)
new_time3 # filter 6 second from end time to 1 second from end time
= patch.select(time=(-6, -1), relative=True)
new_time4 # Select first 10 distance indices
= patch.select(distance=(..., 10), samples=True)
new_distance1 # Select last time row/column
= patch.select(time=-1, samples=True)
new_distance2 # only include certain rows/columns based on a boolean array.
= patch.get_array("time")
time = patch.select(time=time>time[2])
new_time_5 # Select only specific values along a dimension
= patch.get_array("distance")
distance = patch.select(distace=distance[1::2]) new_distance_3
select
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 Slice or a tuple of (min, max) for that dimension. None
and … both indicate open intervals. - 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.
Parameters
Parameter | Description |
---|---|
patch | The patch object. |
copy |
If True, copy the resulting data. This is needed so the old array can get gc’ed and memory freed. |
relative |
If True, select ranges are relative to the start of coordinate, if possitive, 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
Note
- It is important to remember select will not change the order of the patch, only fiter values. If the order of the patch should change, or multiple rows/columns need to be repeated, See
Patch.order
.