예제 #1
0
def test_morphing():
    stc = datasets.get_mne_stc()
    y = load.fiff.stc_ndvar(stc,
                            'sample',
                            'ico-5',
                            subjects_dir,
                            'dSPM',
                            name='src')

    # sample to fsaverage
    m = mne.compute_source_morph(stc, 'sample', 'fsaverage', subjects_dir)
    stc_fsa = m.apply(stc)
    y_fsa = morph_source_space(y, 'fsaverage')
    assert_array_equal(y_fsa.x, stc_fsa.data)
    stc_fsa_ndvar = load.fiff.stc_ndvar(stc_fsa,
                                        'fsaverage',
                                        'ico-5',
                                        subjects_dir,
                                        'dSPM',
                                        False,
                                        'src',
                                        parc=None)
    assert_dataobj_equal(stc_fsa_ndvar, y_fsa)

    # scaled to fsaverage
    y_scaled = datasets.get_mne_stc(True, subject='fsaverage_scaled')
    y_scaled_m = morph_source_space(y_scaled, 'fsaverage')
    assert y_scaled_m.source.subject == 'fsaverage'
    assert_array_equal(y_scaled_m.x, y_scaled.x)

    # scaled to fsaverage [masked]
    y_sub = y_scaled.sub(source='superiortemporal-lh')
    y_sub_m = morph_source_space(y_sub, 'fsaverage')
    assert y_sub_m.source.subject == 'fsaverage'
    assert_array_equal(y_sub_m.x, y_sub.x)
예제 #2
0
def test_xhemi():
    y = datasets.get_mne_stc(ndvar=True)
    data_dir = mne.datasets.sample.data_path()
    subjects_dir = os.path.join(data_dir, 'subjects')
    load.update_subjects_dir(y, subjects_dir)

    lh, rh = xhemi(y, mask=False)
    assert lh.source.rh_n == 0
    assert rh.source.rh_n == 0
    assert lh.max() == pytest.approx(10.80, abs=1e-2)
    assert rh.max() == pytest.approx(7.91, abs=1e-2)

    # volume source space
    ds = datasets.get_mne_sample(src='vol', ori='vector', hpf=1)
    y = ds[0, 'src']
    with pytest.raises(NotImplementedError):
        xhemi(y)
    # make symmetric
    coords = list(map(tuple, y.source.coordinates))
    index = [r == 0 or (-r, a, s) in coords for r, a, s in coords]
    y = y.sub(source=np.array(index))
    # test xhemi
    yl, yr = xhemi(y)
    assert yl.source == yr.source
    # test vector mirroring
    r, a, s = coords[10]
    assert r  # make sure it's not on midline
    for i_orig, coords in enumerate(y.source.coordinates):
        if tuple(coords) == (r, a, s):
            break
    for i_flipped, coords in enumerate(yr.source.coordinates):
        if tuple(coords) == (-r, a, s):
            break
    assert_array_equal(yr.x[i_flipped], y.x[i_orig] * [[-1], [1], [1]])
예제 #3
0
def test_glassbrain():
    ndvar = datasets.get_mne_stc(True, True)

    # source space only
    p = plot.GlassBrain(ndvar.source)
    p.close()

    # single time points
    ndvar_30 = ndvar.sub(time=0.030)
    p = plot.GlassBrain(ndvar_30)
    p.close()
    # without arrows
    p = plot.GlassBrain(ndvar_30, draw_arrows=False)
    p.close()

    # time series
    p = plot.GlassBrain(ndvar)
    p.set_time(.03)
    p.close()

    # masked data
    import numpy as np
    h = ndvar.sub(time=0.030)
    c =  6.15459575929912e-10  # precomputed _fast_abs_percentile(h)
    mask = h.norm('space') < c
    mask_x = np.repeat(h._ialign(mask), 3, h.get_axis('space'))
    mask = NDVar(mask_x, h.dims)
    y = h.mask(mask)
    p = plot.GlassBrain(y)
    p.close()
