-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
MRG+1: ENH: functionality for doing ICA on MEG reference channels #5807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Naive question, why do all of this rather than simply doing a joint decomposition of the reference and non-reference channels together, and reject components that are most clearly in the reference channels? I know mechanically in MNE Admittedly I don't know why we don't allow ref channels in ICA decompositions in the first place... |
|
I've just tried this approach, and it also works well. The one advantage to doing it the original way is having a unified algorithmic approach: you're essentially doing the same thing as with automatic EOG- or EKG-related component removal; the only difference is instead of using the EOG or EKG channels as your ground truth, you're using the reference channel components. With the approach you've suggested, you'll ultimately need to also decide an algorithm which determines "most clearly in the reference channels," which probably wouldn't be so challenging, but it would also be different than the established tools already built into MNE. |
|
Apologies if this is slightly OT, but this reminds me of the following two papers :
If this seems relevant, I coded those in python a while back (but then stopped working with MEG so I never took the time to fully test it on real data). |
Codecov Report
@@ Coverage Diff @@
## master #5807 +/- ##
==========================================
- Coverage 88.69% 88.67% -0.02%
==========================================
Files 396 396
Lines 71870 71905 +35
Branches 12071 12081 +10
==========================================
+ Hits 63744 63762 +18
- Misses 5198 5213 +15
- Partials 2928 2930 +2 |
|
It should be working now. 1) ICA fitting accepts reference channels 2) any attempt to visualise a topography of components derived only from reference channels will simply return and: I've found that this approach is good not only for removing intermittent environmental noise, but to my astonishment, EKG components are in nearly every case detected, and once or twice I've even picked up EOG components. |
|
@jshanna100 can you look into why Travis is unhappy? It's better to review after CIs are green. But what you say sounds useful! |
|
The Travis problems seem to come from the fact that the ICA tests use a threshold of .9 of the variance. Now that reference channels are allowed, it attempts an ICA on those, and can find no more than one component under that threshold, which results in an error. |
|
I see you have not modified How about:
|
mne/preprocessing/ica.py
Outdated
| scores = scores[0] | ||
| self.labels_['ref'] = list(ref_idx) | ||
|
|
||
| return self.labels_['ref'], scores |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much of this code is shared with find_bads_eog / find_bads_ecg? If it's 95%+, then we should refactor so that this and those functions each just call a return self._find_bads_type(...) to reduce code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's maybe about 75% between eog and ref. ecg is fairly different. I've left them as is, for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jshanna100 you should then refactor to have a private function eg _find_bads_ch_type that takes the channel type you want to correlate with and make find_bads_ecg and find_bads_ref_meg use this private function. This would avoid the code duplication.
also you can run:
make pep
from the mne-python folder. It will show you the code formatting errors that prevent travisci to be green.
thanks a lot for your efforts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this is done, I think. It works on some of my own data with reference channels. I've run some quick tests on the MNE sample data, and as far as I can tell, the ECG and EOG functions also seem to work as they should.
|
Sorry, "make pep," passed on my system, but now the ica_test.py is broken. Will sort out. Please bear with me; this is my first time sorting out a PR here... |
|
CircleCI: You can't reference private functions in public docstrings (users should not use or think about them) |
larsoner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refactoring looks nice!
|
Alright, good! Got a deadline this week, so will get to all this first half of the next one. |
|
ok cool
|
|
I'm having a hard time figuring out what the problem with travis is now. All I changed from last commit was some commented lines. Does this have to do with something else, somehow? |
|
Just ensure sure you did not add errors to the files you've edited, #5892 will fix the flake problems with the others. |
|
If you rebase, it should fix the CircleCI build problem (I think) |
…partially visualising these components
new function find_bads_ref identifies bad components that correlate with reference channel derived components
|
Alright, that appears to be sorted now. I don't know how to interpret these codecov errors. Are they a problem? |
|
codecov can be a bit unreliable sometimes, it's probably okay. I see a few more minor things to change, okay for me to push a commit to your branch? |
|
Yep, go for it. |
|
Is there anything left to be done on this? |
larsoner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM +1 for merge
@agramfort feel free to merge if you're happy
|
thx @jshanna100 |
I recently had some success removing a pattern of intermittent external noise using ICA decompositions of the reference channel array in a 4D MEG system. The procedure went as follows:
MNE as it currently stands does not allow ICA decomposition of reference channels. The suggested changes are a first step in providing this functionality. They allow the decomposition itself, as well as permitting visualisation functions like e.g. preprocessing.ICA.plot_properties. The topographies are nonsense, but plotting functions at least now do not fail entirely, allowing inspection of other types of visualisations.
One possible substitute for the topographies might be quiver plots, where the arrows orientations are determined by the orientations of the reference channels, projected onto 2D space. I could also put together a proper component identifier function that carries out steps 3 and 4.