def test_io_stc():
    """Test IO for STC files
    """
    stc = read_stc(fname)

    write_stc(op.join(tempdir, "tmp.stc"), stc['tmin'], stc['tstep'],
              stc['vertices'], stc['data'])
    stc2 = read_stc(op.join(tempdir, "tmp.stc"))

    assert_array_almost_equal(stc['data'], stc2['data'])
    assert_array_almost_equal(stc['tmin'], stc2['tmin'])
    assert_array_almost_equal(stc['vertices'], stc2['vertices'])
    assert_array_almost_equal(stc['tstep'], stc2['tstep'])
Esempio n. 2
0
def test_io_stc():
    """Test IO for STC files
    """
    stc = read_stc(fname)

    write_stc(op.join(tempdir, "tmp.stc"), stc['tmin'], stc['tstep'],
              stc['vertices'], stc['data'])
    stc2 = read_stc(op.join(tempdir, "tmp.stc"))

    assert_array_almost_equal(stc['data'], stc2['data'])
    assert_array_almost_equal(stc['tmin'], stc2['tmin'])
    assert_array_almost_equal(stc['vertices'], stc2['vertices'])
    assert_array_almost_equal(stc['tstep'], stc2['tstep'])
Esempio n. 3
0
def test_io_stc():
    """Test IO for STC files
    """
    stc = mne.read_stc(fname)

    mne.write_stc("tmp.stc", stc['tmin'], stc['tstep'],
                             stc['vertices'], stc['data'])
    stc2 = mne.read_stc("tmp.stc")

    assert_array_almost_equal(stc['data'], stc2['data'])
    assert_array_almost_equal(stc['tmin'], stc2['tmin'])
    assert_array_almost_equal(stc['vertices'], stc2['vertices'])
    assert_array_almost_equal(stc['tstep'], stc2['tstep'])
def test_io_stc():
    """Test IO for STC files
    """
    stc = mne.read_stc(fname)

    mne.write_stc("tmp.stc", stc['tmin'], stc['tstep'], stc['vertices'],
                  stc['data'])
    stc2 = mne.read_stc("tmp.stc")

    assert_array_almost_equal(stc['data'], stc2['data'])
    assert_array_almost_equal(stc['tmin'], stc2['tmin'])
    assert_array_almost_equal(stc['vertices'], stc2['vertices'])
    assert_array_almost_equal(stc['tstep'], stc2['tstep'])
lambda2 = 1.0 / snr ** 2
dSPM = True

# Load data
evoked = Evoked(fname_evoked, setno=setno, baseline=(None, 0))
forward = mne.read_forward_solution(fname_fwd)
noise_cov = mne.Covariance(fname_cov)

# Compute whitener from noise covariance matrix
whitener = noise_cov.get_whitener(evoked.info, mag_reg=0.1, grad_reg=0.1, eeg_reg=0.1, pca=True)
# Compute inverse solution
stc, K, W = mne.minimum_norm(evoked, forward, whitener, orientation="loose", method="dspm", snr=3, loose=0.2)

# Save result in stc files
lh_vertices = stc["inv"]["src"][0]["vertno"]
rh_vertices = stc["inv"]["src"][1]["vertno"]
lh_data = stc["sol"][: len(lh_vertices)]
rh_data = stc["sol"][-len(rh_vertices) :]

mne.write_stc("mne_dSPM_inverse-lh.stc", tmin=stc["tmin"], tstep=stc["tstep"], vertices=lh_vertices, data=lh_data)
mne.write_stc("mne_dSPM_inverse-rh.stc", tmin=stc["tmin"], tstep=stc["tstep"], vertices=rh_vertices, data=rh_data)

###############################################################################
# View activation time-series
times = stc["tmin"] + stc["tstep"] * np.arange(stc["sol"].shape[1])
pl.close("all")
pl.plot(1e3 * times, stc["sol"][::100, :].T)
pl.xlabel("time (ms)")
pl.ylabel("dSPM value")
pl.show()
setno = 0
snr = 3.0
lambda2 = 1.0 / snr ** 2
dSPM = True

# Load data
evoked = Evoked(fname_evoked, setno=setno, baseline=(None, 0))
inverse_operator = mne.read_inverse_operator(fname_inv)

# Compute inverse solution
res = mne.apply_inverse(evoked, inverse_operator, lambda2, dSPM)

# Save result in stc files
lh_vertices = res['inv']['src'][0]['vertno']
rh_vertices = res['inv']['src'][1]['vertno']
lh_data = res['sol'][:len(lh_vertices)]
rh_data = res['sol'][-len(rh_vertices):]

mne.write_stc('mne_dSPM_inverse-lh.stc', tmin=res['tmin'], tstep=res['tstep'],
               vertices=lh_vertices, data=lh_data)
mne.write_stc('mne_dSPM_inverse-rh.stc', tmin=res['tmin'], tstep=res['tstep'],
               vertices=rh_vertices, data=rh_data)

###############################################################################
# View activation time-series
times = res['tmin'] + res['tstep'] * np.arange(lh_data.shape[1])
pl.plot(1e3 * times, res['sol'][::100, :].T)
pl.xlabel('time (ms)')
pl.ylabel('dSPM value')
pl.show()