예제 #1
0
fid = open(subjs_fname, 'r')
subjs = [line.rstrip() for line in fid]
fid.close()

# generating source space frequency envelopes
for subj in subjs:
    raw_fname = data_dir + 'fifs/%s_rest_LP100_CP3_DS300_raw.fif' % subj
    fwd_fname = data_dir + 'analysis/rest/%s_rest_LP100_CP3_DS300_raw-5-fwd.fif' % subj
    forward = mne.read_forward_solution(fwd_fname, surf_ori=True)
    for l_freq, h_freq in bands:
        # we need to always reload raw because we bandpass and resample it
        raw = mne.fiff.Raw(raw_fname, preload=True)
        picks = mne.fiff.pick_channels_regexp(raw.info['ch_names'], 'M..-*')
        raw.filter(l_freq, h_freq, picks=picks)
        data_cov = mne.compute_raw_data_covariance(raw, picks=picks)
        weights = calculate_weights(forward, data_cov.data, reg=reg)
        # downsample to 1 Hz effective sampling resolution. Note that the paper did this after beamforming, but we are safe to do it here as long as we get the covariance matrices before that. It'll make it go faster this way
        raw.resample(1)
        # instead of getting the hilbert of the source space (costly), do the Hilbert first and compute the envelope later
        raw.apply_hilbert(picks, envelope=False)
        data, times = raw[picks, :]
        print 'Multiplying data by beamformer weights...'
        # get the abs() of Hilbert transform (Hilbert envelope)
        sol = abs(np.dot(weights, data))
        stc = mne.SourceEstimate(
            sol, [forward['src'][0]['vertno'], forward['src'][1]['vertno']],
            times[0],
            times[1] - times[0],
            subject=subj)
        stc.save(dir_out + 'lcmv-%dto%d-' % (l_freq, h_freq) + subj)
###############################################################################
# Generate noisy evoked data
picks = mne.fiff.pick_types(raw.info, meg=True)
iir_filter = iir_filter_raw(raw, order=5, picks=picks, tmin=60, tmax=180)
evoked = generate_evoked(fwd, stc, evoked_template, cov, snr)  # , iir_filter=iir_filter)
raw[:306, :ntimes] = evoked.data
raw = raw.crop(tmax=evoked.times[-1])
raw.save("t2-raw.fif")

raw2 = mne.fiff.Raw("t2-raw.fif")
cov = mne.compute_raw_data_covariance(raw2)

dsim = stc.in_label(labels[0])
pl.plot(dsim.data.T)

weights = ve.calculate_weights(fwd, cov, reg=0)

d, _ = raw2[:306, :]
sol = np.dot(weights, d)
src = mne.SourceEstimate(sol, (fwd["src"][0]["vertno"], fwd["src"][1]["vertno"]), tmin, tstep)

"""
# plotting the localized source
const = 1*10**-18
good_data = np.nonzero(abs(src.data[:,150])>const)
lv = np.nonzero(abs(src.lh_data[:,150])>const)
rv = np.nonzero(abs(src.rh_data[:,150])>const)
src.data = np.squeeze(src.data[np.ix_(good_data[0]),:])
src.vertno = [np.array([src.lh_vertno[lv[0][0]]]), np.array([src.rh_vertno[rv[0][0]]])]

# plotting the simulated source
예제 #3
0
fid = open(subjs_fname, "r")
subjs = [line.rstrip() for line in fid]
fid.close()

# generating source space frequency envelopes
for subj in subjs:
    raw_fname = data_dir + "fifs/%s_rest_LP100_CP3_DS300_raw.fif" % subj
    fwd_fname = data_dir + "analysis/rest/%s_rest_LP100_CP3_DS300_raw-5-fwd.fif" % subj
    forward = mne.read_forward_solution(fwd_fname, surf_ori=True)
    for l_freq, h_freq in bands:
        # we need to always reload raw because we bandpass and resample it
        raw = mne.fiff.Raw(raw_fname, preload=True)
        picks = mne.fiff.pick_channels_regexp(raw.info["ch_names"], "M..-*")
        raw.filter(l_freq, h_freq, picks=picks)
        data_cov = mne.compute_raw_data_covariance(raw, picks=picks)
        weights = calculate_weights(forward, data_cov.data, reg=reg)
        # downsample to 1 Hz effective sampling resolution. Note that the paper did this after beamforming, but we are safe to do it here as long as we get the covariance matrices before that. It'll make it go faster this way
        raw.resample(1)
        # instead of getting the hilbert of the source space (costly), do the Hilbert first and compute the envelope later
        raw.apply_hilbert(picks, envelope=False)
        data, times = raw[picks, :]
        print "Multiplying data by beamformer weights..."
        # get the abs() of Hilbert transform (Hilbert envelope)
        sol = abs(np.dot(weights, data))
        stc = mne.SourceEstimate(
            sol, [forward["src"][0]["vertno"], forward["src"][1]["vertno"]], times[0], times[1] - times[0], subject=subj
        )
        stc.save(dir_out + "lcmv-%dto%d-" % (l_freq, h_freq) + subj)

# # morph all subjects
# subject_to = 'fsaverage'
예제 #4
0
###############################################################################
# Generate noisy evoked data
picks = mne.fiff.pick_types(raw.info, meg=True)
iir_filter = iir_filter_raw(raw, order=5, picks=picks, tmin=60, tmax=180)
evoked = generate_evoked(fwd, stc, evoked_template, cov, snr) #, iir_filter=iir_filter)
raw[:306,:ntimes] = evoked.data
raw = raw.crop(tmax=evoked.times[-1])
raw.save('t2-raw.fif')

raw2 = mne.fiff.Raw('t2-raw.fif')
cov = mne.compute_raw_data_covariance(raw2)

dsim = stc.in_label(labels[0])
pl.plot(dsim.data.T)

weights = ve.calculate_weights(fwd, cov, reg=0)

d, _ = raw2[:306,:]
sol = np.dot(weights, d)
src = mne.SourceEstimate(sol, (fwd['src'][0]['vertno'], fwd['src'][1]['vertno']), tmin, tstep)

'''
# plotting the localized source
const = 1*10**-18
good_data = np.nonzero(abs(src.data[:,150])>const)
lv = np.nonzero(abs(src.lh_data[:,150])>const)
rv = np.nonzero(abs(src.rh_data[:,150])>const)
src.data = np.squeeze(src.data[np.ix_(good_data[0]),:])
src.vertno = [np.array([src.lh_vertno[lv[0][0]]]), np.array([src.rh_vertno[rv[0][0]]])]

# plotting the simulated source