示例#1
0
def test_datasets_basic(tmpdir):
    """Test simple dataset functions."""
    # XXX 'hf_sef' and 'misc' do not conform to these standards
    for dname in ('sample', 'somato', 'spm_face', 'testing', 'opm',
                  'bst_raw', 'bst_auditory', 'bst_resting', 'multimodal',
                  'bst_phantom_ctf', 'bst_phantom_elekta', 'kiloword',
                  'mtrf', 'phantom_4dbti',
                  'visual_92_categories', 'fieldtrip_cmc'):
        if dname.startswith('bst'):
            dataset = getattr(datasets.brainstorm, dname)
            check_name = 'brainstorm.%s' % (dname,)
        else:
            dataset = getattr(datasets, dname)
            check_name = dname
        if dataset.data_path(download=False) != '':
            assert isinstance(dataset.get_version(), str)
            assert datasets.utils.has_dataset(check_name)
        else:
            assert dataset.get_version() is None
            assert not datasets.utils.has_dataset(check_name)
        print('%s: %s' % (dname, datasets.utils.has_dataset(check_name)))
    tempdir = str(tmpdir)
    # don't let it read from the config file to get the directory,
    # force it to look for the default
    with modified_env(**{'_MNE_FAKE_HOME_DIR': tempdir, 'SUBJECTS_DIR': None}):
        assert (datasets.utils._get_path(None, 'foo', 'bar') ==
                op.join(tempdir, 'mne_data'))
        assert get_subjects_dir(None) is None
        _set_montage_coreg_path()
        sd = get_subjects_dir()
        assert sd.endswith('MNE-fsaverage-data')
示例#2
0
def test_make_scalp_surfaces(tmpdir):
    """Test mne make_scalp_surfaces."""
    check_usage(mne_make_scalp_surfaces)
    has = 'SUBJECTS_DIR' in os.environ
    # Copy necessary files to avoid FreeSurfer call
    tempdir = str(tmpdir)
    surf_path = op.join(subjects_dir, 'sample', 'surf')
    surf_path_new = op.join(tempdir, 'sample', 'surf')
    os.mkdir(op.join(tempdir, 'sample'))
    os.mkdir(surf_path_new)
    subj_dir = op.join(tempdir, 'sample', 'bem')
    os.mkdir(subj_dir)
    shutil.copy(op.join(surf_path, 'lh.seghead'), surf_path_new)

    cmd = ('-s', 'sample', '--subjects-dir', tempdir)
    with modified_env(**{'_MNE_TESTING_SCALP': 'true'}):
        dense_fname = op.join(subj_dir, 'sample-head-dense.fif')
        medium_fname = op.join(subj_dir, 'sample-head-medium.fif')
        with ArgvSetter(cmd, disable_stdout=False, disable_stderr=False):
            with modified_env(FREESURFER_HOME=None):
                pytest.raises(RuntimeError, mne_make_scalp_surfaces.run)
            with modified_env(FREESURFER_HOME=tempdir):
                mne_make_scalp_surfaces.run()
                assert op.isfile(dense_fname)
                assert op.isfile(medium_fname)
                with pytest.raises(IOError, match='overwrite'):
                    mne_make_scalp_surfaces.run()
    # actually check the outputs
    head_py = read_bem_surfaces(dense_fname)
    assert_equal(len(head_py), 1)
    head_py = head_py[0]
    head_c = read_bem_surfaces(op.join(subjects_dir, 'sample', 'bem',
                                       'sample-head-dense.fif'))[0]
    assert_allclose(head_py['rr'], head_c['rr'])
    if not has:
        assert 'SUBJECTS_DIR' not in os.environ
