def test_plot_topo(): """Test plotting of ERP topography """ # Show topography evoked = _get_epochs().average() plot_topo(evoked, layout) warnings.simplefilter('always', UserWarning) picked_evoked = pick_channels_evoked(evoked, evoked.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', 'inaxes') func(event(inaxes=fig.axes[0]))
def test_plot_topo(): """Test plotting of ERP topography """ # Show topography evoked = _get_epochs().average() plot_topo(evoked, layout) warnings.simplefilter('always', UserWarning) picked_evoked = pick_channels_evoked(evoked, evoked.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked( evoked_delayed_ssp, ch_names) fig = plot_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', 'inaxes') func(event(inaxes=fig.axes[0]))
def test_plot_topo(): """Test plotting of ERP topography """ import matplotlib.pyplot as plt # Show topography evoked = _get_epochs().average() # should auto-find layout plot_evoked_topo([evoked, evoked], merge_grads=True) # Test jointplot evoked.plot_joint() evoked.plot_joint(title='test', ts_args=dict(spatial_colors=True), topomap_args=dict(colorbar=True, times=[0.])) warnings.simplefilter('always', UserWarning) picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3]) picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked( evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func( event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True) picked_evoked.plot_topo(merge_grads=True) # Test RMS plot of grad pairs plt.close('all') for ax, idx in iter_topography(evoked.info): ax.plot(evoked.data[idx], color='red') plt.close('all')
def test_plot_topo(): """Test plotting of ERP topography.""" # Show topography evoked = _get_epochs().average() # should auto-find layout plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w') picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3]) picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: pytest.raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func(event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) with pytest.warns(RuntimeWarning, match='projection'): _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True, background_color='k') # Test RMS plot of grad pairs picked_evoked.plot_topo(merge_grads=True, background_color='w') plt.close('all') for ax, idx in iter_topography(evoked.info): ax.plot(evoked.data[idx], color='red') # test status bar message assert (evoked.ch_names[idx] in ax.format_coord(.5, .5)) plt.close('all') cov = read_cov(cov_fname) cov['projs'] = [] evoked.pick_types(meg=True).plot_topo(noise_cov=cov) plt.close('all') # test plot_topo evoked.plot_topo() # should auto-find layout _line_plot_onselect(0, 200, ['mag', 'grad'], evoked.info, evoked.data, evoked.times) plt.close('all')
def test_plot_topo(): """Test plotting of ERP topography.""" import matplotlib.pyplot as plt # Show topography evoked = _get_epochs().average() # should auto-find layout plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w') # Test jointplot evoked.plot_joint() def return_inds(d): # to test function kwarg to zorder arg of evoked.plot return list(range(d.shape[0])) evoked.plot_joint(title='test', topomap_args=dict(contours=0, res=8), ts_args=dict(spatial_colors=True, zorder=return_inds)) assert_raises(ValueError, evoked.plot_joint, ts_args=dict(axes=True)) warnings.simplefilter('always', UserWarning) picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3]) picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func(event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True, background_color='k') # Test RMS plot of grad pairs picked_evoked.plot_topo(merge_grads=True, background_color='w') plt.close('all') for ax, idx in iter_topography(evoked.info): ax.plot(evoked.data[idx], color='red') # test status bar message assert_true(evoked.ch_names[idx] in ax.format_coord(.5, .5)) plt.close('all')
def test_plot_evoked_field(): """Test plotting evoked field.""" evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: with warnings.catch_warnings(record=True): # bad proj maps = make_field_map(evoked, trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) evoked.plot_field(maps, time=0.1)
def test_plot_evoked_field(renderer): """Test plotting evoked field.""" evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: with pytest.warns(RuntimeWarning, match='projection'): maps = make_field_map(evoked, trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) evoked.plot_field(maps, time=0.1)
def test_plot_evoked_field(): """Test plotting evoked field.""" evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: with pytest.warns(RuntimeWarning, match='projection'): maps = make_field_map(evoked, trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) evoked.plot_field(maps, time=0.1)
def test_plot_evoked_field(): """Test plotting evoked field """ evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: with warnings.catch_warnings(record=True): # bad proj maps = make_field_map(evoked, trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) evoked.plot_field(maps, time=0.1)
def test_plot_evoked_field(): """Test plotting evoked field """ trans_fname = op.join(data_dir, "MEG", "sample", "sample_audvis_raw-trans.fif") evoked = read_evokeds(evoked_fname, condition="Left Auditory", baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ["meg", None]: maps = make_field_map( evoked, trans_fname=trans_fname, subject="sample", subjects_dir=subjects_dir, n_jobs=1, ch_type=t ) evoked.plot_field(maps, time=0.1)
def test_plot_topo(): """Test plotting of ERP topography """ # Show topography evoked = _get_epochs().average() plot_topo(evoked, layout) warnings.simplefilter("always", UserWarning) picked_evoked = pick_channels_evoked(evoked, evoked.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_topo, evo, layout, color=["y", "b"]) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) plot_topo(picked_evoked_delayed_ssp, layout, proj="interactive")
def test_plot_evoked_field(): """Test plotting evoked field """ trans_fname = op.join(data_dir, 'MEG', 'sample', 'sample_audvis_raw-trans.fif') evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: maps = make_field_map(evoked, trans_fname=trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) evoked.plot_field(maps, time=0.1)
def test_plot_evoked_field(renderer): """Test plotting evoked field.""" evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: with pytest.warns(RuntimeWarning, match='projection'): maps = make_field_map(evoked, trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) fig = evoked.plot_field(maps, time=0.1) if renderer.get_3d_backend() == 'mayavi': import mayavi # noqa: F401 analysis:ignore assert isinstance(fig, mayavi.core.scene.Scene)
def test_plot_evoked_field(backends_3d): """Test plotting evoked field.""" backend_name = get_3d_backend() evoked = read_evokeds(evoked_fname, condition='Left Auditory', baseline=(-0.2, 0.0)) evoked = pick_channels_evoked(evoked, evoked.ch_names[::10]) # speed for t in ['meg', None]: with pytest.warns(RuntimeWarning, match='projection'): maps = make_field_map(evoked, trans_fname, subject='sample', subjects_dir=subjects_dir, n_jobs=1, ch_type=t) fig = evoked.plot_field(maps, time=0.1) if backend_name == 'mayavi': import mayavi # noqa: F401 analysis:ignore assert isinstance(fig, mayavi.core.scene.Scene)
def test_plot_topo(): """Test plotting of ERP topography """ import matplotlib.pyplot as plt # Show topography evoked = _get_epochs().average() plot_evoked_topo(evoked) # should auto-find layout # Test jointplot evoked.plot_joint() evoked.plot_joint(title='test', ts_args=dict(spatial_colors=True), topomap_args=dict(colorbar=True, times=[0.])) warnings.simplefilter('always', UserWarning) picked_evoked = evoked.pick_channels(evoked.ch_names[:3], copy=True) picked_evoked_eeg = evoked.pick_types(meg=False, eeg=True, copy=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func(event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True) picked_evoked.plot_topo(merge_grads=True) # Test RMS plot of grad pairs plt.close('all')
def test_plot_topo(): """Test plotting of ERP topography """ import matplotlib.pyplot as plt # Show topography evoked = _get_epochs().average() plot_evoked_topo(evoked) # should auto-find layout warnings.simplefilter('always', UserWarning) picked_evoked = evoked.pick_channels(evoked.ch_names[:3], copy=True) picked_evoked_eeg = evoked.pick_types(meg=False, eeg=True, copy=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: assert_raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked( evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', 'inaxes') func(event(inaxes=fig.axes[0])) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) _plot_update_evoked_topo(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True) plt.close('all')
def test_plot_topo(): """Test plotting of ERP topography.""" # Show topography evoked = _get_epochs().average() # should auto-find layout plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w') picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3]) picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: pytest.raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func( event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) with pytest.warns(RuntimeWarning, match='projection'): _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True, background_color='k') # Test RMS plot of grad pairs picked_evoked.plot_topo(merge_grads=True, background_color='w') plt.close('all') for ax, idx in iter_topography(evoked.info, legend=True): ax.plot(evoked.data[idx], color='red') # test status bar message if idx != -1: assert (evoked.ch_names[idx] in ax.format_coord(.5, .5)) assert idx == -1 plt.close('all') cov = read_cov(cov_fname) cov['projs'] = [] evoked.pick_types(meg=True).plot_topo(noise_cov=cov) plt.close('all') # test plot_topo evoked.plot_topo() # should auto-find layout _line_plot_onselect(0, 200, ['mag', 'grad'], evoked.info, evoked.data, evoked.times) plt.close('all') for ax, idx in iter_topography(evoked.info): # brief test with false ax.plot([0, 1, 2]) break plt.close('all')
from mne.minimum_norm import make_inverse_operator, apply_inverse from mne.inverse_sparse import tf_mixed_norm from mne.viz import plot_sparse_source_estimates data_path = sample.data_path() fwd_fname = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif' ave_fname = data_path + '/MEG/sample/sample_audvis-no-filter-ave.fif' cov_fname = data_path + '/MEG/sample/sample_audvis-cov.fif' # Read noise covariance matrix cov = mne.read_cov(cov_fname) # Handling average file condition = 'Left visual' evoked = io.read_evokeds(ave_fname, condition=condition, baseline=(None, 0)) evoked = mne.pick_channels_evoked(evoked) # We make the window slightly larger than what you'll eventually be interested # in ([-0.05, 0.3]) to avoid edge effects. evoked.crop(tmin=-0.1, tmax=0.4) # Handling forward solution forward = mne.read_forward_solution(fwd_fname, force_fixed=False, surf_ori=True) cov = mne.cov.regularize(cov, evoked.info) ############################################################################### # Run solver # alpha_space regularization parameter is between 0 and 100 (100 is high) alpha_space = 50. # spatial regularization parameter
def test_plot_topo(): """Test plotting of ERP topography.""" import matplotlib.pyplot as plt # Show topography evoked = _get_epochs().average() # should auto-find layout plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w') # Test jointplot evoked.plot_joint(ts_args=dict(time_unit='s'), topomap_args=dict(time_unit='s')) def return_inds(d): # to test function kwarg to zorder arg of evoked.plot return list(range(d.shape[0])) evoked.plot_joint(title='test', topomap_args=dict(contours=0, res=8, time_unit='ms'), ts_args=dict(spatial_colors=True, zorder=return_inds, time_unit='s')) pytest.raises(ValueError, evoked.plot_joint, ts_args=dict(axes=True, time_unit='s')) axes = plt.subplots(nrows=3)[-1].flatten().tolist() evoked.plot_joint(times=[0], picks=[6, 7, 8], ts_args=dict(axes=axes[0]), topomap_args={ "axes": axes[1:], "time_unit": "s" }) plt.close() pytest.raises(ValueError, evoked.plot_joint, picks=[6, 7, 8], ts_args=dict(axes=axes[0]), topomap_args=dict(axes=axes[2:])) warnings.simplefilter('always', UserWarning) picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3]) picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling with warnings.catch_warnings(record=True): for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: pytest.raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked( evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func( event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True, background_color='k') # Test RMS plot of grad pairs picked_evoked.plot_topo(merge_grads=True, background_color='w') plt.close('all') for ax, idx in iter_topography(evoked.info): ax.plot(evoked.data[idx], color='red') # test status bar message assert (evoked.ch_names[idx] in ax.format_coord(.5, .5)) plt.close('all') cov = read_cov(cov_fname) cov['projs'] = [] evoked.pick_types(meg=True).plot_topo(noise_cov=cov) plt.close('all')
vertno = [ss['vertno'] for ss in forward['src']] stc_ctf = SourceEstimate(np.squeeze(ctfs).T, vertno, tmin=0., tstep=0.001) # save CTF as STC file for mne_analyze print "STC filename for CTFs: %s " % stc_fname_out stc_ctf.save(stc_fname_out) #### APPLY TO EVOKED DATA AND COMPUTE SNRs # (e.g. to check whether regularization is reasonable) # (assumes as many conditions in evoked as spatial filters in spatial_filters) # read and prepare evoked data evoked = [mne.read_evokeds(fname_evoked, condition=cc, baseline=(None, 0), proj=True) for cc in range(n_filter)] evoked = [mne.pick_channels_evoked(ee, ch_names) for ee in evoked] evoked_mat = [ee.data for ee in evoked] # Apply estimator to data evoked_tc = [spatial_filters[ff].dot(evoked_mat[ff]) for ff in range(n_filter)] # Compute SNR as ration with standard deviation of baseline (to 0ms) base_idx = [np.abs(ee.times).argmin() for ee in evoked] evoked_tc_snr = [evoked_tc[ff] / np.std(evoked_tc[:base_idx[ff]]) for ff in range(n_filter)] print "\n Evoked data:" for ff in np.arange(len(spatial_filters)): print "Max SNR (std to baseline) %f: " % np.abs(evoked_tc_snr[ff]).max() print "\n"
print(__doc__) data_path = sample.data_path() subjects_dir = data_path + '/subjects' fwd_fname = data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif' ave_fname = data_path + '/MEG/sample/sample_audvis-no-filter-ave.fif' cov_fname = data_path + '/MEG/sample/sample_audvis-shrunk-cov.fif' # Read noise covariance matrix cov = mne.read_cov(cov_fname) # Handling average file condition = 'Left visual' evoked = mne.read_evokeds(ave_fname, condition=condition, baseline=(None, 0)) evoked = mne.pick_channels_evoked(evoked) # We make the window slightly larger than what you'll eventually be interested # in ([-0.05, 0.3]) to avoid edge effects. evoked.crop(tmin=-0.1, tmax=0.4) # Handling forward solution forward = mne.read_forward_solution(fwd_fname) ############################################################################### # Run solver # alpha parameter is between 0 and 100 (100 gives 0 active source) alpha = 40. # general regularization parameter # l1_ratio parameter between 0 and 1 promotes temporal smoothness # (0 means no temporal regularization) l1_ratio = 0.03 # temporal regularization parameter
def test_plot_topo(): """Test plotting of ERP topography.""" # Show topography evoked = _get_epochs().average() # should auto-find layout plot_evoked_topo([evoked, evoked], merge_grads=True, background_color='w') # Test jointplot evoked.plot_joint(ts_args=dict(time_unit='s'), topomap_args=dict(time_unit='s')) def return_inds(d): # to test function kwarg to zorder arg of evoked.plot return list(range(d.shape[0])) evoked.plot_joint(title='test', topomap_args=dict(contours=0, res=8, time_unit='ms'), ts_args=dict(spatial_colors=True, zorder=return_inds, time_unit='s')) pytest.raises(ValueError, evoked.plot_joint, ts_args=dict(axes=True, time_unit='s')) axes = plt.subplots(nrows=3)[-1].flatten().tolist() evoked.plot_joint(times=[0], picks=[6, 7, 8], ts_args=dict(axes=axes[0]), topomap_args={"axes": axes[1:], "time_unit": "s"}) plt.close() pytest.raises(ValueError, evoked.plot_joint, picks=[6, 7, 8], ts_args=dict(axes=axes[0]), topomap_args=dict(axes=axes[2:])) picked_evoked = evoked.copy().pick_channels(evoked.ch_names[:3]) picked_evoked_eeg = evoked.copy().pick_types(meg=False, eeg=True) picked_evoked_eeg.pick_channels(picked_evoked_eeg.ch_names[:3]) # test scaling for ylim in [dict(mag=[-600, 600]), None]: plot_evoked_topo([picked_evoked] * 2, layout, ylim=ylim) for evo in [evoked, [evoked, picked_evoked]]: pytest.raises(ValueError, plot_evoked_topo, evo, layout, color=['y', 'b']) evoked_delayed_ssp = _get_epochs_delayed_ssp().average() ch_names = evoked_delayed_ssp.ch_names[:3] # make it faster picked_evoked_delayed_ssp = pick_channels_evoked(evoked_delayed_ssp, ch_names) fig = plot_evoked_topo(picked_evoked_delayed_ssp, layout, proj='interactive') func = _get_presser(fig) event = namedtuple('Event', ['inaxes', 'xdata', 'ydata']) func(event(inaxes=fig.axes[0], xdata=fig.axes[0]._mne_axs[0].pos[0], ydata=fig.axes[0]._mne_axs[0].pos[1])) func(event(inaxes=fig.axes[0], xdata=0, ydata=0)) params = dict(evokeds=[picked_evoked_delayed_ssp], times=picked_evoked_delayed_ssp.times, fig=fig, projs=picked_evoked_delayed_ssp.info['projs']) bools = [True] * len(params['projs']) with pytest.warns(RuntimeWarning, match='projection'): _plot_update_evoked_topo_proj(params, bools) # should auto-generate layout plot_evoked_topo(picked_evoked_eeg.copy(), fig_background=np.zeros((4, 3, 3)), proj=True, background_color='k') # Test RMS plot of grad pairs picked_evoked.plot_topo(merge_grads=True, background_color='w') plt.close('all') for ax, idx in iter_topography(evoked.info): ax.plot(evoked.data[idx], color='red') # test status bar message assert (evoked.ch_names[idx] in ax.format_coord(.5, .5)) plt.close('all') cov = read_cov(cov_fname) cov['projs'] = [] evoked.pick_types(meg=True).plot_topo(noise_cov=cov) plt.close('all') # test plot_topo evoked.plot_topo() # should auto-find layout _line_plot_onselect(0, 200, ['mag', 'grad'], evoked.info, evoked.data, evoked.times) plt.close('all')