-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
ENH: Add source space SNR estimate #6908
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
244e2cc
source-snr-edit
padmasundaram 908e7b9
FIX move estimate_snr to be a method
jasmainak f9fb26b
ENH: name change
jasmainak d954ae4
Make it work
jasmainak aef9f00
SNR works, now clean up code
padmasundaram a013fe7
fixed unnecessary stc copy, returns stc object
padmasundaram 3b4a93d
added plot source space SNR tutorial file
padmasundaram a80c567
updated author names
padmasundaram 5ad490f
fixed period for pydocsty and suggested documenation edit
padmasundaram 9bf444e
edits suggested from @drammock
padmasundaram 6e3106b
made edits suggested by reviewers
padmasundaram 04012cf
made edits suggested by reviewers
padmasundaram 3213d2b
N -> n_channels
padmasundaram 3efeba9
Fixed formatting of Reference in comment
padmasundaram beac772
fixed formatting in doc and in code
padmasundaram 60c1fd0
fixed snr_stc creation
padmasundaram dbcff92
further minor edits
padmasundaram 66fdd89
fixed formatting issues and colormap choice in eg
padmasundaram 39b64fb
removed colon after Reference
padmasundaram 48a7c70
Corrected SNR calculation to take unwhitened sensor signal b instead …
klankinen 7cd0057
Minor changes to formatting
klankinen fb2655f
FIX: transparent
larsoner 40c4713
FIX: Rename
larsoner 8c65e2e
FIX?
larsoner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| # -*- coding: utf-8 -*- | ||
| """ | ||
| =============================== | ||
| Computing source space SNR | ||
| =============================== | ||
|
|
||
| This example shows how to compute and plot source space SNR as in [1]_. | ||
| """ | ||
| # Author: Padma Sundaram <tottochan@gmail.com> | ||
| # Kaisu Lankinen <klankinen@mgh.harvard.edu> | ||
| # | ||
| # License: BSD (3-clause) | ||
|
|
||
| # sphinx_gallery_thumbnail_number = 2 | ||
|
|
||
| import mne | ||
| from mne.datasets import sample | ||
| from mne.minimum_norm import make_inverse_operator, apply_inverse | ||
| import numpy as np | ||
| import matplotlib.pyplot as plt | ||
|
|
||
| print(__doc__) | ||
|
|
||
| data_path = sample.data_path() | ||
| subjects_dir = data_path + '/subjects' | ||
|
|
||
| # Read data | ||
| fname_evoked = data_path + '/MEG/sample/sample_audvis-ave.fif' | ||
| evoked = mne.read_evokeds(fname_evoked, condition='Left Auditory', | ||
| baseline=(None, 0)) | ||
| fname_fwd = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif' | ||
| fname_cov = data_path + '/MEG/sample/sample_audvis-cov.fif' | ||
| fwd = mne.read_forward_solution(fname_fwd) | ||
| cov = mne.read_cov(fname_cov) | ||
|
|
||
| ############################################################################### | ||
| # MEG-EEG | ||
| # ------- | ||
|
|
||
| # Read inverse operator: | ||
| inv_op = make_inverse_operator(evoked.info, fwd, cov, fixed=True, verbose=True) | ||
|
|
||
| # Calculate MNE: | ||
| snr = 3.0 | ||
| lambda2 = 1.0 / snr ** 2 | ||
| stc = apply_inverse(evoked, inv_op, lambda2, 'MNE', verbose=True) | ||
|
|
||
| # Calculate SNR in source space: | ||
| snr_stc = stc.estimate_snr(evoked.info, fwd, cov) | ||
|
|
||
| # Plot an average SNR across source points over time: | ||
| ave = np.mean(snr_stc.data, axis=0) | ||
|
|
||
| fig, ax = plt.subplots() | ||
| ax.plot(evoked.times, ave) | ||
| ax.set(xlabel='Time (sec)', ylabel='SNR MEG-EEG') | ||
| fig.tight_layout() | ||
|
|
||
| # Find time point of maximum SNR: | ||
| maxidx = np.argmax(ave) | ||
|
|
||
| # Plot SNR on source space at the time point of maximum SNR: | ||
| kwargs = dict(initial_time=evoked.times[maxidx], hemi='split', | ||
| views=['lat', 'med'], subjects_dir=subjects_dir, size=(600, 600), | ||
| clim=dict(kind='value', lims=(-100, -70, -40)), | ||
| transparent=True, colormap='viridis') | ||
| snr_stc.plot(**kwargs) | ||
|
|
||
| ############################################################################### | ||
| # EEG | ||
| # --- | ||
| # Next we do the same for EEG and plot the result on the cortex: | ||
|
|
||
| evoked_eeg = evoked.copy().pick_types(eeg=True, meg=False) | ||
| inv_op_eeg = make_inverse_operator(evoked_eeg.info, fwd, cov, fixed=True, | ||
| verbose=True) | ||
| stc_eeg = apply_inverse(evoked_eeg, inv_op_eeg, lambda2, 'MNE', verbose=True) | ||
| snr_stc_eeg = stc_eeg.estimate_snr(evoked_eeg.info, fwd, cov) | ||
| snr_stc_eeg.plot(**kwargs) | ||
|
|
||
| ############################################################################### | ||
| # MEG | ||
| # --- | ||
| # Finally we do this for MEG: | ||
|
|
||
| evoked_meg = evoked.copy().pick_types(eeg=False, meg=True) | ||
| inv_op_meg = make_inverse_operator(evoked_meg.info, fwd, cov, fixed=True, | ||
| verbose=True) | ||
| stc_meg = apply_inverse(evoked_meg, inv_op_meg, lambda2, 'MNE', verbose=True) | ||
| snr_stc_meg = stc_meg.estimate_snr(evoked_meg.info, fwd, cov) | ||
| snr_stc_meg.plot(**kwargs) | ||
|
|
||
| ############################################################################## | ||
| # References | ||
| # ---------- | ||
| # .. [1] Goldenholz, D. M., Ahlfors, S. P., Hämäläinen, M. S., Sharon, D., | ||
| # Ishitobi, M., Vaina, L. M., & Stufflebeam, S. M. (2009). Mapping the | ||
| # Signal-To-Noise-Ratios of Cortical Sources in Magnetoencephalography | ||
| # and Electroencephalography. Human Brain Mapping, 30(4), 1077–1086. | ||
| # doi:10.1002/hbm.20571 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.