Loading events in EGI/MFF files

Hello,

I cannot seem to be able to get MNE to correctly parse the event codes that are stored in my EGI/MFF files. When I try to retrieve events with mne.find_events(raw, stim_channel='STI 014'), the original event codes seem to be overwritten and replaced by a sequence of numbers (in my case, from 1 to 9, as I have 9 event codes). This makes it impossible to be sure which number correspond to which original event code/condition.

During recording, we made sure that the stimulus being presented and the corresponding event code were sent to NetStation and recorded in the recording files. Proof of that comes from the fact that, when importing the very same recording in the .set format, EEGlab annotations do include event code, even description and word.

Is there something I am missing about the MFF import function and/or event acquisition function? Thanks!

you have annotations or a trigger channel in your data? if it’s annotations look at raw.annotations attribute

and the mne.events_from_annotations — MNE 0.22.0 documentation function

Alex

Yeah, it’s weird – the MFF files have events from a trigger channel, but no annotations. The EEGlab files have annotations, but no trigger channel.

This is difficult to track down remotely. If you can, I’d appreciate if you shared an example file with me (privately) so I can have a look. My email address is richard.hoechenberger@gmail.com

1 Like

I just sent it to your gmail address through Google Drive! Have a nice weekend!

Ok it seems all is working as intended, just the documentation is lacking some info. The original trigger codes are in fact preserved when loading the MFF data, and the mapping to the new, arbitrary event IDs is stored in Raw.event_id:

import mne

infile = './Petrosino_01_20170417_011527.mff'
raw = mne.io.read_raw(infile)

# The original trigger code <> MNE event ID mapping is stored in raw.event_id
print(raw.event_id)

# Visualize events
events = mne.find_events(raw)
mne.viz.plot_events(events=events, sfreq=raw.info['sfreq'],
                    event_id=raw.event_id)

Produces:

{'500': 1, '100': 2, '50': 3, '10': 4, '200': 5, '888': 6, '20': 7, '30': 8, '88': 9}

egimff

1 Like

ok, cool – thanks!!

Hi richard!
thanks for the clarification. i just came into the same problem, and it was solved thanks to your tips. however, i am wondering in which way i can map the original event codes (in your case they are: 500, 100, 50, 10,…) to the event_id(i.e. 1,2,3,4…), so that i can directly working with events with the original event codes rather than the other one

thanks!!!

Hello @jian and welcome to the forum!

I don’t think changing the event codes is really necessary – whenever you need to use the new codes that MNE assigned, you could just do

raw.event_id['orig_code']

where orig_code is the original event code generated during recording (note that it needs to go in quotation marks, as MNE treats it as a string!). I think this is the most convenient way to allow you to work with the original codes, and less error prone than trying to change the events array.

Best wishes,
Richard

HEY Richard. thanks for the quick response!!! this clarifies a lot. and i am learning more about the MNE by watching the recorded videos of yours.
it seems that for the BDF data format, the MNE finds event, just as the original codes, it outputs exactly the original codes, for example, we set one mark called ‘201’ while recording eeg, if we use find_events function in MNE, it outputs 201, there would not be any re-coding. however, for mff data format, it will re-assign an event id to the original codes. is it because the data format? or what?
also, i noticed that for the EGI system recorded data, there stored raw.event_id, but not the data recored by other system, at least not by Biosemi, as far as i know. the MNE tutorial refers to the mne.io.read_raw_egi, it says " The event_id assignment equals np.arange(n_events) + 1", so i am wondering why.

many thanks!!!

best regards!!
Jian