mne-tools / mne-bids-pipeline

Automatically process entire electrophysiological datasets using MNE-Python.
https://mne.tools/mne-bids-pipeline/
BSD 3-Clause "New" or "Revised" License
133 stars 66 forks source link

EyeTracking / New Step? #949

Open behinger opened 1 month ago

behinger commented 1 month ago

Hi! we have ET/EEG combined data and we would love to use mne-bids-pipeline. For this we would want to follow this mne-tutorial which uses read_raw_eyelink + some synchronisation steps.

We couldnt figure out if there is a modular "add_step" guide somewhere, that allows to run custom code (which would be super helpful btw!). We found that the ICLabel PR #812 works by modifying the code of the preproc-ic-step. O.c. we could "hack" a solution by hijacking any other step to synchronize the EEG/ET data - but if there is an "official" way to include new steps (maybe user-defined, maybe for PRs) we would appreciate some pointers :-)

Apologies if this is documented somewhere and we missed it. We'd be happy to contribute such a step to the pipeline, even though we acknowledge it is a bit on the rare side to need it ;-)

Cheers, @jschepers @behinger

welcome[bot] commented 1 month ago

Hello! 👋 Thanks for opening your first issue here! ❤️ We will try to get back to you soon. 🚴🏽‍♂️

drammock commented 1 month ago

adding custom steps has definitely come up before (e.g. in #303) and IIRC it's status is planned-but-not-yet-implemented. @larsoner or @hoechenberger will probably know better how far off we are from supporting it... But I think for now it boils down to "run the pipeline up to the step just before your custom code, run your custom code on the intermediate files, then resume the pipeline with the output of your custom code". Obviously some care is needed with filenames/paths, etc.

That said: support for combined EEG / ET analysis in an "official" way seems like a nice feature (maybe rare, but certainly not one-off). So another option is to incorporate what you come up with into the package itself.

larsoner commented 1 month ago

Hmm... aligning the EEG and eye tracking data is probably going to be experiment-dependent, involving the alignment/registration/fixing of shared triggers or something similar. If there's any way you can do this before the BIDS step -- and for example concatenate the aligned data into a single FIF -- that would make use in MNE-BIDS-Pipeline easier. Maybe it's not really in the spirit of BIDS... but I did it recently for MEG+EEG data recorded simultaneously on different systems and it wasn't too bad.

As far as custom steps go, can you look at https://github.com/mne-tools/mne-bids-pipeline/issues/924#issuecomment-2065293402 and see if you think there's some way you could leverage such an API to do what you need?

behinger commented 1 month ago

yes, in principle the alignment could be made before and the _events.tsv adjusted manually, Nevertheless, it would be nice to have a specific step for this. There are MNE functions to help with the synchronisation via:

mne.preprocessing.realign_raw(
    raw_et, raw_eeg, [et_flash_times], [eeg_flash_times], verbose="error"
)

What MNE practically does is filter the ET-annotations/events and the EEG-annotation/events for the common trigger, and regress that times (I assume ;-)). If the events can be specified in the config, then this should be relatively general.

The callback/hook you mention in 924 would work indeed. I think related but a different issue, I will investigate how to "temporarily" filter something for ICA and then apply the weights to the original data.

For now, what I will do is to define my own step or manually hook it into an existing step in the library. This then later could be converted to a manual hook, or as a PR however you wish.