예제 #4
0
def test_glassbrain():
    ndvar = datasets.get_mne_stc(True, True)

    # source space only
    p = plot.GlassBrain(ndvar.source)
    p.close()

    # single time points
    ndvar_30 = ndvar.sub(time=0.030)
    p = plot.GlassBrain(ndvar_30)
    p.close()
    # without arrows
    p = plot.GlassBrain(ndvar_30, draw_arrows=False)
    p.close()

    # time series
    p = plot.GlassBrain(ndvar)
    p.set_time(.03)
    p.close()

    # masked data
    import numpy as np
    h = ndvar.sub(time=0.030)
    c = 6.15459575929912e-10  # precomputed _fast_abs_percentile(h)
    mask = h.norm('space') < c
    mask_x = np.repeat(h._ialign(mask), 3, h.get_axis('space'))
    mask = NDVar(mask_x, h.dims)
    y = h.mask(mask)
    p = plot.GlassBrain(y)
    p.close()
예제 #5
0
def test_xhemi():
    y = datasets.get_mne_stc(ndvar=True)
    data_dir = mne.datasets.sample.data_path()
    subjects_dir = os.path.join(data_dir, 'subjects')
    load.update_subjects_dir(y, subjects_dir)

    lh, rh = xhemi(y, mask=False)
    assert lh.source.rh_n == 0
    assert rh.source.rh_n == 0
    assert lh.max() == pytest.approx(10.80, abs=1e-2)
    assert rh.max() == pytest.approx(7.91, abs=1e-2)
예제 #6
0
def test_xhemi():
    y = datasets.get_mne_stc(ndvar=True)
    data_dir = mne.datasets.sample.data_path()
    subjects_dir = os.path.join(data_dir, 'subjects')
    load.update_subjects_dir(y, subjects_dir)

    lh, rh = xhemi(y, mask=False)
    assert lh.source.rh_n == 0
    assert rh.source.rh_n == 0
    assert lh.max() == pytest.approx(10.80, abs=1e-2)
    assert rh.max() == pytest.approx(7.91, abs=1e-2)
예제 #7
0
def test_plot_brain():
    """Test plot.brain plots"""
    if sys.platform.startswith('win'):
        pytest.xfail("Hangs on Appveyor")
    stc = datasets.get_mne_stc(True)

    # size
    b = plot.brain.brain(stc.source, hemi='rh', w=400, h=300, mask=False)
    assert b.screenshot().shape == (300, 400, 3)
    if sys.platform == 'linux':
        pytest.xfail("Brain.set_size() on Linux/Travis")
    b.set_size(200, 150)
    assert b.screenshot().shape == (150, 200, 3)
    b.close()
    # both hemispheres
    b = plot.brain.brain(stc.source, w=600, h=300, mask=False)
    assert b.screenshot().shape == (300, 600, 3)
    b.set_size(400, 150)
    assert b.screenshot().shape == (150, 400, 3)
    b.close()

    # plot shortcuts
    p = plot.brain.dspm(stc, mask=False)
    cb = p.plot_colorbar()
    cb.close()
    p.close()

    p = plot.brain.dspm(stc, hemi='lh', mask=False)
    cb = p.plot_colorbar()
    cb.close()
    p.close()

    p = plot.brain.cluster(stc, hemi='rh', views='parietal', mask=False)
    cb = p.plot_colorbar()
    cb.close()
    p.close()

    image = plot.brain.bin_table(stc, tstart=0.05, tstop=0.07, tstep=0.01, surf='white', mask=False)
    print(repr(image))
    print(image)

    # plot p-map
    pmap = NDVar(np.random.uniform(0, 1, stc.shape), stc.dims, _info.for_p_map(stc.info))
    p = plot.brain.p_map(pmap, stc, mask=False)
    cb = p.plot_colorbar()
    cb.close()
    p.close()

    # mask
    stcm = stc.mask(stc < 11)
    p = plot.brain.brain(stcm, mask=False)
    p.close()
