Importing brainstorm events into MNE

Dear MNE team,

I have written some code to perform source localization on a epilepsy child that has simultaneous MEG and HD-EEG recording with triggers sent to both devices. For the analysis, I need to detect the interictal spikes in these recordings so I use brainstorm to do that. I find the times where there is a spike and I merge them in a group. My question is that how can I bring those timepoints into MNE to use it? I thought about exporting that as brainstorm events(.mat) and then importing it into MNE but I am not sure if it’ll work. Any guidance will be very helpful. Thank you so much!

Regards,

It’s probably easiest if you export your events to simple text files, see Working with events — MNE 0.22.0 documentation.

the read_annotations function

https://mne.tools/stable/generated/mne.read_annotations.html?highlight=read_annotations#mne.read_annotations

can read brainstorm annotations. Just docstring is not up to date.

see:

PR welcome to update the docstring

let us know if this works

Alex

Alex

@cbrnr @agramfort I will try them but I need to figure out how to set the subject directory. I obtained an MRI reconstruction with freesurfer but I can not figure out how to set the directory. I checked MNE website and it says mne.set_config but I did not understand. If you could also help me solve this, I will be very grateful.

Regards,

Hi @ometett, this seems like a quite different issue then (which ideally you should post into a new thread :slight_smile:) You won’t need to use the FreeSurfer files for reading your events.

1 Like

Dear all (especially @ometett),

I do this on a regular basis in a clinical source localization pipeline I am working on.
It took some tinkering and some not so pretty workarounds, but what I am doing is basically to export an event-file (as .csv) with all spikes/events of interest, change a few things and then add events via add_events method.

The first event in the file needs to be some pseudo-event, as, for some reason, the first event sometimes gets messed up. I have absolutely no idea why this happens, but with this pseudo-event which is later-on ignored for the analysis (and even the import) anyway it didn’t happen again.
So in practice I mark 3 or 4 events named “AAA” in the first epoch of the MEG-file.

From this point onwards it’s pretty straight forward:
In order to be correctly imported, events need a label -> sklearns LabelEncoder does that for you.
Label names are also available in the file - they can be extracted, as you might need them later in order to know which spike group you are looking at.
What follows are some type conversions and then you just add the events via add_events method.

I am right now re-writing the pipeline I use in order to generate a BIDS compatible dataset in the process and change some things I didn’t like with the former solution. Even though it’s far from complete, merging of events should already work.

I just made the repo public, have a look at:
https://github.com/RuKrei/SourceLoc.git

The files src/01_create_DS_and_folders.py and utils/utils.py contain what you are looking for.

Hope that helps.

3 Likes

Hi @ometett. I have come across the same problem. I was wondering if you could share how you got MNE to read brainstorm events. The MNE code would be of great help.