cut

method of dascore.core.spool.Spool source

cut(
    self ,
    annotations: dascore.core.annotations.AnnotationSet | None[AnnotationSet, None] = None,
    tolerance: float | pint.registry.Quantity | numpy.timedelta64 | None[float, Quantity, timedelta64, None] = None,
    max_shift: float | None[float, None] = None,
    conflict: Literal[‘drop’, ‘raise’, ‘keep_first’] = raise,
    **kwargs ,
)-> ‘Self’

Return one lazy patch per window, from explicit windows or annotations.

Experimental: this may change in any minor release without a deprecation period; see what experimental means.

Each window is cut from the sources it reaches and joined across them as chunk joins, along every dimension, so a gap leaves labelled fragments. Windows are either (n, 2) arrays (time=windows, in the forms Spool Chunking lists), or the features of an annotation set, lone rows included, cut to their bounds (see AnnotationSet.bounds). Bounds include both ends, so the sample at an annotation range’s (half-open) maximum is kept. Windows bound dimensions only (select also takes other coordinates). A window skips any patch lacking a dimension it bounds, one holding no samples gives nothing, overlapping windows duplicate data, and inside a window an earlier source’s samples are its own (rule 6). Unlike chunk’s windows, no window need be complete. Planning reads coordinates but no data arrays.

Each output states, as attrs and get_contents columns, its window (its row) or, cut by annotations, its feature_id (blank for a lone row) and annotation (a lone row’s index label, blank for a feature), which join back to the set. A cut replaces these labels wherever patches carry them, blanking the other kind’s. They are written to files like any attribute and differ between outputs, so rejoining outputs needs chunk(..., conflict="drop"). Envelopes are the samples kept, not the window asked for.

Parameters

Parameter Description
annotations The set to cut by; without it, keywords give the windows.
tolerance As for chunk, along each dimension a window bounds, for that
window; one with units, along those of its kind only.
max_shift As for chunk, along each dimension a window bounds, for that
window.
conflict As for chunk, for the sources each window joins.
**kwargs Without annotations, dim=windows: an (n, 2) array of
absolute bounds (a dimension named tolerance or max_shift
cannot take one). With them, dim=(before, after): offsets
added to a feature’s ends along dim which are stated values,
before (usually negative) to its minimum and after to its
maximum; range ends are kept. A feature at a single value needs
one. Time offsets are timedeltas, strings with units such as
“-1s”, or seconds.

Examples

import numpy as np
import pandas as pd
import dascore as dc
spool = dc.get_example_spool()
start = spool.get_contents()["time_min"].min()
second = np.timedelta64(1, "s")
# two windows, each joined across the files it spans
windows = np.array([[start, start + 9 * second], [start, start + second]])
cut = spool.cut(time=windows)
assert cut.get_contents()["window"].tolist() == [0, 1]
# or cut around the times an annotation set picks
frame = pd.DataFrame({"time": [start + pd.Timedelta("10s")]})
picks = dc.AnnotationSet(frame, dims=("distance", "time"))
cut = spool.cut(picks, time=("-1s", "3s"))
assert len(cut) == 1