示例#3
0
def test_setup_source_space_spacing(tmpdir, spacing):
    """Test setting up surface source spaces using a given spacing."""
    tempdir = str(tmpdir)
    copytree(op.join(subjects_dir, 'sample'), op.join(tempdir, 'sample'))
    args = [] if spacing == 7 else ['--spacing', str(spacing)]
    with modified_env(SUBJECTS_DIR=tempdir, SUBJECT='sample'):
        run_subprocess(['mne_setup_source_space'] + args)
    src = read_source_spaces(op.join(tempdir, 'sample', 'bem',
                                     'sample-%d-src.fif' % spacing))
    src_new = setup_source_space('sample', spacing=spacing, add_dist=False,
                                 subjects_dir=subjects_dir)
    _compare_source_spaces(src, src_new, mode='approx', nearest=True)
    # Degenerate conditions
    with pytest.raises(TypeError, match='spacing must be.*got.*float.*'):
        setup_source_space('sample', 7., subjects_dir=subjects_dir)
    with pytest.raises(ValueError, match='spacing must be >= 2, got 1'):
        setup_source_space('sample', 1, subjects_dir=subjects_dir)
def test_setup_source_space_spacing(tmpdir, spacing):
    """Test setting up surface source spaces using a given spacing."""
    copytree(op.join(subjects_dir, 'sample'), str(tmpdir.join('sample')))
    args = [] if spacing == 7 else ['--spacing', str(spacing)]
    with modified_env(SUBJECTS_DIR=str(tmpdir), SUBJECT='sample'):
        run_subprocess(['mne_setup_source_space'] + args)
    src = read_source_spaces(
        tmpdir.join('sample', 'bem', 'sample-%d-src.fif' % spacing))
    src_new = setup_source_space('sample',
                                 spacing=spacing,
                                 add_dist=False,
                                 subjects_dir=subjects_dir)
    _compare_source_spaces(src, src_new, mode='approx', nearest=True)
    # Degenerate conditions
    with pytest.raises(TypeError, match='spacing must be.*got.*float.*'):
        setup_source_space('sample', 7., subjects_dir=subjects_dir)
    with pytest.raises(ValueError, match='spacing must be >= 2, got 1'):
        setup_source_space('sample', 1, subjects_dir=subjects_dir)
def test_kit2fiff_gui(check_gui_ci, tmpdir):
    """Test Kit2Fiff GUI."""
    home_dir = str(tmpdir)
    with modified_env(_MNE_GUI_TESTING_MODE='true',
                      _MNE_FAKE_HOME_DIR=home_dir):
        from pyface.api import GUI
        gui = GUI()
        gui.process_events()

        ui, frame = mne.gui.kit2fiff()
        assert not frame.model.can_save
        assert frame.model.stim_threshold == 1.
        frame.model.stim_threshold = 10.
        frame.model.stim_chs = 'save this!'
        frame.save_config(home_dir)
        ui.dispose()

        gui.process_events()

        # test setting persistence
        ui, frame = mne.gui.kit2fiff()
        assert frame.model.stim_threshold == 10.
        assert frame.model.stim_chs == 'save this!'

        # set and reset marker file
        points = [[-0.084612, 0.021582, -0.056144],
                  [0.080425, 0.021995, -0.061171],
                  [-0.000787, 0.105530, 0.014168],
                  [-0.047943, 0.091835, 0.010240],
                  [0.042976, 0.094380, 0.010807]]
        assert_array_equal(frame.marker_panel.mrk1_obj.points, 0)
        assert_array_equal(frame.marker_panel.mrk3_obj.points, 0)
        frame.model.markers.mrk1.file = mrk_pre_path
        assert_allclose(frame.marker_panel.mrk1_obj.points, points, atol=1e-6)
        assert_allclose(frame.marker_panel.mrk3_obj.points, points, atol=1e-6)
        frame.marker_panel.mrk1_obj.label = True
        frame.marker_panel.mrk1_obj.label = False
        frame.kit2fiff_panel.clear_all = True
        assert_array_equal(frame.marker_panel.mrk1_obj.points, 0)
        assert_array_equal(frame.marker_panel.mrk3_obj.points, 0)
        ui.dispose()

        gui.process_events()
