mne.annotations_from_events(events, sfreq, event_desc=None, first_samp=0, orig_time=None, verbose=None)[source]#

Convert an event array to an Annotations object.

eventsndarray, shape (n_events, 3)

The events.


Sampling frequency.

event_descdict | array_like | callable() | None

Events description. Can be:

  • dict: map integer event codes (keys) to descriptions (values). Only the descriptions present will be mapped, others will be ignored.

  • array-like: list, or 1d array of integers event codes to include. Only the event codes present will be mapped, others will be ignored. Event codes will be passed as string descriptions.

  • callable: must take a integer event code as input and return a string description or None to ignore it.

  • None: Use integer event codes as descriptions.


The first data sample (default=0). See docstring.

orig_timefloat | str | datetime | tuple of int | None

Determines the starting time of annotation acquisition. If None (default), starting time is determined from beginning of raw data acquisition. For details, see mne.Annotations() docstring.

verbosebool | str | int | None

Control verbosity of the logging output. If None, use the default verbosity level. See the logging documentation and mne.verbose() for details. Should only be passed as a keyword argument.

annotinstance of Annotations

The annotations.


Annotations returned by this function will all have zero (null) duration.

Creating events from annotations via the function mne.events_from_annotations takes in event mappings with key→value pairs as description→ID, whereas mne.annotations_from_events takes in event mappings with key→value pairs as ID→description. If you need to use these together, you can invert the mapping by doing:

event_desc = {v: k for k, v in event_id.items()}

Examples using mne.annotations_from_events#

Parsing events from raw data

Parsing events from raw data