import dascore as dc
# get an example patch which has unevenly sampled coords time, distance
patch = dc.get_example_patch("wacky_dim_coords_patch")
# snap time dimension
time_snap = patch.snap_coords("time")
# snap the distance dimension
dist_snap = patch.snap_coords("distance")
# put time on the grid of its smallest spacing, refusing moves over half a step
import numpy as np
time = patch.get_coord("time")
step = np.diff(time.values).min()
grid_snap = patch.snap_coords("time", step=step, max_shift=0.5)snap_coords
snap_coords(
self ,
*coords ,
reverse: bool = False,
step = None,
max_shift = None,
)-> ‘Self’
Snap coordinates to evenly spaced samples.
Sorts each specified coordinate, then replaces its labels with evenly spaced values between its endpoints in the selected sort direction. Data remain unchanged after sorting, so snapping can shift labels: a label moved more than one step warns, since a gap is being spread (use fill_gaps to keep it). Use interpolate when linear interpolation is preferable.
Parameters
| Parameter | Description |
|---|---|
| *coords | Dimensions to snap. By default, snap every dimensional coordinate. |
| reverse | If True, reverse the sorting of the coordinates. |
| step |
If given, move each label to the nearest position of this step’s grid through the first label instead, so labels skipping positions become segments (past dascore.config.max_index_runs, one list withno step, with a warning). Time steps may be given in seconds. |
| max_shift |
If given, raise rather than move any label further than this many steps. |