Skip to content

EventsFromAnnotations

Bases: BaseClass

Class for extracting events from annotations in MNE Raw objects, and adding them to the stim channel. If the stim channel does not exist, it will be created.

MNE-function used: mne.events_from_annotations

Parameters:

Name Type Description Default
raw Raw

Input Raw object containing annotations.

required
event_id dict | callable() | None | auto

Can be: dict: map descriptions (keys) to integer event codes (values). Only the descriptions present will be mapped, others will be ignored. callable: must take a string input and return an integer event code, or return None to ignore the event. None: Map descriptions to unique integer values based on their sorted order. ‘auto’ (default): prefer a raw-format-specific parser: Brainvision: map stimulus events to their integer part; response events to integer part + 1000; optic events to integer part + 2000; ‘SyncStatus/Sync On’ to 99998; ‘New Segment/’ to 99999; all others like None with an offset of 10000. Other raw formats: Behaves like None.

'auto'
regex str

Regular expression to extract event IDs from annotation descriptions. If regex is provided, event_id will be ignored and event IDs will be extracted using the regex pattern. The regex should contain a capturing group that extracts only the desired event ID.

None
stim_channel str

If the stim channel does not exist, give a name for the new stim channel to be created. If the stim channel already exists, this parameter is ignored.

'STI 014'
delete_annotations bool

If True, deletes all annotations after extracting events.

False
silent bool

If True, suppresses print statements during processing.

False

Attributes:

Name Type Description
processed Raw

Output data with events added to the stim channel.

Example settings for config file

Example settings in correct format for the config file.

EventsFromAnnotations:
  _biopap_module: <class 'biopap.modules.events_from_annotations.EventsFromAnnotations'>
  regex:   r'(?<=(^RS232 Trigger: ))(\d+)'
The regular expression should match an integer as the first group (code uses re.search). For example, this regex:

r'(?<=(^RS232 Trigger: ))(\d+)'

matches the number 23 in the string:

RS232 Trigger: 23('\u0017')

Alternatively, you can provide a dictionary containing annotation/event pairs, so for instance:

{ "RS232 Trigger: 31('\u001f')": 31, "RS232 Trigger: 32(' ')": 32, "RS232 Trigger: 34('\"')": 34, "RS232 Trigger: 35('#')": 35 } To create a JSON-file with a template dictionary, run the create_template_annotations_dict() function from the helpers' module. This function will read all annotations from the input file and create a dictionary from the, guessing the corresponding event ID's from the annotations (or add?when it doesn't know). Edit the file to fit your use case, read it back into a dictionary, and runEventsFromAnnotationswith assigining the dictionary to theevent_id` parameter.