clip_intervals

function of dascore.utils.intervals source

clip_intervals(
    items ,
    lo: float ,
    hi: float ,
    outer: float | None[float, None] = None,
    start_field: str = start_distance,
    end_field: str = end_distance,
)-> ‘list’

Clip interval items to [lo, hi), dropping those left with no coverage.

Point markers cover nothing but are not nothing: they survive when they fall inside the clip, or on its outermost included endpoint.

Parameters

Parameter Description
items Models whose start and end are held by start_field and
end_field, and which support pydantic’s model_copy.
lo The inclusive start of the clip.
hi The exclusive end of the clip.
outer The outermost value the clipped axis holds, if any. A point marker
sitting exactly there survives, since nothing beyond it can claim it.
start_field Name of the field holding each item’s interval start.
end_field Name of the field holding each item’s interval end.

Examples

from pydantic import BaseModel
from dascore.utils.intervals import clip_intervals
class Span(BaseModel):
    start_distance: float
    end_distance: float
clipped = clip_intervals([Span(start_distance=0, end_distance=10)], 2, 6)
clipped[0].start_distance, clipped[0].end_distance
(2, 6)