Skip to content

annotations

Reading the annotations of an EDF+ recording.

EDF+ keeps annotations in "EDF Annotations" signals inside the data records, as Time-stamped Annotation Lists (TALs): +onset<0x15>duration<0x14>text<0x14><0x00>. Annotation text is mapped onto the platform's event labels; text that matches none is kept as it was written.

EDF_ANNOTATIONS_LABEL = 'EDF Annotations' module-attribute

The label EDF+ gives a signal that holds annotations rather than samples.

MAX_ANNOTATION_SECONDS = 30 * 24 * 3600 module-attribute

Annotations per second of recording after which parsing stops; at least 100 are always read.

SeekableReadable

Bases: Protocol

A file or stream that can be read and repositioned.

read(size)

Read up to size bytes.

seek(offset)

Move to offset bytes from the start.

tell()

Return the current position.

parse_edf_annotations(readable, n_signals, n_records, record_duration_seconds, samples_per_record, annotation_signal_indices)

Read the annotations of an EDF+ recording's data records.

Only the annotation signals are read: the reader seeks past every other signal. Parsing stops once :data:MAX_ANNOTATION_DENSITY annotations per second of recording have been read, and never before 100.

Parameters:

Name Type Description Default
readable SeekableReadable

The recording, positioned at the start of its data records.

required
n_signals int

The number of signals, annotation signals included.

required
n_records int

The number of data records.

required
record_duration_seconds float

The duration of one data record.

required
samples_per_record list[int]

Each signal's samples per data record.

required
annotation_signal_indices list[int]

The indices of the annotation signals.

required

Returns:

Type Description
list[tuple[int, int, str, str | None]]

(start_ms, end_ms, label, original_text) for every annotation whose

list[tuple[int, int, str, str | None]]

onset is at least 0 and at most :data:MAX_ANNOTATION_SECONDS, with

list[tuple[int, int, str, str | None]]

its duration capped at the same. label is the matching event label, or

list[tuple[int, int, str, str | None]]

"Unknown"; original_text is the text as written when nothing

list[tuple[int, int, str, str | None]]

matched, else None.