Hello,
I am trying to do artifact detection on EEG data measured during an fMRI session.
I am looking for some pre-existing tool/package – preferably python-based – able to detect these kind of artifacts (e.g. pulse, gradient artifacts).
There are some preliminary ECG/EKG artifact detection tools in MNE Python. It looks like someone has taken some steps of implementing what you’re asking for in a separate tool that integrates with MNE as well: https://github.com/russellu/eegfmripy.
If that doesn’t seem appealing, it is fairly straightforward to remove gradient artifacts by doing template subtraction and the QRS detect and OBS method for BCG reduction is also fairly well documented if you wanted to write your own.
@sfc@pmolfese We’re no longer working on the Python version of that code for a number of reasons. There are Python-specific and MNE-specific issues that are difficult (if not impossible) to resolve and cause lots of intermittent failures. We found that Python is just a bad choice of programming language for this type of cleaning.
Thanks for the updated link and codebase. I’m curious what the holdups were regarding Python or MNE codebases that prevented you from developing on them.
The biggest issue we had was when we tried to do gradient artifact correction. We use cross correlations to determine where all the artifacts occur and then remove them. The issue though is that in Python/MNE, for some reason we have yet to determine, the gradients changed drastically over time and this breaks the cross-correlation algorithm because the artifacts become very different from each other over time. We accept some changes in the gradient values, but it got so bad that a correlation threshold of 0.3 needed to be used, and this resulted in very poor cleaning.
In Matlab (using EEGLAB), we have never seen this massive change in values. I had some images of this change in gradient values but I don’t know where they are, if I find them I’ll post them. I’m not entirely sure is this issue is related to Python or MNE or a combination of both. My first guess is that the data representation in MNE/Python is the problem and it causes these large differences to pop out.
EDIT: Another thing to note is that this is an intermittent failure, making it even more difficult to debug. Some data sets had this issue while others did not (in Matlab those data sets were always fine) and they were also all recorded in the same way, with the same cap, same fMRI sequence, etc…
This is definitely worth an issue on GitHub. I suppose first I’d ask if you can pull the numpy array of the EEG data and work your cross-correlations on that. I suspect that would work just fine as my template code for doing something similar works on the numpy array and not on the MNE object (currently). I’d love to try and find a way to make this work if you’re willing to point me to some of the code issues. Happy to PM about it too.
Hi Pmolfese, my name is Russell Butler, i worked with gmierz to create eegfmripy.
we basically moved away from python for two reasons
we simply had more experience with matlab/eeglab than python/mne, so the code was simpler and more robust in python, and we already had a lot of preexisting code
some of the numpy functions seemed slow, but we may have been mis-using them.
eegfmripy isn’t maintained much anymore (i have since gone on from my phd, and gmierz is almost done as well) but if there was some demand, we could do some work to adapt it to a dataset you are interested in.
right now, its mainly tailored to datasets from our center, but it shouldn’t take long to get working on some of your data, if you could send us a sample dataset.