示例#6
0
def few_surfaces():
    """Set the _MNE_FEW_SURFACES env var."""
    with modified_env(_MNE_FEW_SURFACES='true'):
        yield
示例#7
0
def test_coreg_gui_display(tmpdir):
    """Test CoregFrame."""
    _check_ci()
    from mayavi import mlab
    from tvtk.api import tvtk
    home_dir = str(tmpdir)
    with modified_env(**{'_MNE_GUI_TESTING_MODE': 'true',
                         '_MNE_FAKE_HOME_DIR': home_dir}):
        with pytest.raises(ValueError, match='not a valid subject'):
            mne.gui.coregistration(subject='Elvis', subjects_dir=subjects_dir)

        # avoid modal dialog if SUBJECTS_DIR is set to a directory that
        # does not contain valid subjects
        ui, frame = mne.gui.coregistration(subjects_dir='')
        mlab.process_ui_events()
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir,
                                           subject='sample')
        mlab.process_ui_events()

        assert not frame.model.mri.fid_ok
        frame.model.mri.lpa = [[-0.06, 0, 0]]
        frame.model.mri.nasion = [[0, 0.05, 0]]
        frame.model.mri.rpa = [[0.08, 0, 0]]
        assert (frame.model.mri.fid_ok)
        frame.data_panel.raw_src.file = raw_path
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.SphereSource)
        frame.data_panel.view_options_panel.eeg_obj.project_to_surface = True
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.CylinderSource)
        mlab.process_ui_events()

        # grow hair (faster for low-res)
        assert frame.data_panel.view_options_panel.head_high_res
        frame.data_panel.view_options_panel.head_high_res = False
        frame.model.grow_hair = 40.

        # scale
        frame.coreg_panel.n_scale_params = 3
        frame.coreg_panel.scale_x_inc = True
        assert frame.model.scale_x == 101.
        frame.coreg_panel.scale_y_dec = True
        assert frame.model.scale_y == 99.

        # reset parameters
        frame.coreg_panel.reset_params = True
        assert_equal(frame.model.grow_hair, 0)
        assert not frame.data_panel.view_options_panel.head_high_res

        # configuration persistence
        assert (frame.model.prepare_bem_model)
        frame.model.prepare_bem_model = False
        frame.save_config(home_dir)
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir)
        assert not frame.model.prepare_bem_model
        assert not frame.data_panel.view_options_panel.head_high_res
        ui.dispose()
        mlab.process_ui_events()
示例#8
0
def test_combine_markers_panel(check_gui_ci):
    """Test CombineMarkersPanel."""
    from mne.gui._marker_gui import CombineMarkersPanel
    with modified_env(_MNE_GUI_TESTING_MODE='true'):
        CombineMarkersPanel()
示例#9
0
def test_coreg_gui_display(tmpdir):
    """Test CoregFrame."""
    _check_ci()
    from mayavi import mlab
    from tvtk.api import tvtk
    home_dir = str(tmpdir)
    with modified_env(**{
            '_MNE_GUI_TESTING_MODE': 'true',
            '_MNE_FAKE_HOME_DIR': home_dir
    }):
        with pytest.raises(ValueError, match='not a valid subject'):
            mne.gui.coregistration(subject='Elvis', subjects_dir=subjects_dir)

        # avoid modal dialog if SUBJECTS_DIR is set to a directory that
        # does not contain valid subjects
        ui, frame = mne.gui.coregistration(subjects_dir='')
        mlab.process_ui_events()
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir,
                                           subject='sample')
        mlab.process_ui_events()

        assert not frame.model.mri.fid_ok
        frame.model.mri.lpa = [[-0.06, 0, 0]]
        frame.model.mri.nasion = [[0, 0.05, 0]]
        frame.model.mri.rpa = [[0.08, 0, 0]]
        assert (frame.model.mri.fid_ok)
        frame.data_panel.raw_src.file = raw_path
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.SphereSource)
        frame.data_panel.view_options_panel.eeg_obj.project_to_surface = True
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.CylinderSource)
        mlab.process_ui_events()

        # grow hair (faster for low-res)
        assert frame.data_panel.view_options_panel.head_high_res
        frame.data_panel.view_options_panel.head_high_res = False
        frame.model.grow_hair = 40.

        # scale
        frame.coreg_panel.n_scale_params = 3
        frame.coreg_panel.scale_x_inc = True
        assert frame.model.scale_x == 101.
        frame.coreg_panel.scale_y_dec = True
        assert frame.model.scale_y == 99.

        # reset parameters
        frame.coreg_panel.reset_params = True
        assert_equal(frame.model.grow_hair, 0)
        assert not frame.data_panel.view_options_panel.head_high_res

        # configuration persistence
        assert (frame.model.prepare_bem_model)
        frame.model.prepare_bem_model = False
        frame.save_config(home_dir)
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir)
        assert not frame.model.prepare_bem_model
        assert not frame.data_panel.view_options_panel.head_high_res
        ui.dispose()
        mlab.process_ui_events()
