def test_limits_to_control_points(): """Test functionality for determing control points.""" sample_src = read_source_spaces(src_fname) kwargs = dict(subjects_dir=subjects_dir, smoothing_steps=1) vertices = [s['vertno'] for s in sample_src] n_time = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.random.RandomState(0).rand((n_verts * n_time)) stc_data.shape = (n_verts, n_time) stc = SourceEstimate(stc_data, vertices, 1, 1, 'sample') # Test for simple use cases mlab = _import_mlab() stc.plot(**kwargs) stc.plot(clim=dict(pos_lims=(10, 50, 90)), **kwargs) stc.plot(colormap='hot', clim='auto', **kwargs) stc.plot(colormap='mne', clim='auto', **kwargs) figs = [mlab.figure(), mlab.figure()] stc.plot(clim=dict(kind='value', lims=(10, 50, 90)), figure=99, **kwargs) assert_raises(ValueError, stc.plot, clim='auto', figure=figs, **kwargs) # Test both types of incorrect limits key (lims/pos_lims) assert_raises(KeyError, plot_source_estimates, stc, colormap='mne', clim=dict(kind='value', lims=(5, 10, 15)), **kwargs) assert_raises(KeyError, plot_source_estimates, stc, colormap='hot', clim=dict(kind='value', pos_lims=(5, 10, 15)), **kwargs) # Test for correct clim values assert_raises(ValueError, stc.plot, clim=dict(kind='value', pos_lims=[0, 1, 0]), **kwargs) assert_raises(ValueError, stc.plot, colormap='mne', clim=dict(pos_lims=(5, 10, 15, 20)), **kwargs) assert_raises(ValueError, stc.plot, clim=dict(pos_lims=(5, 10, 15), kind='foo'), **kwargs) assert_raises(ValueError, stc.plot, colormap='mne', clim='foo', **kwargs) assert_raises(ValueError, stc.plot, clim=(5, 10, 15), **kwargs) assert_raises(ValueError, plot_source_estimates, 'foo', clim='auto', **kwargs) assert_raises(ValueError, stc.plot, hemi='foo', clim='auto', **kwargs) # Test handling of degenerate data with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') # thresholded maps stc._data.fill(0.) plot_source_estimates(stc, **kwargs) assert any('All data were zero' in str(ww.message) for ww in w) mlab.close(all=True)
def test_limits_to_control_points(): """Test functionality for determing control points.""" sample_src = read_source_spaces(src_fname) kwargs = dict(subjects_dir=subjects_dir, smoothing_steps=1) vertices = [s['vertno'] for s in sample_src] n_time = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.random.RandomState(0).rand((n_verts * n_time)) stc_data.shape = (n_verts, n_time) stc = SourceEstimate(stc_data, vertices, 1, 1, 'sample') # Test for simple use cases mlab = _import_mlab() stc.plot(**kwargs) stc.plot(clim=dict(pos_lims=(10, 50, 90)), **kwargs) stc.plot(colormap='hot', clim='auto', **kwargs) stc.plot(colormap='mne', clim='auto', **kwargs) figs = [mlab.figure(), mlab.figure()] stc.plot(clim=dict(kind='value', lims=(10, 50, 90)), figure=99, **kwargs) assert_raises(ValueError, stc.plot, clim='auto', figure=figs, **kwargs) # Test both types of incorrect limits key (lims/pos_lims) assert_raises(KeyError, plot_source_estimates, stc, colormap='mne', clim=dict(kind='value', lims=(5, 10, 15)), **kwargs) assert_raises(KeyError, plot_source_estimates, stc, colormap='hot', clim=dict(kind='value', pos_lims=(5, 10, 15)), **kwargs) # Test for correct clim values assert_raises(ValueError, stc.plot, clim=dict(kind='value', pos_lims=[0, 1, 0]), **kwargs) assert_raises(ValueError, stc.plot, colormap='mne', clim=dict(pos_lims=(5, 10, 15, 20)), **kwargs) assert_raises(ValueError, stc.plot, clim=dict(pos_lims=(5, 10, 15), kind='foo'), **kwargs) assert_raises(ValueError, stc.plot, colormap='mne', clim='foo', **kwargs) assert_raises(ValueError, stc.plot, clim=(5, 10, 15), **kwargs) assert_raises(ValueError, plot_source_estimates, 'foo', clim='auto', **kwargs) assert_raises(ValueError, stc.plot, hemi='foo', clim='auto', **kwargs) # Test handling of degenerate data with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') # thresholded maps stc._data.fill(0.) plot_source_estimates(stc, **kwargs) assert_equal(len(w), 1) mlab.close(all=True)
def test_limits_to_control_points(): """Test functionality for determining control points.""" sample_src = read_source_spaces(src_fname) kwargs = dict(subjects_dir=subjects_dir, smoothing_steps=1) vertices = [s['vertno'] for s in sample_src] n_time = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.random.RandomState(0).rand((n_verts * n_time)) stc_data.shape = (n_verts, n_time) stc = SourceEstimate(stc_data, vertices, 1, 1, 'sample') # Test for simple use cases mlab = _import_mlab() stc.plot(**kwargs) stc.plot(clim=dict(pos_lims=(10, 50, 90)), **kwargs) stc.plot(colormap='hot', clim='auto', **kwargs) stc.plot(colormap='mne', clim='auto', **kwargs) figs = [mlab.figure(), mlab.figure()] stc.plot(clim=dict(kind='value', lims=(10, 50, 90)), figure=99, **kwargs) pytest.raises(ValueError, stc.plot, clim='auto', figure=figs, **kwargs) # Test for correct clim values with pytest.raises(ValueError, match='monotonically'): stc.plot(clim=dict(kind='value', pos_lims=[0, 1, 0]), **kwargs) with pytest.raises(ValueError, match=r'.*must be \(3,\)'): stc.plot(colormap='mne', clim=dict(pos_lims=(5, 10, 15, 20)), **kwargs) with pytest.raises(ValueError, match="'value', 'values' and 'percent'"): stc.plot(clim=dict(pos_lims=(5, 10, 15), kind='foo'), **kwargs) with pytest.raises(ValueError, match='must be "auto" or dict'): stc.plot(colormap='mne', clim='foo', **kwargs) with pytest.raises(TypeError, match='must be an instance of'): plot_source_estimates('foo', clim='auto', **kwargs) with pytest.raises(ValueError, match='hemi'): stc.plot(hemi='foo', clim='auto', **kwargs) with pytest.raises(ValueError, match='Exactly one'): stc.plot(clim=dict(lims=[0, 1, 2], pos_lims=[0, 1, 2], kind='value'), **kwargs) # Test handling of degenerate data: thresholded maps stc._data.fill(0.) with pytest.warns(RuntimeWarning, match='All data were zero'): plot_source_estimates(stc, **kwargs) mlab.close(all=True)
def test_limits_to_control_points(): """Test functionality for determining control points.""" sample_src = read_source_spaces(src_fname) kwargs = dict(subjects_dir=subjects_dir, smoothing_steps=1) vertices = [s['vertno'] for s in sample_src] n_time = 5 n_verts = sum(len(v) for v in vertices) stc_data = np.random.RandomState(0).rand((n_verts * n_time)) stc_data.shape = (n_verts, n_time) stc = SourceEstimate(stc_data, vertices, 1, 1, 'sample') # Test for simple use cases mlab = _import_mlab() stc.plot(**kwargs) stc.plot(clim=dict(pos_lims=(10, 50, 90)), **kwargs) stc.plot(colormap='hot', clim='auto', **kwargs) stc.plot(colormap='mne', clim='auto', **kwargs) figs = [mlab.figure(), mlab.figure()] stc.plot(clim=dict(kind='value', lims=(10, 50, 90)), figure=99, **kwargs) pytest.raises(ValueError, stc.plot, clim='auto', figure=figs, **kwargs) # Test for correct clim values with pytest.raises(ValueError, match='monotonically'): stc.plot(clim=dict(kind='value', pos_lims=[0, 1, 0]), **kwargs) with pytest.raises(ValueError, match=r'.*must be \(3,\)'): stc.plot(colormap='mne', clim=dict(pos_lims=(5, 10, 15, 20)), **kwargs) with pytest.raises(ValueError, match='must be "value" or "percent"'): stc.plot(clim=dict(pos_lims=(5, 10, 15), kind='foo'), **kwargs) with pytest.raises(ValueError, match='must be "auto" or dict'): stc.plot(colormap='mne', clim='foo', **kwargs) with pytest.raises(TypeError, match='must be an instance of'): plot_source_estimates('foo', clim='auto', **kwargs) with pytest.raises(ValueError, match='hemi'): stc.plot(hemi='foo', clim='auto', **kwargs) with pytest.raises(ValueError, match='Exactly one'): stc.plot(clim=dict(lims=[0, 1, 2], pos_lims=[0, 1, 2], kind='value'), **kwargs) # Test handling of degenerate data: thresholded maps stc._data.fill(0.) with pytest.warns(RuntimeWarning, match='All data were zero'): plot_source_estimates(stc, **kwargs) mlab.close(all=True)
def test_plot_alignment(): """Test plotting of -trans.fif files and MEG sensor layouts.""" # generate fiducials file for testing tempdir = _TempDir() fiducials_path = op.join(tempdir, 'fiducials.fif') fid = [{'coord_frame': 5, 'ident': 1, 'kind': 1, 'r': [-0.08061612, -0.02908875, -0.04131077]}, {'coord_frame': 5, 'ident': 2, 'kind': 1, 'r': [0.00146763, 0.08506715, -0.03483611]}, {'coord_frame': 5, 'ident': 3, 'kind': 1, 'r': [0.08436285, -0.02850276, -0.04127743]}] write_dig(fiducials_path, fid, 5) mlab = _import_mlab() evoked = read_evokeds(evoked_fname)[0] sample_src = read_source_spaces(src_fname) with warnings.catch_warnings(record=True): # 4D weight tables bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True, preload=False).info infos = dict( Neuromag=evoked.info, CTF=read_raw_ctf(ctf_fname).info, BTi=bti, KIT=read_raw_kit(sqd_fname).info, ) for system, info in infos.items(): meg = ['helmet', 'sensors'] if system == 'KIT': meg.append('ref') plot_alignment(info, trans_fname, subject='sample', subjects_dir=subjects_dir, meg=meg) mlab.close(all=True) # KIT ref sensor coil def is defined mlab.close(all=True) info = infos['Neuromag'] assert_raises(TypeError, plot_alignment, 'foo', trans_fname, subject='sample', subjects_dir=subjects_dir) assert_raises(TypeError, plot_alignment, info, trans_fname, subject='sample', subjects_dir=subjects_dir, src='foo') assert_raises(ValueError, plot_alignment, info, trans_fname, subject='fsaverage', subjects_dir=subjects_dir, src=sample_src) sample_src.plot(subjects_dir=subjects_dir, head=True, skull=True, brain='white') mlab.close(all=True) # no-head version mlab.close(all=True) # all coord frames assert_raises(ValueError, plot_alignment, info) plot_alignment(info, surfaces=[]) for coord_frame in ('meg', 'head', 'mri'): plot_alignment(info, meg=['helmet', 'sensors'], dig=True, coord_frame=coord_frame, trans=trans_fname, subject='sample', mri_fiducials=fiducials_path, subjects_dir=subjects_dir, src=sample_src) mlab.close(all=True) # EEG only with strange options evoked_eeg_ecog = evoked.copy().pick_types(meg=False, eeg=True) evoked_eeg_ecog.info['projs'] = [] # "remove" avg proj evoked_eeg_ecog.set_channel_types({'EEG 001': 'ecog'}) with warnings.catch_warnings(record=True) as w: plot_alignment(evoked_eeg_ecog.info, subject='sample', trans=trans_fname, subjects_dir=subjects_dir, surfaces=['white', 'outer_skin', 'outer_skull'], meg=['helmet', 'sensors'], eeg=['original', 'projected'], ecog=True) mlab.close(all=True) assert_true(['Cannot plot MEG' in str(ww.message) for ww in w]) sphere = make_sphere_model(info=evoked.info, r0='auto', head_radius='auto') bem_sol = read_bem_solution(op.join(subjects_dir, 'sample', 'bem', 'sample-1280-1280-1280-bem-sol.fif')) bem_surfs = read_bem_surfaces(op.join(subjects_dir, 'sample', 'bem', 'sample-1280-1280-1280-bem.fif')) sample_src[0]['coord_frame'] = 4 # hack for coverage plot_alignment(info, subject='sample', eeg='projected', meg='helmet', bem=sphere, dig=True, surfaces=['brain', 'inner_skull', 'outer_skull', 'outer_skin']) plot_alignment(info, trans_fname, subject='sample', meg='helmet', subjects_dir=subjects_dir, eeg='projected', bem=sphere, surfaces=['head', 'brain'], src=sample_src) plot_alignment(info, trans_fname, subject='sample', meg=[], subjects_dir=subjects_dir, bem=bem_sol, eeg=True, surfaces=['head', 'inflated', 'outer_skull', 'inner_skull']) plot_alignment(info, trans_fname, subject='sample', meg=True, subjects_dir=subjects_dir, surfaces=['head', 'inner_skull'], bem=bem_surfs) sphere = make_sphere_model('auto', 'auto', evoked.info) src = setup_volume_source_space(sphere=sphere) plot_alignment(info, eeg='projected', meg='helmet', bem=sphere, src=src, dig=True, surfaces=['brain', 'inner_skull', 'outer_skull', 'outer_skin']) sphere = make_sphere_model('auto', None, evoked.info) # one layer plot_alignment(info, trans_fname, subject='sample', meg=False, coord_frame='mri', subjects_dir=subjects_dir, surfaces=['brain'], bem=sphere, show_axes=True) # one layer bem with skull surfaces: assert_raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['brain', 'head', 'inner_skull'], bem=sphere) # wrong eeg value: assert_raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, eeg='foo') # wrong meg value: assert_raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, meg='bar') # multiple brain surfaces: assert_raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['white', 'pial']) assert_raises(TypeError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=[1]) assert_raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['foo']) mlab.close(all=True)
def test_plot_trans(): """Test plotting of -trans.fif files and MEG sensor layouts.""" mlab = _import_mlab() evoked = read_evokeds(evoked_fname)[0] sample_src = read_source_spaces(src_fname) with warnings.catch_warnings(record=True): # 4D weight tables bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True, preload=False).info infos = dict( Neuromag=evoked.info, CTF=read_raw_ctf(ctf_fname).info, BTi=bti, KIT=read_raw_kit(sqd_fname).info, ) for system, info in infos.items(): ref_meg = False if system == 'KIT' else True plot_trans(info, trans_fname, subject='sample', meg_sensors=True, subjects_dir=subjects_dir, ref_meg=ref_meg) mlab.close(all=True) # KIT ref sensor coil def is defined plot_trans(infos['KIT'], None, meg_sensors=True, ref_meg=True) mlab.close(all=True) info = infos['Neuromag'] assert_raises(ValueError, plot_trans, info, trans_fname, subject='sample', subjects_dir=subjects_dir, ch_type='bad-chtype') assert_raises(TypeError, plot_trans, 'foo', trans_fname, subject='sample', subjects_dir=subjects_dir) assert_raises(TypeError, plot_trans, info, trans_fname, subject='sample', subjects_dir=subjects_dir, src='foo') assert_raises(ValueError, plot_trans, info, trans_fname, subject='fsaverage', subjects_dir=subjects_dir, src=sample_src) sample_src.plot(subjects_dir=subjects_dir) mlab.close(all=True) # no-head version plot_trans(info, None, meg_sensors=True, dig=True, coord_frame='head') mlab.close(all=True) # all coord frames for coord_frame in ('meg', 'head', 'mri'): plot_trans(info, meg_sensors=True, dig=True, coord_frame=coord_frame, trans=trans_fname, subject='sample', subjects_dir=subjects_dir) mlab.close(all=True) # EEG only with strange options evoked_eeg_ecog = evoked.copy().pick_types(meg=False, eeg=True) evoked_eeg_ecog.info['projs'] = [] # "remove" avg proj evoked_eeg_ecog.set_channel_types({'EEG 001': 'ecog'}) with warnings.catch_warnings(record=True) as w: plot_trans(evoked_eeg_ecog.info, subject='sample', trans=trans_fname, source='outer_skin', meg_sensors=True, skull=True, eeg_sensors=['original', 'projected'], ecog_sensors=True, brain='white', head=True, subjects_dir=subjects_dir) mlab.close(all=True) assert_true(['Cannot plot MEG' in str(ww.message) for ww in w])
def test_plot_alignment(tmpdir, backends_3d): """Test plotting of -trans.fif files and MEG sensor layouts.""" backend_name = get_3d_backend() # generate fiducials file for testing tempdir = str(tmpdir) fiducials_path = op.join(tempdir, 'fiducials.fif') fid = [{ 'coord_frame': 5, 'ident': 1, 'kind': 1, 'r': [-0.08061612, -0.02908875, -0.04131077] }, { 'coord_frame': 5, 'ident': 2, 'kind': 1, 'r': [0.00146763, 0.08506715, -0.03483611] }, { 'coord_frame': 5, 'ident': 3, 'kind': 1, 'r': [0.08436285, -0.02850276, -0.04127743] }] write_dig(fiducials_path, fid, 5) if backend_name == 'mayavi': mlab = _import_mlab() evoked = read_evokeds(evoked_fname)[0] sample_src = read_source_spaces(src_fname) bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True, preload=False).info infos = dict( Neuromag=evoked.info, CTF=read_raw_ctf(ctf_fname).info, BTi=bti, KIT=read_raw_kit(sqd_fname).info, ) for system, info in infos.items(): meg = ['helmet', 'sensors'] if system == 'KIT': meg.append('ref') plot_alignment(info, trans_fname, subject='sample', subjects_dir=subjects_dir, meg=meg) if backend_name == 'mayavi': mlab.close(all=True) # KIT ref sensor coil def is defined if backend_name == 'mayavi': mlab.close(all=True) info = infos['Neuromag'] pytest.raises(TypeError, plot_alignment, 'foo', trans_fname, subject='sample', subjects_dir=subjects_dir) pytest.raises(OSError, plot_alignment, info, trans_fname, subject='sample', subjects_dir=subjects_dir, src='foo') pytest.raises(ValueError, plot_alignment, info, trans_fname, subject='fsaverage', subjects_dir=subjects_dir, src=sample_src) sample_src.plot(subjects_dir=subjects_dir, head=True, skull=True, brain='white') if backend_name == 'mayavi': mlab.close(all=True) # no-head version if backend_name == 'mayavi': mlab.close(all=True) # all coord frames pytest.raises(ValueError, plot_alignment, info) plot_alignment(info, surfaces=[]) for coord_frame in ('meg', 'head', 'mri'): plot_alignment(info, meg=['helmet', 'sensors'], dig=True, coord_frame=coord_frame, trans=trans_fname, subject='sample', mri_fiducials=fiducials_path, subjects_dir=subjects_dir, src=src_fname) if backend_name == 'mayavi': mlab.close(all=True) # EEG only with strange options evoked_eeg_ecog_seeg = evoked.copy().pick_types(meg=False, eeg=True) evoked_eeg_ecog_seeg.info['projs'] = [] # "remove" avg proj evoked_eeg_ecog_seeg.set_channel_types({ 'EEG 001': 'ecog', 'EEG 002': 'seeg' }) with pytest.warns(RuntimeWarning, match='Cannot plot MEG'): plot_alignment(evoked_eeg_ecog_seeg.info, subject='sample', trans=trans_fname, subjects_dir=subjects_dir, surfaces=['white', 'outer_skin', 'outer_skull'], meg=['helmet', 'sensors'], eeg=['original', 'projected'], ecog=True, seeg=True) if backend_name == 'mayavi': mlab.close(all=True) sphere = make_sphere_model(info=evoked.info, r0='auto', head_radius='auto') bem_sol = read_bem_solution( op.join(subjects_dir, 'sample', 'bem', 'sample-1280-1280-1280-bem-sol.fif')) bem_surfs = read_bem_surfaces( op.join(subjects_dir, 'sample', 'bem', 'sample-1280-1280-1280-bem.fif')) sample_src[0]['coord_frame'] = 4 # hack for coverage plot_alignment( info, subject='sample', eeg='projected', meg='helmet', bem=sphere, dig=True, surfaces=['brain', 'inner_skull', 'outer_skull', 'outer_skin']) plot_alignment(info, trans_fname, subject='sample', meg='helmet', subjects_dir=subjects_dir, eeg='projected', bem=sphere, surfaces=['head', 'brain'], src=sample_src) assert all(surf['coord_frame'] == FIFF.FIFFV_COORD_MRI for surf in bem_sol['surfs']) plot_alignment(info, trans_fname, subject='sample', meg=[], subjects_dir=subjects_dir, bem=bem_sol, eeg=True, surfaces=['head', 'inflated', 'outer_skull', 'inner_skull']) assert all(surf['coord_frame'] == FIFF.FIFFV_COORD_MRI for surf in bem_sol['surfs']) plot_alignment(info, trans_fname, subject='sample', meg=True, subjects_dir=subjects_dir, surfaces=['head', 'inner_skull'], bem=bem_surfs) sphere = make_sphere_model('auto', 'auto', evoked.info) src = setup_volume_source_space(sphere=sphere) plot_alignment( info, eeg='projected', meg='helmet', bem=sphere, src=src, dig=True, surfaces=['brain', 'inner_skull', 'outer_skull', 'outer_skin']) sphere = make_sphere_model('auto', None, evoked.info) # one layer # no info is permitted fig = plot_alignment(trans=trans_fname, subject='sample', meg=False, coord_frame='mri', subjects_dir=subjects_dir, surfaces=['brain'], bem=sphere, show_axes=True) if backend_name == 'mayavi': import mayavi # noqa: F401 analysis:ignore assert isinstance(fig, mayavi.core.scene.Scene) # 3D coil with no defined draw (ConvexHull) info_cube = pick_info(info, [0]) info['dig'] = None info_cube['chs'][0]['coil_type'] = 9999 with pytest.raises(RuntimeError, match='coil definition not found'): plot_alignment(info_cube, meg='sensors', surfaces=()) coil_def_fname = op.join(tempdir, 'temp') with open(coil_def_fname, 'w') as fid: fid.write(coil_3d) with use_coil_def(coil_def_fname): plot_alignment(info_cube, meg='sensors', surfaces=(), dig=True) # one layer bem with skull surfaces: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['brain', 'head', 'inner_skull'], bem=sphere) # wrong eeg value: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, eeg='foo') # wrong meg value: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, meg='bar') # multiple brain surfaces: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['white', 'pial']) pytest.raises(TypeError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=[1]) pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['foo']) if backend_name == 'mayavi': mlab.close(all=True)
def test_plot_alignment(tmpdir): """Test plotting of -trans.fif files and MEG sensor layouts.""" # generate fiducials file for testing tempdir = str(tmpdir) fiducials_path = op.join(tempdir, 'fiducials.fif') fid = [{'coord_frame': 5, 'ident': 1, 'kind': 1, 'r': [-0.08061612, -0.02908875, -0.04131077]}, {'coord_frame': 5, 'ident': 2, 'kind': 1, 'r': [0.00146763, 0.08506715, -0.03483611]}, {'coord_frame': 5, 'ident': 3, 'kind': 1, 'r': [0.08436285, -0.02850276, -0.04127743]}] write_dig(fiducials_path, fid, 5) mlab = _import_mlab() evoked = read_evokeds(evoked_fname)[0] sample_src = read_source_spaces(src_fname) bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True, preload=False).info infos = dict( Neuromag=evoked.info, CTF=read_raw_ctf(ctf_fname).info, BTi=bti, KIT=read_raw_kit(sqd_fname).info, ) for system, info in infos.items(): meg = ['helmet', 'sensors'] if system == 'KIT': meg.append('ref') plot_alignment(info, trans_fname, subject='sample', subjects_dir=subjects_dir, meg=meg) mlab.close(all=True) # KIT ref sensor coil def is defined mlab.close(all=True) info = infos['Neuromag'] pytest.raises(TypeError, plot_alignment, 'foo', trans_fname, subject='sample', subjects_dir=subjects_dir) pytest.raises(TypeError, plot_alignment, info, trans_fname, subject='sample', subjects_dir=subjects_dir, src='foo') pytest.raises(ValueError, plot_alignment, info, trans_fname, subject='fsaverage', subjects_dir=subjects_dir, src=sample_src) sample_src.plot(subjects_dir=subjects_dir, head=True, skull=True, brain='white') mlab.close(all=True) # no-head version mlab.close(all=True) # all coord frames pytest.raises(ValueError, plot_alignment, info) plot_alignment(info, surfaces=[]) for coord_frame in ('meg', 'head', 'mri'): plot_alignment(info, meg=['helmet', 'sensors'], dig=True, coord_frame=coord_frame, trans=trans_fname, subject='sample', mri_fiducials=fiducials_path, subjects_dir=subjects_dir, src=sample_src) mlab.close(all=True) # EEG only with strange options evoked_eeg_ecog_seeg = evoked.copy().pick_types(meg=False, eeg=True) evoked_eeg_ecog_seeg.info['projs'] = [] # "remove" avg proj evoked_eeg_ecog_seeg.set_channel_types({'EEG 001': 'ecog', 'EEG 002': 'seeg'}) with pytest.warns(RuntimeWarning, match='Cannot plot MEG'): plot_alignment(evoked_eeg_ecog_seeg.info, subject='sample', trans=trans_fname, subjects_dir=subjects_dir, surfaces=['white', 'outer_skin', 'outer_skull'], meg=['helmet', 'sensors'], eeg=['original', 'projected'], ecog=True, seeg=True) mlab.close(all=True) sphere = make_sphere_model(info=evoked.info, r0='auto', head_radius='auto') bem_sol = read_bem_solution(op.join(subjects_dir, 'sample', 'bem', 'sample-1280-1280-1280-bem-sol.fif')) bem_surfs = read_bem_surfaces(op.join(subjects_dir, 'sample', 'bem', 'sample-1280-1280-1280-bem.fif')) sample_src[0]['coord_frame'] = 4 # hack for coverage plot_alignment(info, subject='sample', eeg='projected', meg='helmet', bem=sphere, dig=True, surfaces=['brain', 'inner_skull', 'outer_skull', 'outer_skin']) plot_alignment(info, trans_fname, subject='sample', meg='helmet', subjects_dir=subjects_dir, eeg='projected', bem=sphere, surfaces=['head', 'brain'], src=sample_src) assert all(surf['coord_frame'] == FIFF.FIFFV_COORD_MRI for surf in bem_sol['surfs']) plot_alignment(info, trans_fname, subject='sample', meg=[], subjects_dir=subjects_dir, bem=bem_sol, eeg=True, surfaces=['head', 'inflated', 'outer_skull', 'inner_skull']) assert all(surf['coord_frame'] == FIFF.FIFFV_COORD_MRI for surf in bem_sol['surfs']) plot_alignment(info, trans_fname, subject='sample', meg=True, subjects_dir=subjects_dir, surfaces=['head', 'inner_skull'], bem=bem_surfs) sphere = make_sphere_model('auto', 'auto', evoked.info) src = setup_volume_source_space(sphere=sphere) plot_alignment(info, eeg='projected', meg='helmet', bem=sphere, src=src, dig=True, surfaces=['brain', 'inner_skull', 'outer_skull', 'outer_skin']) sphere = make_sphere_model('auto', None, evoked.info) # one layer plot_alignment(info, trans_fname, subject='sample', meg=False, coord_frame='mri', subjects_dir=subjects_dir, surfaces=['brain'], bem=sphere, show_axes=True) # 3D coil with no defined draw (ConvexHull) info_cube = pick_info(info, [0]) info['dig'] = None info_cube['chs'][0]['coil_type'] = 9999 with pytest.raises(RuntimeError, match='coil definition not found'): plot_alignment(info_cube, meg='sensors', surfaces=()) coil_def_fname = op.join(tempdir, 'temp') with open(coil_def_fname, 'w') as fid: fid.write(coil_3d) with use_coil_def(coil_def_fname): plot_alignment(info_cube, meg='sensors', surfaces=(), dig=True) # one layer bem with skull surfaces: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['brain', 'head', 'inner_skull'], bem=sphere) # wrong eeg value: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, eeg='foo') # wrong meg value: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, meg='bar') # multiple brain surfaces: pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['white', 'pial']) pytest.raises(TypeError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=[1]) pytest.raises(ValueError, plot_alignment, info=info, trans=trans_fname, subject='sample', subjects_dir=subjects_dir, surfaces=['foo']) mlab.close(all=True)
def test_plot_trans(): """Test plotting of -trans.fif files and MEG sensor layouts.""" # generate fiducials file for testing tempdir = _TempDir() fiducials_path = op.join(tempdir, 'fiducials.fif') fid = [{ 'coord_frame': 5, 'ident': 1, 'kind': 1, 'r': [-0.08061612, -0.02908875, -0.04131077] }, { 'coord_frame': 5, 'ident': 2, 'kind': 1, 'r': [0.00146763, 0.08506715, -0.03483611] }, { 'coord_frame': 5, 'ident': 3, 'kind': 1, 'r': [0.08436285, -0.02850276, -0.04127743] }] write_dig(fiducials_path, fid, 5) mlab = _import_mlab() evoked = read_evokeds(evoked_fname)[0] sample_src = read_source_spaces(src_fname) with warnings.catch_warnings(record=True): # 4D weight tables bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True, preload=False).info infos = dict( Neuromag=evoked.info, CTF=read_raw_ctf(ctf_fname).info, BTi=bti, KIT=read_raw_kit(sqd_fname).info, ) for system, info in infos.items(): ref_meg = False if system == 'KIT' else True plot_trans(info, trans_fname, subject='sample', meg_sensors=True, subjects_dir=subjects_dir, ref_meg=ref_meg) mlab.close(all=True) # KIT ref sensor coil def is defined plot_trans(infos['KIT'], None, meg_sensors=True, ref_meg=True) mlab.close(all=True) info = infos['Neuromag'] assert_raises(ValueError, plot_trans, info, trans_fname, subject='sample', subjects_dir=subjects_dir, ch_type='bad-chtype') assert_raises(TypeError, plot_trans, 'foo', trans_fname, subject='sample', subjects_dir=subjects_dir) assert_raises(TypeError, plot_trans, info, trans_fname, subject='sample', subjects_dir=subjects_dir, src='foo') assert_raises(ValueError, plot_trans, info, trans_fname, subject='fsaverage', subjects_dir=subjects_dir, src=sample_src) sample_src.plot(subjects_dir=subjects_dir) mlab.close(all=True) # no-head version plot_trans(info, None, meg_sensors=True, dig=True, coord_frame='head') mlab.close(all=True) # all coord frames for coord_frame in ('meg', 'head', 'mri'): plot_trans(info, meg_sensors=True, dig=True, coord_frame=coord_frame, trans=trans_fname, subject='sample', mri_fiducials=fiducials_path, subjects_dir=subjects_dir) mlab.close(all=True) # EEG only with strange options evoked_eeg_ecog = evoked.copy().pick_types(meg=False, eeg=True) evoked_eeg_ecog.info['projs'] = [] # "remove" avg proj evoked_eeg_ecog.set_channel_types({'EEG 001': 'ecog'}) with warnings.catch_warnings(record=True) as w: plot_trans(evoked_eeg_ecog.info, subject='sample', trans=trans_fname, source='outer_skin', meg_sensors=True, skull=True, eeg_sensors=['original', 'projected'], ecog_sensors=True, brain='white', head=True, subjects_dir=subjects_dir) mlab.close(all=True) assert_true(['Cannot plot MEG' in str(ww.message) for ww in w])
def test_plot_trans(): """Test plotting of -trans.fif files and MEG sensor layouts.""" # generate fiducials file for testing tempdir = _TempDir() fiducials_path = op.join(tempdir, 'fiducials.fif') fid = [{'coord_frame': 5, 'ident': 1, 'kind': 1, 'r': [-0.08061612, -0.02908875, -0.04131077]}, {'coord_frame': 5, 'ident': 2, 'kind': 1, 'r': [0.00146763, 0.08506715, -0.03483611]}, {'coord_frame': 5, 'ident': 3, 'kind': 1, 'r': [0.08436285, -0.02850276, -0.04127743]}] write_dig(fiducials_path, fid, 5) mlab = _import_mlab() evoked = read_evokeds(evoked_fname)[0] sample_src = read_source_spaces(src_fname) with warnings.catch_warnings(record=True): # 4D weight tables bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True, preload=False).info infos = dict( Neuromag=evoked.info, CTF=read_raw_ctf(ctf_fname).info, BTi=bti, KIT=read_raw_kit(sqd_fname).info, ) for system, info in infos.items(): ref_meg = False if system == 'KIT' else True plot_trans(info, trans_fname, subject='sample', meg_sensors=True, subjects_dir=subjects_dir, ref_meg=ref_meg) mlab.close(all=True) # KIT ref sensor coil def is defined plot_trans(infos['KIT'], None, meg_sensors=True, ref_meg=True) mlab.close(all=True) info = infos['Neuromag'] assert_raises(TypeError, plot_trans, 'foo', trans_fname, subject='sample', subjects_dir=subjects_dir) assert_raises(TypeError, plot_trans, info, trans_fname, subject='sample', subjects_dir=subjects_dir, src='foo') assert_raises(ValueError, plot_trans, info, trans_fname, subject='fsaverage', subjects_dir=subjects_dir, src=sample_src) sample_src.plot(subjects_dir=subjects_dir) mlab.close(all=True) # no-head version plot_trans(info, None, meg_sensors=True, dig=True, coord_frame='head') mlab.close(all=True) # all coord frames for coord_frame in ('meg', 'head', 'mri'): plot_trans(info, meg_sensors=True, dig=True, coord_frame=coord_frame, trans=trans_fname, subject='sample', mri_fiducials=fiducials_path, subjects_dir=subjects_dir) mlab.close(all=True) # EEG only with strange options evoked_eeg_ecog = evoked.copy().pick_types(meg=False, eeg=True) evoked_eeg_ecog.info['projs'] = [] # "remove" avg proj evoked_eeg_ecog.set_channel_types({'EEG 001': 'ecog'}) with warnings.catch_warnings(record=True) as w: plot_trans(evoked_eeg_ecog.info, subject='sample', trans=trans_fname, source='outer_skin', meg_sensors=True, skull=True, eeg_sensors=['original', 'projected'], ecog_sensors=True, brain='white', head=True, subjects_dir=subjects_dir) mlab.close(all=True) assert_true(['Cannot plot MEG' in str(ww.message) for ww in w])