예제 #8
0
def test_morphing():
    stc = datasets.get_mne_stc()
    y = load.fiff.stc_ndvar(stc, 'sample', 'ico-5', subjects_dir, 'dSPM', name='src')

    # sample to fsaverage
    m = mne.compute_source_morph(stc, 'sample', 'fsaverage', subjects_dir)
    stc_fsa = m.apply(stc)
    y_fsa = morph_source_space(y, 'fsaverage')
    assert_array_equal(y_fsa.x, stc_fsa.data)
    stc_fsa_ndvar = load.fiff.stc_ndvar(stc_fsa, 'fsaverage', 'ico-5', subjects_dir, 'dSPM', False, 'src', parc=None)
    assert_dataobj_equal(stc_fsa_ndvar, y_fsa)

    # scaled to fsaverage
    y_scaled = datasets.get_mne_stc(True, subject='fsaverage_scaled')
    y_scaled_m = morph_source_space(y_scaled, 'fsaverage')
    assert y_scaled_m.source.subject == 'fsaverage'
    assert_array_equal(y_scaled_m.x, y_scaled.x)

    # scaled to fsaverage [masked]
    y_sub = y_scaled.sub(source='superiortemporal-lh')
    y_sub_m = morph_source_space(y_sub, 'fsaverage')
    assert y_sub_m.source.subject == 'fsaverage'
    assert_array_equal(y_sub_m.x, y_sub.x)
예제 #9
0
def test_plot_butterfly():
    "Test plot.Butterfly"
    ds = datasets.get_uts(utsnd=True)
    p = plot.Butterfly('utsnd', ds=ds)
    p.close()
    p = plot.Butterfly('utsnd', 'A%B', ds=ds)
    p.close()

    # other y-dim
    stc = datasets.get_mne_stc(True, subject='fsaverage')
    p = plot.Butterfly(stc)
    p.close()

    # _ax_bfly_epoch (used in GUI, not part of a figure)
    fig = Figure(1)
    ax = _ax_bfly_epoch(fig._axes[0], ds[0, 'utsnd'])
    fig.show()
    ax.set_data(ds[1, 'utsnd'])
    fig.draw()

    # source space
    stc = datasets.get_mne_stc(True)
    p = plot.Butterfly(stc, '.source.hemi')
    p.close()
예제 #10
0
def test_plot_butterfly():
    "Test plot.Butterfly"
    ds = datasets.get_uts(utsnd=True)
    p = plot.Butterfly('utsnd', ds=ds, show=False)
    p.close()
    p = plot.Butterfly('utsnd', 'A%B', ds=ds, show=False)
    p.close()

    # other y-dim
    stc = datasets.get_mne_stc(True)
    p = plot.Butterfly(stc, show=False)
    p.close()

    # _ax_bfly_epoch (used in GUI, not part of a figure)
    fig = Figure(1, show=False)
    ax = _ax_bfly_epoch(fig._axes[0], ds[0, 'utsnd'])
    fig.show()
    ax.set_data(ds[1, 'utsnd'])
    fig.draw()
예제 #11
0
def test_plot_butterfly():
    "Test plot.Butterfly"
    ds = datasets.get_uts(utsnd=True)
    p = plot.Butterfly('utsnd', ds=ds, show=False)
    p.close()
    p = plot.Butterfly('utsnd', 'A%B', ds=ds, show=False)
    p.close()

    # other y-dim
    stc = datasets.get_mne_stc(True)
    p = plot.Butterfly(stc)
    p.close()

    # _ax_bfly_epoch
    fig = Figure(1, show=False)
    ax = _ax_bfly_epoch(fig._axes[0], ds[0, 'utsnd'])
    fig.show()
    ax.set_data(ds[1, 'utsnd'])
    fig.draw()
