cut

method of dascore.core.spool.Spool source

cut(
    self ,
    annotations: AnnotationSet ,
    **pads ,
)-> ‘Self’

Return one lazy patch per feature of an annotation set.

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

Each feature, lone rows included, is cut to its bounds (see AnnotationSet.bounds) and merged across source patches along every dimension, as chunk merges, so a gap still leaves several patches. A feature skips any patch lacking a dimension it bounds. Selection includes both ends, so the sample at a range’s (half-open) maximum is kept; an empty range gives nothing. A feature spanning a dimension keeps the spool’s full extent along it, one holding no samples gives nothing, and overlapping features duplicate data. Nothing is loaded.

Each output states feature_id (blank for a lone row) and annotation (a lone row’s index label, blank for a feature), as attrs and as get_contents columns, which join back to the set. Their envelopes are the samples kept, not the window asked for.

Parameters

Parameter Description
annotations The set to cut by.
**pads 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 pandas as pd
import dascore as dc
spool = dc.get_example_spool()
start = spool.get_contents()["time_min"].min()
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