confusing warning with applying projs
See original GitHub issueDescribe the bug
Using apply_proj
after marking bad channels should automatically do the right thing instead of raising a confusing warning.
Steps to reproduce
import os
import numpy as np
import mne
sample_data_folder = mne.datasets.sample.data_path()
sample_data_raw_file = os.path.join(sample_data_folder, 'MEG', 'sample',
'sample_audvis_filt-0-40_raw.fif')
raw = mne.io.read_raw_fif(sample_data_raw_file)
raw = raw.pick_types(meg='mag', eeg=False)
print(raw.info['projs'])
raw.info['bads'] = raw.info['ch_names'][:16]
raw2 = raw.copy()
raw.apply_proj()
raw2.info.normalize_proj()
raw2.apply_proj()
np.testing.assert_allclose(raw.get_data(), raw2.get_data())
As per the warning, normalize_proj
should be applied but as you can see, it makes no difference except getting rid of the warning.
Expected results
There should be no warning
Actual results
We see a warning:
/Users/mainak/Desktop/mne_proj_issue.py:16: RuntimeWarning: Projection vector "PCA-v1" has magnitude 0.99 (should be unity), applying projector with 86/102 of the original channels available may be dangerous, consider recomputing and adding projection vectors for channels that are eventually used. If this is intentional, consider using info.normalize_proj()
# raw.apply_proj()
/Users/mainak/Desktop/mne_proj_issue.py:16: RuntimeWarning: Projection vector "PCA-v2" has magnitude 0.95 (should be unity), applying projector with 86/102 of the original channels available may be dangerous, consider recomputing and adding projection vectors for channels that are eventually used. If this is intentional, consider using info.normalize_proj()
# raw.apply_proj()
/Users/mainak/Desktop/mne_proj_issue.py:16: RuntimeWarning: Projection vector "PCA-v3" has magnitude 0.85 (should be unity), applying projector with 86/102 of the original channels available may be dangerous, consider recomputing and adding projection vectors for channels that are eventually used. If this is intentional, consider using info.normalize_proj()
Additional information
Additionally, the code path is somewhat confusing to follow. There is an if inplace
clause:
which makes the function return without performing an SVD. I see that _make_projector
is never called with inplace=False
. Is this dead code? We discussed this with @mshamalainen and the right thing to do is:
- combine the projectors into a matrix with bad channels zeroed out
- compute SVD of this matrix and use it to make the new projector
There is nothing “dangerous” per se in doing this as far as we can see. It only makes the projection operator mathematically correct. That is: P.P = P
Issue Analytics
- State:
- Created 2 years ago
- Comments:22 (22 by maintainers)
Top Results From Across the Web
Consumer Warning Labels Aren't Working
Warning labels are everywhere. They alert us to the risks of eating unhealthy foods, smoking cigarettes, taking prescription drugs, ...
Read more >The risk of putting warning labels on election misinformation
There isn't clear evidence that the warning labels Facebook and Twitter attach to fake news reduce the spread of misinformation.
Read more >ESMA LIBRARY - European Union
07/02/2014, 2014/152, ESMA tells firms to improve their selling practices for complex financial products, MiFID - Investor Protection, Warnings and ...
Read more >Sugar-Sweetened Beverage Warning Labels - NCBI - NIH
Lessons from tobacco warning labels can be applied to developing and implementing warning labels for sugar-sweetened beverages (SSBs).
Read more >likely to cause confusion among customers - Dutch translation ...
the existing proposal, which requires only a simple pictogram displaying the letters 'EX' to appear on the warning sign, as being likely to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One last point to clarify here – note that the default is
inplace=False
:https://github.com/mne-tools/mne-python/blob/258b462f06a3a5ef4c6d8ded6ca03f519b498831/mne/io/proj.py#L542-L543
So for example this bit of code in
mne.io.proj.make_projector
should hit theinplace=False
path:https://github.com/mne-tools/mne-python/blob/258b462f06a3a5ef4c6d8ded6ca03f519b498831/mne/io/proj.py#L539
Also:
seems to suggest that subselecting channels in projection operator is dangerous. Rather, what’s dangerous is if there was a bad channel when computing the original projector which is a different problem