예제 #12
0
def test_ndvar_indexing():
    ds = datasets.get_uts(utsnd=True)
    x = ds['utsnd']

    # case
    test_ndvar_index(x, 'case', 1, 1)
    test_ndvar_index(x, 'case', [0, 3], [0, 3])
    test_ndvar_index(x, 'case', slice(0, 10, 2), slice(0, 10, 2))

    # sensor
    test_ndvar_index(x, 'sensor', '0', 0)
    test_ndvar_index(x, 'sensor', ['0', '2'], [0, 2])
    test_ndvar_index(x, 'sensor', slice('0', '2'), slice(0, 2))
    test_ndvar_index(x, 'sensor', 0, 0, False)
    test_ndvar_index(x, 'sensor', [0, 2], [0, 2], False)
    test_ndvar_index(x, 'sensor', slice(0, 2), slice(0, 2), False)

    # time
    test_ndvar_index(x, 'time', 0, 20)
    test_ndvar_index(x, 'time', 0.1, 30)
    test_ndvar_index(x, 'time', 0.102, 30, False)
    test_ndvar_index(x, 'time', [0, 0.1, 0.2], [20, 30, 40])
    test_ndvar_index(x, 'time', slice(0.1, None), slice(30, None))
    test_ndvar_index(x, 'time', slice(0.2), slice(40))
    test_ndvar_index(x, 'time', slice(0.202), slice(41), False)
    test_ndvar_index(x, 'time', slice(0.1, 0.2), slice(30, 40))
    test_ndvar_index(x, 'time', slice(0.102, 0.2), slice(31, 40), False)
    test_ndvar_index(x, 'time', slice(0.1, None, 0.1), slice(30, None, 10))
    test_ndvar_index(x, 'time', slice(0.1, None, 1), slice(30, None, 100))

    # Ordered
    x = cwt_morlet(ds['uts'], [8, 10, 13, 17])
    assert_raises(IndexError, x.__getitem__, (full_slice, 9))
    assert_raises(IndexError, x.__getitem__, (full_slice, 6))
    test_ndvar_index(x, 'frequency', 10, 1)
    test_ndvar_index(x, 'frequency', 10.1, 1, False)
    test_ndvar_index(x, 'frequency', 9.9, 1, False)
    test_ndvar_index(x, 'frequency', [8.1, 10.1], [0, 1], False)
    test_ndvar_index(x, 'frequency', slice(8, 13), slice(0, 2))
    test_ndvar_index(x, 'frequency', slice(8, 13.1), slice(0, 3), False)
    test_ndvar_index(x, 'frequency', slice(8, 13.1, 2), slice(0, 3, 2), False)

    # Categorial
    x = NDVar(x.x, ('case', Categorial('cat', ['8', '10', '13', '17']), x.time))
    assert_raises(TypeError, x.__getitem__, (full_slice, 9))
    assert_raises(IndexError, x.__getitem__, (full_slice, '9'))
    test_ndvar_index(x, 'cat', '13', 2)
    test_ndvar_index(x, 'cat', ['8', '13'], [0, 2])
    test_ndvar_index(x, 'cat', slice('8', '13'), slice(0, 2))
    test_ndvar_index(x, 'cat', slice('8', None, 2), slice(0, None, 2))

    # SourceSpace
    x = datasets.get_mne_stc(True)
    assert_raises(TypeError, x.__getitem__, slice('insula-rh'))
    assert_raises(TypeError, x.__getitem__, slice('insula-lh', 'insula-rh'))
    assert_raises(TypeError, x.__getitem__, ('insula-lh', 'insula-rh'))
    test_ndvar_index(x, 'source', 'L90', 90)
    test_ndvar_index(x, 'source', 'R90', 642 + 90)
    test_ndvar_index(x, 'source', ['L90', 'R90'], [90, 642 + 90])
    test_ndvar_index(x, 'source', slice('L90', 'R90'), slice(90, 642 + 90))
    test_ndvar_index(x, 'source', 90, 90, False)
    test_ndvar_index(x, 'source', [90, 95], [90, 95], False)
    test_ndvar_index(x, 'source', slice(90, 95), slice(90, 95), False)
    test_ndvar_index(x, 'source', 'insula-lh', x.source.parc == 'insula-lh', False)
    test_ndvar_index(x, 'source', ('insula-lh', 'insula-rh'),
                     x.source.parc.isin(('insula-lh', 'insula-rh')), False)
    n_lh = x.source.parc.endswith('lh').sum()
    test_ndvar_index(x, 'source', 'lh', slice(n_lh), False)
    test_ndvar_index(x, 'source', 'rh', slice(n_lh, None), False)

    # argmax
    x.x[10, 10] = 20
    eq_(x.argmax(), ('L10', 0.1))
    eq_(x[('L10', 0.1)], 20)
    eq_(x.sub(source='L10').argmax(), 0.1)
    eq_(x.sub(time=0.1).argmax(), 'L10')