SnapCoords

class of dascore.proc.coords
inherits from: dascore.proc.coords._Reorder, PatchProcessor, DascoreBaseModel, pydantic.main.BaseModel
source

SnapCoords(
    *args ,
    coords: tuple[str, …] = (),
    reverse: bool = False,
    step: Any = None,
    max_shift: float | None[float, None] = None,
)-> None

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 with
no 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.

Examples

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)

Methods

Name Description
check Refuse a patch which does not carry what the operation needs.
chunk_contract Return what a chunk of the output needs of the input, or None.
get_metadata Return the sorted coordinates and the indexing they imply.
halo Return how far along an axis the kernel reads to fill a sample.
kernel Return the data reordered the way the coordinates were.
model_copy Copy the model, dropping cached values the update invalidates.
new Create new instance with some attributed updated.
snap_coords Snap coordinates to evenly spaced samples.
reconcile Return metadata or a patch holding the final data; default as is.
run Run the operation: check, get_metadata, kernel, reconcile, record.