# Read noise covariance matrix cov = mne.read_cov(cov_fname) # Handling average file setno = 0 evoked = fiff.read_evoked(ave_fname, setno=setno, baseline=(None, 0)) evoked.crop(tmin=0, tmax=0.3) # Handling forward solution forward = mne.read_forward_solution(fwd_fname, surf_ori=True) cov = mne.cov.regularize(cov, evoked.info) import pylab as pl pl.figure() ylim = dict(eeg=[-10, 10], grad=[-400, 400], mag=[-600, 600]) plot_evoked(evoked, ylim=ylim, proj=True) ############################################################################### # Run solver alpha = 70 # regularization parameter between 0 and 100 (100 is high) loose, depth = 0.2, 0.9 # loose orientation & depth weighting # Compute dSPM solution to be used as weights in MxNE inverse_operator = make_inverse_operator(evoked.info, forward, cov, loose=None, depth=depth, fixed=True) stc_dspm = apply_inverse(evoked, inverse_operator, lambda2=1. / 9., method='dSPM') # Compute MxNE inverse solution stc, residual = mixed_norm(evoked, forward, cov, alpha, loose=loose, depth=depth, maxit=3000, tol=1e-4, active_set_size=10,
times = np.linspace(tmin, tmin + n_samples * tstep, n_samples) # Generate times series from 2 Morlet wavelets stc_data = np.zeros((len(labels), len(times))) Ws = morlet(sfreq, [3, 10], n_cycles=[1, 1.5]) stc_data[0][:len(Ws[0])] = np.real(Ws[0]) stc_data[1][:len(Ws[1])] = np.real(Ws[1]) stc_data *= 100 * 1e-9 # use nAm as unit # time translation stc_data[1] = np.roll(stc_data[1], 80) stc = generate_sparse_stc(fwd['src'], labels, stc_data, tmin, tstep, random_state=0) ############################################################################### # Generate noisy evoked data picks = mne.fiff.pick_types(raw.info, meg=True, exclude='bads') iir_filter = iir_filter_raw(raw, order=5, picks=picks, tmin=60, tmax=180) evoked = generate_evoked(fwd, stc, evoked_template, cov, snr, tmin=0.0, tmax=0.2, iir_filter=iir_filter) ############################################################################### # Plot plot_sparse_source_estimates(fwd['src'], stc, bgcolor=(1, 1, 1), opacity=0.5, high_resolution=True) plt.figure() plt.psd(evoked.data[0]) plot_evoked(evoked)
""" ================================== Reading and writing an evoked file ================================== """ # Author: Alexandre Gramfort <*****@*****.**> # # License: BSD (3-clause) print __doc__ from mne import fiff from mne.datasets import sample from mne.viz import plot_evoked data_path = sample.data_path('.') fname = data_path + '/MEG/sample/sample_audvis-ave.fif' # Reading evoked = fiff.Evoked(fname, setno=0, baseline=(None, 0)) ############################################################################### # Show result picks = fiff.pick_types(evoked.info, meg=True, eeg=True, exclude=evoked.info['bads']) # Pick channels to view plot_evoked(evoked, picks=picks)
""" ================================== Reading and writing an evoked file ================================== """ # Author: Alexandre Gramfort <*****@*****.**> # # License: BSD (3-clause) print __doc__ from mne import fiff from mne.datasets import sample from mne.viz import plot_evoked data_path = sample.data_path() fname = data_path + "/MEG/sample/sample_audvis-ave.fif" # Reading evoked = fiff.Evoked(fname, setno="Left Auditory", baseline=(None, 0), proj=True) ############################################################################### # Show result: # By using exclude=[] bad channels are not excluded and are shown in red plot_evoked(evoked, exclude=[])
""" ================================== Reading and writing an evoked file ================================== """ # Author: Alexandre Gramfort <*****@*****.**> # # License: BSD (3-clause) print __doc__ from mne import fiff from mne.datasets import sample from mne.viz import plot_evoked data_path = sample.data_path() fname = data_path + '/MEG/sample/sample_audvis-ave.fif' # Reading evoked = fiff.Evoked(fname, setno='Left Auditory', baseline=(None, 0), proj=True) ############################################################################### # Show result: # By using exclude=[] bad channels are not excluded and are shown in red plot_evoked(evoked, exclude=[])
# Read noise covariance matrix cov = mne.read_cov(cov_fname) # Handling average file setno = 0 evoked = fiff.read_evoked(ave_fname, setno=setno, baseline=(None, 0)) evoked.crop(tmin=0, tmax=0.3) # Handling forward solution forward = mne.read_forward_solution(fwd_fname, force_fixed=True, surf_ori=True) cov = mne.cov.regularize(cov, evoked.info) import pylab as pl pl.figure() ylim = dict(eeg=[-10, 10], grad=[-400, 400], mag=[-600, 600]) plot_evoked(evoked, ylim=ylim, proj=True) ############################################################################### # Run solver alpha = 70 # regularization parameter between 0 and 100 (100 is high) loose, depth = 0.2, 0.9 # loose orientation & depth weighting # Compute dSPM solution to be used as weights in MxNE inverse_operator = make_inverse_operator(evoked.info, forward, cov, loose=loose, depth=depth) stc_dspm = apply_inverse(evoked, inverse_operator, lambda2=1. / 9.,
loose=loose, depth=depth, maxit=200, tol=1e-4, weights=stc_dspm, weights_min=8., debias=True, wsize=16, tstep=4, window=0.05, return_residual=True) evoked = mne.fiff.pick_types_evoked(evoked, meg='grad') residual = mne.fiff.pick_types_evoked(residual, meg='grad') # Crop to remove edges stc.crop(tmin=-0.05, tmax=0.3) evoked.crop(tmin=-0.05, tmax=0.3) residual.crop(tmin=-0.05, tmax=0.3) import pylab as pl pl.figure() ylim = dict(eeg=[-10, 10], grad=[-200, 250], mag=[-600, 600]) plot_evoked(evoked, ylim=ylim, proj=True, titles=dict(grad='Evoked Response (grad)')) pl.figure() plot_evoked(residual, ylim=ylim, proj=True, titles=dict(grad='Residual (grad)')) ############################################################################### # View in 2D and 3D ("glass" brain like 3D plot) plot_sparse_source_estimates(forward['src'], stc, bgcolor=(1, 1, 1), opacity=0.1, fig_name="TF-MxNE (cond %s)" % setno, fig_number=setno, modes=['sphere'], scale_factors=[1.]) time_label = 'TF-MxNE time=%0.2f ms' brain = stc.plot('sample', 'inflated', 'rh', fmin=10e-9, fmid=15e-9, fmax=20e-9, time_label=time_label, smoothing_steps=5,
""" ================================== Reading and writing an evoked file ================================== """ # Author: Alexandre Gramfort <*****@*****.**> # # License: BSD (3-clause) print __doc__ from mne import fiff from mne.datasets import sample from mne.viz import plot_evoked data_path = sample.data_path('.') fname = data_path + '/MEG/sample/sample_audvis-ave.fif' # Reading evoked = fiff.Evoked(fname, setno=0, baseline=(None, 0), proj=True) ############################################################################### # Show result picks = fiff.pick_types(evoked.info, meg=True, eeg=True, exclude=evoked.info['bads']) # Pick channels to view plot_evoked(evoked, picks=picks)