annotations

function of dascore.core.annotation_loader source

annotations(
    source: dascore.core.annotations.AnnotationSet | str | os.PathLike | Any[AnnotationSet, str, PathLike, Any] = None,
    dims: collections.abc.Sequence[collections.abc.Sequence[str], None] = None,
    **kwargs ,
)-> ‘AnnotationSet’

Load annotations from whatever holds them.

The one door every source goes through, as dascore.spool is for patches: a set comes back from a set, a directory, a table on disk, or anything a dataframe can be built from.

Parameters

Parameter Description
source An AnnotationSet, a dataframe of one row per annotation, or a path
to a CSV table, a set directory, a directory of set directories, or a
directory of data carrying either under .annotations.
dims The patch dimensions the annotations are stated in. Required unless
the source states them itself – in its attributes, or in a
# dims: distance, time line above its table. A source which
states them takes them again only if the two agree.
**kwargs Passed to AnnotationSet.
A source already holding what one states – a set, or a directory
holding its own attributes and vertices – refuses it rather than
dropping it.

Examples

import pandas as pd
import dascore as dc
frame = pd.DataFrame({"group": ["event"], "distance": [10.0]})
picks = dc.annotations(frame, dims=("distance",))
len(picks)
dc.annotations(picks) is picks
import tempfile
from pathlib import Path
with tempfile.TemporaryDirectory() as folder:
    root = Path(folder) / "sets"
    _ = picks.io.save(root / "hand")
    _ = picks.io.save(root / "phasenet")
    together = dc.annotations(root)
len(together), together[0].set, sorted(together.attrs.sets)
with tempfile.TemporaryDirectory() as folder:
    data = Path(folder)
    _ = picks.io.save(data / ".annotations")
    carried = dc.annotations(data)
carried == picks
True