Skip to main content

FiffAnnotation

Namespace: FIFFLIB  ·  Library: FIFF Library

#include <fiff/fiff_annotations.h>

struct FIFFLIB::FiffAnnotation

One FIFF / MNE annotation: onset (s), duration (s) and description string.

Field-for-field counterpart of one row of mne.Annotations in MNE-Python. Onset is given in seconds relative to the recording start (matching the first_samp / sfreq convention of FiffRawData).

src/examples/ex_fiff_api/main.cpp
MatrixXi firstThree = events.events.topRows(3);
FiffAnnotations annotations = annotationsFromEvents(firstThree, info.sfreq, {{1, "auditory/left"}, {2, "auditory/right"}}, raw.first_samp);
const FiffAnnotation blink{0.5, 1.0, "BAD_blink", {}, {}, {}}; // onset s, duration s, description, channels, ...
annotations.append(blink);
FiffAnnotations::write(tmp.filePath("annot.csv"), annotations);
const FiffAnnotations annotationsBack = FiffAnnotations::read(tmp.filePath("annot.csv"));
const MatrixXi eventsAgain = eventsFromAnnotations(annotationsBack.select("auditory"), info.sfreq, {{"auditory/left", 1}, {"auditory/right", 2}}, raw.first_samp);

Example​

Used in examples​

ex_fiff_api​

FIFF library: measurement info, channels, digitizer, transforms, projectors, covariance, events,.

src/examples/ex_fiff_api/main.cpp, line 186
MatrixXi firstThree = events.events.topRows(3);
FiffAnnotations annotations = annotationsFromEvents(firstThree, info.sfreq, {{1, "auditory/left"}, {2, "auditory/right"}}, raw.first_samp);
const FiffAnnotation blink{0.5, 1.0, "BAD_blink", {}, {}, {}}; // onset s, duration s, description, channels, ...
annotations.append(blink);
FiffAnnotations::write(tmp.filePath("annot.csv"), annotations);
const FiffAnnotations annotationsBack = FiffAnnotations::read(tmp.filePath("annot.csv"));
const MatrixXi eventsAgain = eventsFromAnnotations(annotationsBack.select("auditory"), info.sfreq, {{"auditory/left", 1}, {"auditory/right", 2}}, raw.first_samp);
// Event 13988 (code 2) is (13988 - 12900) / 300.307 s = 3.6230 s after the first sample; code 3 has no description and stays "3"; the CSV keeps onsets to well within half a sample
ok &= expect(annotationsBack.size() == 4 && std::fabs(annotationsBack.select("auditory/right").toVector()[0].onset - (13988 - 12900) / info.sfreq) < 0.5 / info.sfreq && eventsAgain.rows() == 2 && eventsAgain(0, 0) == 13988 && eventsAgain(1, 0) == 14385 && eventsAgain(1, 2) == 1 && annotationsBack.select("3").size() == 1,
"FiffAnnotations: events become onsets in seconds and back, with descriptions as codes");

Authors of this file​