get_gaps

method of dascore.core.spool.Spool source

get_gaps(
    self ,
    dim: str = time,
    tolerance: float | pint.registry.Quantity | numpy.timedelta64 | None[float, Quantity, timedelta64, None] = None,
    max_shift: float | None[float, None] = None,
    group: str | collections.abc.Sequence[str, collections.abc.Sequence[str], None] = None,
    on_missing_dim: Literal[‘raise’, ‘drop’] = drop,
)-> ‘pd.DataFrame’

Return a dataframe with one row per gap along a dimension.

Each row is a seam where chunk with the same arguments starts a new patch: the later patch does not start one step after the earlier one ends, give or take max_shift (nor within tolerance). A patch with holes enters a spool as its contiguous pieces, so its holes are gaps like any other.

Parameters

Parameter Description
dim The dimension to look for gaps along.
tolerance Off by default. A number joins seams up to that many steps
wide; a quantity or timedelta (eg 1 * s) joins seams up to
that width in the coordinate’s own units. Same meaning as
chunk’s tolerance.
max_shift How far, as a fraction of a step, a seam may be from one step
wide and still join; None means dascore.config.max_shift.
Same meaning as chunk’s max_shift.
group Attributes which separate patches into unrelated groups; a gap
is never reported between two groups. Defaults to the config
option patch_kind_attrs. Sampling rate and coordinate
structure split groups too, exactly as they do for chunk,
so one attribute value can span several groups. A value
nobody recorded is a value of its own, so a patch which never
stated the attribute is not grouped with one which did.
on_missing_dim What to do with patches lacking dim: “drop” (the default)
excludes them, “raise” refuses. Chunk defaults to “raise”
because it must produce those patches; a report need not.
Note

{dim}_min is the last sample before the gap and {dim}_max the first sample after it, so gap_size is their difference — one step wider than the missing extent. Subtract the magnitude of the returned {dim}_step for the extent itself; the step keeps the coordinate’s sign, which is negative for a descending one. missing counts the samples the gap is missing, on the earlier patch’s step (NaN where it has none): a seam 1.3 steps wide is a gap missing none.

group_id names the group each gap belongs to, and is the column to join against get_coverage.

Each boundary is measured against the furthest point reached so far, not the previous row. An overlapping patch continues from its first sample at least one step less max_shift past that point, so one on the earlier patch’s grid opens no gap, while one off it (by half a step, say) opens one there.

Patches whose step is unknown join where they overlap or touch, and across a seam only under a tolerance stated as a quantity or timedelta; without one, every such seam is a gap.

See Also

Spool.get_coverage

get_gap_edges finds the gaps in the values of a coordinate already loaded; this method reads only the index and never loads data.

Examples

import numpy as np
from dascore.examples import random_spool

spool = random_spool(time_gap=np.timedelta64(1, "s"), length=3)
gaps = spool.get_gaps()
assert len(gaps) == 2
# A contiguous spool has none.
assert random_spool().get_gaps().empty
# A seam 1.3 steps wide is a gap missing no sample, unless a
# tolerance spans it.
late = random_spool(time_gap=np.timedelta64(1_200_000, "ns"), length=2)
assert late.get_gaps()["missing"].tolist() == [0]
assert late.get_gaps(tolerance=1.5).empty