Refactor EGIMFF to use mffpy(GSoC)

Hello,
I’m a final year computer science student and have tried to contribute to MNE for GSoC before but haven’t been able to. I’m interested in applying for this years GSoC and want to implement the project of : Refactor EGIMFF to use mffpy.
I need some guidance to get started and have some questions :

-Does this project include modifying mne.io.read_raw_egi or creating something else entirely?

-What are the features that are needed to be implemented with mffpy and how to get started

Thanks in advance

I can only speak to my preference:

  1. Add a function offshoot of read_raw_egi that uses mffpy (while still allowing old pipelines to use the current function)
  2. mffpy’s main use cases are reading/writing 3 types of EEG data: raw/continuous, epoch/segmented, averaged

One thing holding back some of our code for doing simultaneous EEG-fMRI in MNE is how mff is currently converting event times to integers / floats instead of timestamps. That makes doing exact samples to a time challenging since rounding can push a sample up or down a datapoint, which causes some annoyance in doing template subtraction. So if you do implement mffpy’s reading functions it would be handy to represent time as a time, and not an int/float :slight_smile:

You can see how we’ve attempted to get around this in code: GitHub - nimh-sfim/gradient_remover: Gradient Removal with templates

Good luck! I hope you get the GSoC and would love your contributions!

2 Likes

Thank you so much! But I do have a couple more questions :sweat_smile: :sweat_smile:.
Can mffpy be used to read .egi type files as well?
also as i understand mne.read_evokeds_mff is already using mffpy to read averaged MFF files, can this be modified to an object that can be plotted etc and can this be integrated with the function offshoot?
can the writing or/and exporting features of mffpy be added to mne? and is there any way that you can share some examples of mff files where event times are getting converted to integers or just any other examples in general as I have found it kind of difficult to find .mff/.egi files on openneuro or anywhere else.

Hello,

Yes, the mffpy methods are implemented with reading evoked/averaged data and you can also write evoked/averaged data. You could wrap these methods if you wanted to extend them slightly or just start with an mffpy reader for raw data and (optionally) segmented/epoched data (if you wanted to fully replace the existing code capabilities).

For reading events the following lines of code should work:

raw = mne.io.read_raw_egi('FID_S03_run2_raw.mff')
events = mne.find_events(raw)
print(events)

The events array gives the onsets as sample numbers. But if you read the times from the MFF events.XML you’ll likely find that the samples get rounded. Perhaps there’s a useful way of also coding the events by code in the MFF file or doing something with annotations.

Sharing an anonymized subject for a tones study (1khz, 2khz) that’s a little wobbly because it was collected in an MR-environment:
raw
seg / epoched
ave / evoked

https://drive.google.com/drive/folders/1Uf9JPGF_E_bCbV3UlRwPE3VhCDoCGEme?usp=sharing

1 Like

Hello!
Thanks again for taking the time.
So, Im assuming that this is due to this piece of code where np.fix is used to round the samples to the nearest integer.


Can this be fixed by changing this into a datatime format? because as I understand these values have to be plugged back into egi_events and new_trigger. Can the formats of egi_events or new_trigger be changed as well?
mffpy does process events in datatime format I think:

I also noticed that much of the code of reading into the xml files in the original code can be replaced with mffpy methods with a bit of extra coding like:


with

This can clean out the code and might be able replace and/or remove some of the functions in the associated general.py file but im still having difficulty with mffpy because Ive not been able to access the documentation for mffpy using pydoc. Im not sure “pydocmd build” works anymore, Ive been using the command “pydoc-markdown --build pydocmd.yml”, but it breaks:

Ive already raised an issue with the mffpy github page, but if you have already build the markdown file, If possible, please do share the documentation.

Apologies this slipped through the cracks! I’ve also had issues getting the mffpy docs to build. You could try to reach out directly to the company: https://belco.tech

Yes my inclination would be to use the mffpy date-time objects as well as lean on the mffpy methods as much as possible when bringing the data into MNE.