Let users run find_bads_muscle also when no sensor positions are available#12862
Let users run find_bads_muscle also when no sensor positions are available#12862larsoner merged 9 commits intomne-tools:mainfrom
find_bads_muscle also when no sensor positions are available#12862Conversation
mne/preprocessing/ica.py
Outdated
| try: | ||
| # compute metric #2: distance from the vertex of focus |
There was a problem hiding this comment.
Maybe instead of a big try/except block, you could reduce the diff by a check for existence of channel positions and if it's absent exit early?
slope_score = ...
if not has_dig(...):
warn(...)
return slope_score
[...]
returnOtherwise, +1 to add this.
There was a problem hiding this comment.
thanks for the feedback
Yes, that'd be a cleaner solution, and maybe wrap the scoring (currently after the try/except) into a small private function that then gets called either early (after 1st criterion is computed), or later (after all criteria are computed).
are you aware of a simple check whether an object has sensor positions?
There was a problem hiding this comment.
inst.get_montage() is None or inst.info["dig"] is None should do it? I remember other utilities exist, but I can't remember where at the moment..
There was a problem hiding this comment.
Found it: mne.utils.check.py: _check_ch_locs(info, picks=None, ch_type=None)
|
@mscheltienne would you mind reviewing this? |
|
I'm away until Monday, I can review then if it's still needed. |
for more information, see https://pre-commit.ci
Co-authored-by: Clemens Brunner <clemens.brunner@gmail.com>
for more information, see https://pre-commit.ci
larsoner
left a comment
There was a problem hiding this comment.
Otherwise looks good -- FYI I merged in main to get the CI feedback but feel free to push over it
mne/preprocessing/ica.py
Outdated
| logger.warning( | ||
| "No sensor positions found. Scores for bad muscle components are only " | ||
| "based on the 'slope' criterion." | ||
| ) |
There was a problem hiding this comment.
For this you should use warn from mne.utils, it does some nice stuff based on the logging level etc.
mne/preprocessing/tests/test_ica.py
Outdated
| with catch_logging() as log: | ||
| labels, scores = ica.find_bads_muscle(raw, threshold=0.35) | ||
| log = log.getvalue() | ||
| assert "based on the 'slope' criterion" in log |
There was a problem hiding this comment.
Then
| with catch_logging() as log: | |
| labels, scores = ica.find_bads_muscle(raw, threshold=0.35) | |
| log = log.getvalue() | |
| assert "based on the 'slope' criterion" in log | |
| with pytest.warns(RuntimeWarning, match="based on the 'slope'"): | |
| labels, scores = ica.find_bads_muscle(raw, threshold=0.35) |
|
Pushed my suggested fix and marked for merge-when-green, thanks in advance @sappelhoff ! |
This is an "issue as PR", that also contains some commits from #12860 that can be ignored.
The main point that I would like to discuss is, that
find_bads_muscleis using three criteria to flag components as bad by muscle activity. However, two of these criteria require sensor positions to work.I have a dataset without sensor positions available (and no option to add standard positions), and I would still like to run this function, using only the first criterion to flag channels.
In the diff below, I show that this is easily accomplished in principle. In practice I would much rather have some guidance in what components may be muscle related, than none at all.
What are your thoughts on this?