This is an automated email from the git hooks/post-receive script. yoh pushed a commit to tag 0.4 in repository python-mne.
commit 88e70a12f4acfa8d831fa51adc76ed3caac2346c Author: Alexandre Gramfort <[email protected]> Date: Thu Mar 8 15:47:08 2012 +0100 ENH : add plot_cov function to display noise cov with and without SSPs --- examples/plot_estimate_covariance_matrix.py | 23 +--------- examples/plot_read_noise_covariance_matrix.py | 3 ++ mne/minimum_norm/inverse.py | 2 + mne/viz.py | 64 ++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/examples/plot_estimate_covariance_matrix.py b/examples/plot_estimate_covariance_matrix.py index 99bb876..556c5ed 100644 --- a/examples/plot_estimate_covariance_matrix.py +++ b/examples/plot_estimate_covariance_matrix.py @@ -23,26 +23,7 @@ raw = fiff.Raw(fname) cov = mne.compute_raw_data_covariance(raw, reject=dict(eeg=80e-6, eog=150e-6)) print cov -bads = raw.info['bads'] -sel_eeg = mne.fiff.pick_types(raw.info, meg=False, eeg=True, exclude=bads) -sel_mag = mne.fiff.pick_types(raw.info, meg='mag', eeg=False, exclude=bads) -sel_grad = mne.fiff.pick_types(raw.info, meg='grad', eeg=False, exclude=bads) -idx_eeg = [cov.ch_names.index(raw.ch_names[c]) for c in sel_eeg] -idx_mag = [cov.ch_names.index(raw.ch_names[c]) for c in sel_mag] -idx_grad = [cov.ch_names.index(raw.ch_names[c]) for c in sel_grad] - ############################################################################### # Show covariance -import pylab as pl -pl.figure(figsize=(7.3, 2.7)) -pl.subplot(1, 3, 1) -pl.imshow(cov.data[idx_eeg][:, idx_eeg], interpolation="nearest") -pl.title('EEG covariance') -pl.subplot(1, 3, 2) -pl.imshow(cov.data[idx_grad][:, idx_grad], interpolation="nearest") -pl.title('Gradiometers') -pl.subplot(1, 3, 3) -pl.imshow(cov.data[idx_mag][:, idx_mag], interpolation="nearest") -pl.title('Magnetometers') -pl.subplots_adjust(0.04, 0.0, 0.98, 0.94, 0.2, 0.26) -pl.show() +mne.viz.plot_cov(cov, raw.info, exclude=raw.info['bads'], colorbar=True, + proj=True) # try setting proj to False to see the effect diff --git a/examples/plot_read_noise_covariance_matrix.py b/examples/plot_read_noise_covariance_matrix.py index 9efd639..9d23415 100644 --- a/examples/plot_read_noise_covariance_matrix.py +++ b/examples/plot_read_noise_covariance_matrix.py @@ -20,6 +20,9 @@ print cov ############################################################################### # Show covariance + +# Note: if you have the measurement info you can use mne.viz.plot_cov + import pylab as pl pl.matshow(cov.data) pl.title('Noise covariance matrix (%d channels)' % cov.data.shape[0]) diff --git a/mne/minimum_norm/inverse.py b/mne/minimum_norm/inverse.py index 2338301..c60e6a8 100644 --- a/mne/minimum_norm/inverse.py +++ b/mne/minimum_norm/inverse.py @@ -360,6 +360,8 @@ def prepare_inverse_operator(orig, nave, lambda2, dSPM): inv['noise_cov']['names']) if ncomp > 0: print ' Created an SSP operator (subspace dimension = %d)' % ncomp + else: + print ' The projection vectors do not apply to these channels.' # # Create the whitener diff --git a/mne/viz.py b/mne/viz.py index 8670b2a..648c142 100644 --- a/mne/viz.py +++ b/mne/viz.py @@ -5,10 +5,12 @@ # # License: Simplified BSD +import copy import numpy as np import pylab as pl -from .fiff.pick import channel_type +from .fiff.pick import channel_type, pick_types +from .fiff.proj import make_projector def plot_topo(evoked, layout): @@ -79,6 +81,66 @@ def plot_evoked(evoked, picks=None, unit=True, show=True): pl.show() +def plot_cov(cov, info, exclude=None, colorbar=True, proj=False, show=True): + """Plot Covariance data + + Parameters + ---------- + cov : instance of Covariance + The evoked data + info: dict + Measurement info + exclude : list of string + List of channels to exclude. If empty do not exclude any channel. + colorbar : bool + Show colorbar or not + proj : bool + Apply projections or not + show : bool + Call pylab.show() as the end or not. + """ + ch_names = [n for n in cov.ch_names if not n in exclude] + ch_idx = [cov.ch_names.index(n) for n in ch_names] + info_ch_names = info['ch_names'] + sel_eeg = pick_types(info, meg=False, eeg=True, exclude=exclude) + sel_mag = pick_types(info, meg='mag', eeg=False, exclude=exclude) + sel_grad = pick_types(info, meg='grad', eeg=False, exclude=exclude) + idx_eeg = [ch_names.index(info_ch_names[c]) for c in sel_eeg] + idx_mag = [ch_names.index(info_ch_names[c]) for c in sel_mag] + idx_grad = [ch_names.index(info_ch_names[c]) for c in sel_grad] + + idx_names = [(idx_eeg, 'EEG covariance'), + (idx_grad, 'Gradiometers'), + (idx_mag, 'Magnetometers')] + idx_names = [(idx, name) for idx, name in idx_names if len(idx) > 0] + + C = cov.data[ch_idx][:, ch_idx] + + if proj: + projs = copy.deepcopy(info['projs']) + + # Activate the projection items + for p in projs: + p['active'] = True + + P, ncomp, _ = make_projector(projs, ch_names) + if ncomp > 0: + print ' Created an SSP operator (subspace dimension = %d)' % \ + ncomp + C = np.dot(P, np.dot(C, P.T)) + else: + print ' The projection vectors do not apply to these channels.' + + pl.figure(figsize=(2.5 * len(idx_names), 2.7)) + for k, (idx, name) in enumerate(idx_names): + pl.subplot(1, len(idx_names), k + 1) + pl.imshow(C[idx][:, idx], interpolation="nearest") + pl.title(name) + pl.subplots_adjust(0.04, 0.0, 0.98, 0.94, 0.2, 0.26) + if show: + pl.show() + + def plot_source_estimate(src, stc, n_smooth=200, cmap='jet'): """Plot source estimates """ -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-mne.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