示例#10
0
def test_coreg_gui_display(subjects_dir_tmp, check_gui_ci):
    """Test CoregFrame."""
    from mayavi import mlab
    from tvtk.api import tvtk
    home_dir = subjects_dir_tmp
    # Remove the two files that will make the fiducials okay via MNI estimation
    os.remove(
        op.join(subjects_dir_tmp, 'sample', 'bem', 'sample-fiducials.fif'))
    os.remove(
        op.join(subjects_dir_tmp, 'sample', 'mri', 'transforms',
                'talairach.xfm'))
    with modified_env(_MNE_GUI_TESTING_MODE='true',
                      _MNE_FAKE_HOME_DIR=home_dir):
        with pytest.raises(ValueError, match='not a valid subject'):
            mne.gui.coregistration(subject='Elvis',
                                   subjects_dir=subjects_dir_tmp)

        # avoid modal dialog if SUBJECTS_DIR is set to a directory that
        # does not contain valid subjects
        ui, frame = mne.gui.coregistration(subjects_dir='')
        mlab.process_ui_events()
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir_tmp,
                                           subject='sample')
        mlab.process_ui_events()

        assert not frame.model.mri.fid_ok
        frame.model.mri.lpa = [[-0.06, 0, 0]]
        frame.model.mri.nasion = [[0, 0.05, 0]]
        frame.model.mri.rpa = [[0.08, 0, 0]]
        assert frame.model.mri.fid_ok
        frame.data_panel.raw_src.file = raw_path
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.SphereSource)
        frame.data_panel.view_options_panel.eeg_obj.project_to_surface = True
        assert isinstance(frame.eeg_obj.glyph.glyph.glyph_source.glyph_source,
                          tvtk.CylinderSource)
        mlab.process_ui_events()

        # grow hair (faster for low-res)
        assert frame.data_panel.view_options_panel.head_high_res
        frame.data_panel.view_options_panel.head_high_res = False
        frame.model.grow_hair = 40.

        # scale
        frame.coreg_panel.n_scale_params = 3
        frame.coreg_panel.scale_x_inc = True
        assert frame.model.scale_x == 101.
        frame.coreg_panel.scale_y_dec = True
        assert frame.model.scale_y == 99.

        # reset parameters
        frame.coreg_panel.reset_params = True
        assert frame.model.grow_hair == 0
        assert not frame.data_panel.view_options_panel.head_high_res

        # configuration persistence
        assert (frame.model.prepare_bem_model)
        frame.model.prepare_bem_model = False
        frame.save_config(home_dir)
        ui.dispose()
        mlab.process_ui_events()

        ui, frame = mne.gui.coregistration(subjects_dir=subjects_dir_tmp)
        assert not frame.model.prepare_bem_model
        assert not frame.data_panel.view_options_panel.head_high_res
        ui.dispose()
        mlab.process_ui_events()