本文整理汇总了Python中mne.pick_types_forward函数的典型用法代码示例。如果您正苦于以下问题:Python pick_types_forward函数的具体用法?Python pick_types_forward怎么用?Python pick_types_forward使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pick_types_forward函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_make_forward_solution_sphere
def test_make_forward_solution_sphere():
"""Test making a forward solution with a sphere model."""
temp_dir = _TempDir()
fname_src_small = op.join(temp_dir, 'sample-oct-2-src.fif')
src = setup_source_space('sample', 'oct2', subjects_dir=subjects_dir,
add_dist=False)
write_source_spaces(fname_src_small, src) # to enable working with MNE-C
out_name = op.join(temp_dir, 'tmp-fwd.fif')
run_subprocess(['mne_forward_solution', '--meg', '--eeg',
'--meas', fname_raw, '--src', fname_src_small,
'--mri', fname_trans, '--fwd', out_name])
fwd = read_forward_solution(out_name)
sphere = make_sphere_model(verbose=True)
fwd_py = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=True, verbose=True)
_compare_forwards(fwd, fwd_py, 366, 108,
meg_rtol=5e-1, meg_atol=1e-6,
eeg_rtol=5e-1, eeg_atol=5e-1)
# Since the above is pretty lax, let's check a different way
for meg, eeg in zip([True, False], [False, True]):
fwd_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
fwd_py_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
assert_allclose(np.corrcoef(fwd_['sol']['data'].ravel(),
fwd_py_['sol']['data'].ravel())[0, 1],
1.0, rtol=1e-3)
开发者ID:olafhauk,项目名称:mne-python,代码行数:25,代码来源:test_make_forward.py
示例2: test_make_forward_solution_sphere
def test_make_forward_solution_sphere():
"""Test making a forward solution with a sphere model"""
temp_dir = _TempDir()
fname_src_small = op.join(temp_dir, "sample-oct-2-src.fif")
src = setup_source_space("sample", fname_src_small, "oct2", subjects_dir=subjects_dir, add_dist=False)
out_name = op.join(temp_dir, "tmp-fwd.fif")
run_subprocess(
[
"mne_forward_solution",
"--meg",
"--eeg",
"--meas",
fname_raw,
"--src",
fname_src_small,
"--mri",
fname_trans,
"--fwd",
out_name,
]
)
fwd = read_forward_solution(out_name)
sphere = make_sphere_model(verbose=True)
fwd_py = make_forward_solution(fname_raw, fname_trans, src, sphere, meg=True, eeg=True, verbose=True)
_compare_forwards(fwd, fwd_py, 366, 108, meg_rtol=5e-1, meg_atol=1e-6, eeg_rtol=5e-1, eeg_atol=5e-1)
# Since the above is pretty lax, let's check a different way
for meg, eeg in zip([True, False], [False, True]):
fwd_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
fwd_py_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
assert_allclose(np.corrcoef(fwd_["sol"]["data"].ravel(), fwd_py_["sol"]["data"].ravel())[0, 1], 1.0, rtol=1e-3)
开发者ID:mmagnuski,项目名称:mne-python,代码行数:30,代码来源:test_make_forward.py
示例3: test_psf_ctf
def test_psf_ctf():
"""Test computation of PSFs and CTFs for linear estimators
"""
inverse_operator = read_inverse_operator(fname_inv)
forward = read_forward_solution(fname_fwd, force_fixed=False,
surf_ori=True)
forward = pick_types_forward(forward, meg=True, eeg=False)
labels = [mne.read_label(ss) for ss in fname_label]
method = 'MNE'
n_svd_comp = 2
# Test PSFs (then CTFs)
for mode in ('sum', 'svd'):
stc_psf, psf_ev = point_spread_function(inverse_operator,
forward,
method=method,
labels=labels,
lambda2=lambda2,
pick_ori='normal',
mode=mode,
n_svd_comp=n_svd_comp)
n_vert, n_samples = stc_psf.shape
should_n_vert = (inverse_operator['src'][1]['vertno'].shape[0] +
inverse_operator['src'][0]['vertno'].shape[0])
if mode == 'svd':
should_n_samples = len(labels) * n_svd_comp + 1
else:
should_n_samples = len(labels) + 1
assert_true(n_vert == should_n_vert)
assert_true(n_samples == should_n_samples)
n_chan, n_samples = psf_ev.data.shape
assert_true(n_chan == forward['nchan'])
forward = read_forward_solution(fname_fwd, force_fixed=True, surf_ori=True)
forward = pick_types_forward(forward, meg=True, eeg=False)
# Test CTFs
for mode in ('sum', 'svd'):
stc_ctf = cross_talk_function(inverse_operator, forward,
labels, method=method,
lambda2=lambda2,
signed=False, mode=mode,
n_svd_comp=n_svd_comp)
n_vert, n_samples = stc_ctf.shape
should_n_vert = (inverse_operator['src'][1]['vertno'].shape[0] +
inverse_operator['src'][0]['vertno'].shape[0])
if mode == 'svd':
should_n_samples = len(labels) * n_svd_comp + 1
else:
should_n_samples = len(labels) + 1
assert_true(n_vert == should_n_vert)
assert_true(n_samples == should_n_samples)
开发者ID:LizetteH,项目名称:mne-python,代码行数:59,代码来源:test_psf_ctf.py
示例4: test_restrict_forward_to_label
def test_restrict_forward_to_label():
"""Test restriction of source space to label
"""
fwd = read_forward_solution(fname_meeg, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)
label_path = op.join(data_path, 'MEG', 'sample', 'labels')
labels = ['Aud-lh', 'Vis-rh']
label_lh = read_label(op.join(label_path, labels[0] + '.label'))
label_rh = read_label(op.join(label_path, labels[1] + '.label'))
fwd_out = restrict_forward_to_label(fwd, [label_lh, label_rh])
src_sel_lh = np.intersect1d(fwd['src'][0]['vertno'], label_lh.vertices)
src_sel_lh = np.searchsorted(fwd['src'][0]['vertno'], src_sel_lh)
vertno_lh = fwd['src'][0]['vertno'][src_sel_lh]
nuse_lh = fwd['src'][0]['nuse']
src_sel_rh = np.intersect1d(fwd['src'][1]['vertno'], label_rh.vertices)
src_sel_rh = np.searchsorted(fwd['src'][1]['vertno'], src_sel_rh)
vertno_rh = fwd['src'][1]['vertno'][src_sel_rh]
src_sel_rh += nuse_lh
assert_equal(fwd_out['sol']['ncol'], len(src_sel_lh) + len(src_sel_rh))
assert_equal(fwd_out['src'][0]['nuse'], len(src_sel_lh))
assert_equal(fwd_out['src'][1]['nuse'], len(src_sel_rh))
assert_equal(fwd_out['src'][0]['vertno'], vertno_lh)
assert_equal(fwd_out['src'][1]['vertno'], vertno_rh)
fwd = read_forward_solution(fname_meeg, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)
label_path = op.join(data_path, 'MEG', 'sample', 'labels')
labels = ['Aud-lh', 'Vis-rh']
label_lh = read_label(op.join(label_path, labels[0] + '.label'))
label_rh = read_label(op.join(label_path, labels[1] + '.label'))
fwd_out = restrict_forward_to_label(fwd, [label_lh, label_rh])
src_sel_lh = np.intersect1d(fwd['src'][0]['vertno'], label_lh.vertices)
src_sel_lh = np.searchsorted(fwd['src'][0]['vertno'], src_sel_lh)
vertno_lh = fwd['src'][0]['vertno'][src_sel_lh]
nuse_lh = fwd['src'][0]['nuse']
src_sel_rh = np.intersect1d(fwd['src'][1]['vertno'], label_rh.vertices)
src_sel_rh = np.searchsorted(fwd['src'][1]['vertno'], src_sel_rh)
vertno_rh = fwd['src'][1]['vertno'][src_sel_rh]
src_sel_rh += nuse_lh
assert_equal(fwd_out['sol']['ncol'],
3 * (len(src_sel_lh) + len(src_sel_rh)))
assert_equal(fwd_out['src'][0]['nuse'], len(src_sel_lh))
assert_equal(fwd_out['src'][1]['nuse'], len(src_sel_rh))
assert_equal(fwd_out['src'][0]['vertno'], vertno_lh)
assert_equal(fwd_out['src'][1]['vertno'], vertno_rh)
开发者ID:GrantRVD,项目名称:mne-python,代码行数:55,代码来源:test_forward.py
示例5: test_restrict_forward_to_stc
def test_restrict_forward_to_stc():
"""Test restriction of source space to source SourceEstimate
"""
start = 0
stop = 5
n_times = stop - start - 1
sfreq = 10.0
t_start = 0.123
fwd = read_forward_solution(fname_meeg)
fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=True,
use_cps=True)
fwd = pick_types_forward(fwd, meg=True)
vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
fwd_out = restrict_forward_to_stc(fwd, stc)
assert_true(isinstance(fwd_out, Forward))
assert_equal(fwd_out['sol']['ncol'], 20)
assert_equal(fwd_out['src'][0]['nuse'], 15)
assert_equal(fwd_out['src'][1]['nuse'], 5)
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])
fwd = read_forward_solution(fname_meeg)
fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)
vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
fwd_out = restrict_forward_to_stc(fwd, stc)
assert_equal(fwd_out['sol']['ncol'], 60)
assert_equal(fwd_out['src'][0]['nuse'], 15)
assert_equal(fwd_out['src'][1]['nuse'], 5)
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])
# Test saving the restricted forward object. This only works if all fields
# are properly accounted for.
temp_dir = _TempDir()
fname_copy = op.join(temp_dir, 'copy-fwd.fif')
with warnings.catch_warnings(record=True):
warnings.simplefilter('always')
write_forward_solution(fname_copy, fwd_out, overwrite=True)
fwd_out_read = read_forward_solution(fname_copy)
fwd_out_read = convert_forward_solution(fwd_out_read, surf_ori=True,
force_fixed=False)
compare_forwards(fwd_out, fwd_out_read)
开发者ID:HSMin,项目名称:mne-python,代码行数:54,代码来源:test_forward.py
示例6: test_gamma_map
def test_gamma_map():
"""Test Gamma MAP inverse"""
forward = read_forward_solution(fname_fwd, force_fixed=False,
surf_ori=True)
forward = pick_types_forward(forward, meg=False, eeg=True)
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0),
proj=False)
evoked.resample(50, npad=100)
evoked.crop(tmin=0.1, tmax=0.16) # crop to nice window near samp border
cov = read_cov(fname_cov)
cov = regularize(cov, evoked.info)
alpha = 0.5
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=True, update_mode=1)
_check_stc(stc, evoked, 68477)
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=1)
_check_stc(stc, evoked, 82010)
# force fixed orientation
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=2,
loose=None, return_residual=False)
_check_stc(stc, evoked, 85739, 20)
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:27,代码来源:test_gamma_map.py
示例7: _get_fwd_labels
def _get_fwd_labels():
fwd = read_forward_solution(fname_fwd)
fwd = convert_forward_solution(fwd, force_fixed=True, use_cps=True)
fwd = pick_types_forward(fwd, meg=True, eeg=False)
labels = [read_label(op.join(data_path, 'MEG', 'sample', 'labels',
'%s.label' % label)) for label in label_names]
return fwd, labels
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:7,代码来源:test_source.py
示例8: test_gamma_map
def test_gamma_map():
"""Test Gamma MAP inverse"""
forward = read_forward_solution(fname_fwd, force_fixed=False,
surf_ori=True)
forward = pick_types_forward(forward, meg=False, eeg=True)
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0))
evoked.resample(50)
evoked.crop(tmin=0, tmax=0.3)
cov = read_cov(fname_cov)
cov = regularize(cov, evoked.info)
alpha = 0.2
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-5,
xyz_same_gamma=True, update_mode=1, verbose=False)
idx = np.argmax(np.sum(stc.data ** 2, axis=1))
assert_true(np.concatenate(stc.vertices)[idx] == 96397)
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-5,
xyz_same_gamma=False, update_mode=1, verbose=False)
idx = np.argmax(np.sum(stc.data ** 2, axis=1))
assert_true(np.concatenate(stc.vertices)[idx] == 82010)
# force fixed orientation
stc, res = gamma_map(evoked, forward, cov, alpha, tol=1e-5,
xyz_same_gamma=False, update_mode=2,
loose=None, return_residual=True, verbose=False)
idx = np.argmax(np.sum(stc.data ** 2, axis=1))
# assert_true(np.concatenate(stc.vertices)[idx] == 83398) # XXX FIX
assert_array_almost_equal(evoked.times, res.times)
开发者ID:pombreda,项目名称:mne-python,代码行数:30,代码来源:test_gamma_map.py
示例9: test_gamma_map
def test_gamma_map():
"""Test Gamma MAP inverse"""
forward = read_forward_solution(fname_fwd)
forward = convert_forward_solution(forward, surf_ori=True)
forward = pick_types_forward(forward, meg=False, eeg=True)
evoked = read_evokeds(fname_evoked, condition=0, baseline=(None, 0),
proj=False)
evoked.resample(50, npad=100)
evoked.crop(tmin=0.1, tmax=0.16) # crop to window around peak
cov = read_cov(fname_cov)
cov = regularize(cov, evoked.info)
alpha = 0.5
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=True, update_mode=1)
_check_stc(stc, evoked, 68477)
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=1)
_check_stc(stc, evoked, 82010)
dips = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=1,
return_as_dipoles=True)
assert_true(isinstance(dips[0], Dipole))
stc_dip = make_stc_from_dipoles(dips, forward['src'])
_check_stcs(stc, stc_dip)
# force fixed orientation
stc = gamma_map(evoked, forward, cov, alpha, tol=1e-4,
xyz_same_gamma=False, update_mode=2,
loose=0, return_residual=False)
_check_stc(stc, evoked, 85739, 20)
开发者ID:nfoti,项目名称:mne-python,代码行数:35,代码来源:test_gamma_map.py
示例10: test_simulate_evoked
def test_simulate_evoked():
""" Test simulation of evoked data """
raw = Raw(raw_fname)
fwd = read_forward_solution(fwd_fname, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True, eeg=True, exclude=raw.info['bads'])
cov = read_cov(cov_fname)
evoked_template = read_evokeds(ave_fname, condition=0, baseline=None)
evoked_template.pick_types(meg=True, eeg=True, exclude=raw.info['bads'])
snr = 6 # dB
tmin = -0.1
sfreq = 1000. # Hz
tstep = 1. / sfreq
n_samples = 600
times = np.linspace(tmin, tmin + n_samples * tstep, n_samples)
# Generate times series for 2 dipoles
stc = simulate_sparse_stc(fwd['src'], n_dipoles=2, times=times)
stc._data *= 1e-9
# Generate noisy evoked data
iir_filter = [1, -0.9]
evoked = simulate_evoked(fwd, stc, evoked_template.info, cov, snr,
tmin=0.0, tmax=0.2, iir_filter=iir_filter)
assert_array_almost_equal(evoked.times, stc.times)
assert_true(len(evoked.data) == len(fwd['sol']['data']))
# make a vertex that doesn't exist in fwd, should throw error
stc_bad = stc.copy()
mv = np.max(fwd['src'][0]['vertno'][fwd['src'][0]['inuse']])
stc_bad.vertices[0][0] = mv + 1
assert_raises(RuntimeError, simulate_evoked, fwd, stc_bad,
evoked_template.info, cov, snr, tmin=0.0, tmax=0.2)
evoked_1 = simulate_evoked(fwd, stc, evoked_template.info, cov, np.inf,
tmin=0.0, tmax=0.2)
evoked_2 = simulate_evoked(fwd, stc, evoked_template.info, cov, np.inf,
tmin=0.0, tmax=0.2)
assert_array_equal(evoked_1.data, evoked_2.data)
# test snr definition in dB
evoked_noise = simulate_evoked(fwd, stc, evoked_template.info, cov,
snr=snr, tmin=None, tmax=None,
iir_filter=None)
evoked_clean = simulate_evoked(fwd, stc, evoked_template.info, cov,
snr=np.inf, tmin=None, tmax=None,
iir_filter=None)
noise = evoked_noise.data - evoked_clean.data
empirical_snr = 10 * np.log10(np.mean((evoked_clean.data ** 2).ravel()) /
np.mean((noise ** 2).ravel()))
assert_almost_equal(snr, empirical_snr, decimal=5)
cov['names'] = cov.ch_names[:-2] # Error channels are different.
assert_raises(ValueError, simulate_evoked, fwd, stc, evoked_template.info,
cov, snr=3., tmin=None, tmax=None, iir_filter=None)
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:59,代码来源:test_evoked.py
示例11: apply_inverse
def apply_inverse(fnevo, method='dSPM', snr=3.0, event='LLst',
baseline=False, btmin=-0.3, btmax=-0.1, min_subject='fsaverage'):
'''
Parameter
---------
fnevo: string or list
The evoked file with ECG, EOG and environmental noise free.
method: inverse method, 'MNE' or 'dSPM'
event: string
The event name related with epochs.
min_subject: string
The subject name as the common brain.
snr: signal to noise ratio for inverse solution.
'''
#Get the default subjects_dir
from mne.minimum_norm import apply_inverse
fnlist = get_files_from_list(fnevo)
# loop across all filenames
for fname in fnlist:
fn_path = os.path.split(fname)[0]
name = os.path.basename(fname)
stc_name = name[:name.rfind('-ave.fif')]
subject = name.split('_')[0]
subject_path = subjects_dir + '/%s' %subject
min_dir = subjects_dir + '/%s' %min_subject
fn_trans = fn_path + '/%s-trans.fif' % subject
fn_cov = fn_path + '/%s_empty,nr-cov.fif' % subject
fn_src = subject_path + '/bem/%s-ico-5-src.fif' % subject
fn_bem = subject_path + '/bem/%s-5120-5120-5120-bem-sol.fif' % subject
snr = snr
lambda2 = 1.0 / snr ** 2
#noise_cov = mne.read_cov(fn_cov)
[evoked] = mne.read_evokeds(fname)
noise_cov = mne.read_cov(fn_cov)
# this path used for ROI definition
stc_path = min_dir + '/%s_ROIs/%s' %(method,subject)
#fn_cov = meg_path + '/%s_empty,fibp1-45,nr-cov.fif' % subject
set_directory(stc_path)
noise_cov = mne.cov.regularize(noise_cov, evoked.info,
mag=0.05, grad=0.05, proj=True)
fwd_ev = mne.make_forward_solution(evoked.info, trans=fn_trans,
src=fn_src, bem=fn_bem,
fname=None, meg=True, eeg=False,
mindist=5.0, n_jobs=2,
overwrite=True)
fwd_ev = mne.convert_forward_solution(fwd_ev, surf_ori=True)
forward_meg_ev = mne.pick_types_forward(fwd_ev, meg=True, eeg=False)
inverse_operator_ev = mne.minimum_norm.make_inverse_operator(
evoked.info, forward_meg_ev, noise_cov,
loose=0.2, depth=0.8)
# Compute inverse solution
stc = apply_inverse(evoked, inverse_operator_ev, lambda2, method,
pick_ori=None)
# Morph STC
stc_morph = mne.morph_data(subject, min_subject, stc, grade=5, smooth=5)
stc_morph.save(stc_path + '/%s' % (stc_name), ftype='stc')
if baseline == True:
stc_base = stc_morph.crop(btmin, btmax)
stc_base.save(stc_path + '/%s_%s_baseline' % (subject, event), ftype='stc')
开发者ID:dongqunxi,项目名称:ChronoProc,代码行数:59,代码来源:cluster_ROIs.py
示例12: test_restrict_forward_to_label
def test_restrict_forward_to_label():
"""Test restriction of source space to label
"""
fwd = read_forward_solution(fname_meeg, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)
label_path = op.join(data_path, "MEG", "sample", "labels")
labels = ["Aud-lh", "Vis-rh"]
label_lh = read_label(op.join(label_path, labels[0] + ".label"))
label_rh = read_label(op.join(label_path, labels[1] + ".label"))
fwd_out = restrict_forward_to_label(fwd, [label_lh, label_rh])
src_sel_lh = np.intersect1d(fwd["src"][0]["vertno"], label_lh.vertices)
src_sel_lh = np.searchsorted(fwd["src"][0]["vertno"], src_sel_lh)
src_sel_rh = np.intersect1d(fwd["src"][1]["vertno"], label_rh.vertices)
src_sel_rh = np.searchsorted(fwd["src"][1]["vertno"], src_sel_rh) + len(fwd["src"][0]["vertno"])
assert_equal(fwd_out["sol"]["ncol"], len(src_sel_lh) + len(src_sel_rh))
assert_equal(fwd_out["src"][0]["nuse"], len(src_sel_lh))
assert_equal(fwd_out["src"][1]["nuse"], len(src_sel_rh))
assert_equal(fwd_out["src"][0]["vertno"], src_sel_lh)
assert_equal(fwd_out["src"][1]["vertno"], src_sel_rh)
fwd = read_forward_solution(fname_meeg, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)
label_path = op.join(data_path, "MEG", "sample", "labels")
labels = ["Aud-lh", "Vis-rh"]
label_lh = read_label(op.join(label_path, labels[0] + ".label"))
label_rh = read_label(op.join(label_path, labels[1] + ".label"))
fwd_out = restrict_forward_to_label(fwd, [label_lh, label_rh])
src_sel_lh = np.intersect1d(fwd["src"][0]["vertno"], label_lh.vertices)
src_sel_lh = np.searchsorted(fwd["src"][0]["vertno"], src_sel_lh)
src_sel_rh = np.intersect1d(fwd["src"][1]["vertno"], label_rh.vertices)
src_sel_rh = np.searchsorted(fwd["src"][1]["vertno"], src_sel_rh) + len(fwd["src"][0]["vertno"])
assert_equal(fwd_out["sol"]["ncol"], 3 * (len(src_sel_lh) + len(src_sel_rh)))
assert_equal(fwd_out["src"][0]["nuse"], len(src_sel_lh))
assert_equal(fwd_out["src"][1]["nuse"], len(src_sel_rh))
assert_equal(fwd_out["src"][0]["vertno"], src_sel_lh)
assert_equal(fwd_out["src"][1]["vertno"], src_sel_rh)
开发者ID:mdclarke,项目名称:mne-python,代码行数:46,代码来源:test_forward.py
示例13: test_simulate_evoked
def test_simulate_evoked():
"""Test simulation of evoked data."""
raw = read_raw_fif(raw_fname)
fwd = read_forward_solution(fwd_fname)
fwd = convert_forward_solution(fwd, force_fixed=True, use_cps=False)
fwd = pick_types_forward(fwd, meg=True, eeg=True, exclude=raw.info['bads'])
cov = read_cov(cov_fname)
evoked_template = read_evokeds(ave_fname, condition=0, baseline=None)
evoked_template.pick_types(meg=True, eeg=True, exclude=raw.info['bads'])
cov = regularize(cov, evoked_template.info)
nave = evoked_template.nave
tmin = -0.1
sfreq = 1000. # Hz
tstep = 1. / sfreq
n_samples = 600
times = np.linspace(tmin, tmin + n_samples * tstep, n_samples)
# Generate times series for 2 dipoles
stc = simulate_sparse_stc(fwd['src'], n_dipoles=2, times=times,
random_state=42)
# Generate noisy evoked data
iir_filter = [1, -0.9]
evoked = simulate_evoked(fwd, stc, evoked_template.info, cov,
iir_filter=iir_filter, nave=nave)
assert_array_almost_equal(evoked.times, stc.times)
assert_true(len(evoked.data) == len(fwd['sol']['data']))
assert_equal(evoked.nave, nave)
# make a vertex that doesn't exist in fwd, should throw error
stc_bad = stc.copy()
mv = np.max(fwd['src'][0]['vertno'][fwd['src'][0]['inuse']])
stc_bad.vertices[0][0] = mv + 1
assert_raises(RuntimeError, simulate_evoked, fwd, stc_bad,
evoked_template.info, cov)
evoked_1 = simulate_evoked(fwd, stc, evoked_template.info, cov,
nave=np.inf)
evoked_2 = simulate_evoked(fwd, stc, evoked_template.info, cov,
nave=np.inf)
assert_array_equal(evoked_1.data, evoked_2.data)
# Test the equivalence snr to nave
with warnings.catch_warnings(record=True): # deprecation
evoked = simulate_evoked(fwd, stc, evoked_template.info, cov,
snr=6, random_state=42)
assert_allclose(np.linalg.norm(evoked.data, ord='fro'),
0.00078346820226502716)
cov['names'] = cov.ch_names[:-2] # Error channels are different.
assert_raises(ValueError, simulate_evoked, fwd, stc, evoked_template.info,
cov, nave=nave, iir_filter=None)
开发者ID:nfoti,项目名称:mne-python,代码行数:56,代码来源:test_evoked.py
示例14: test_make_forward_solution_sphere
def test_make_forward_solution_sphere():
"""Test making a forward solution with a sphere model."""
temp_dir = _TempDir()
fname_src_small = op.join(temp_dir, 'sample-oct-2-src.fif')
src = setup_source_space('sample', 'oct2', subjects_dir=subjects_dir,
add_dist=False)
write_source_spaces(fname_src_small, src) # to enable working with MNE-C
out_name = op.join(temp_dir, 'tmp-fwd.fif')
run_subprocess(['mne_forward_solution', '--meg', '--eeg',
'--meas', fname_raw, '--src', fname_src_small,
'--mri', fname_trans, '--fwd', out_name])
fwd = read_forward_solution(out_name)
sphere = make_sphere_model(verbose=True)
fwd_py = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=True, verbose=True)
_compare_forwards(fwd, fwd_py, 366, 108,
meg_rtol=5e-1, meg_atol=1e-6,
eeg_rtol=5e-1, eeg_atol=5e-1)
# Since the above is pretty lax, let's check a different way
for meg, eeg in zip([True, False], [False, True]):
fwd_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
fwd_py_ = pick_types_forward(fwd, meg=meg, eeg=eeg)
assert_allclose(np.corrcoef(fwd_['sol']['data'].ravel(),
fwd_py_['sol']['data'].ravel())[0, 1],
1.0, rtol=1e-3)
# Number of layers in the sphere model doesn't matter for MEG
# (as long as no sources are omitted due to distance)
assert len(sphere['layers']) == 4
fwd = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=False)
sphere_1 = make_sphere_model(head_radius=None)
assert len(sphere_1['layers']) == 0
assert_array_equal(sphere['r0'], sphere_1['r0'])
fwd_1 = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=False)
_compare_forwards(fwd, fwd_1, 306, 108, meg_rtol=1e-12, meg_atol=1e-12)
# Homogeneous model
sphere = make_sphere_model(head_radius=None)
with pytest.raises(RuntimeError, match='zero shells.*EEG'):
make_forward_solution(fname_raw, fname_trans, src, sphere)
开发者ID:adykstra,项目名称:mne-python,代码行数:40,代码来源:test_make_forward.py
示例15: _load_forward
def _load_forward():
"""Load forward models."""
fwd_free = mne.read_forward_solution(fname_fwd)
fwd_free = mne.pick_types_forward(fwd_free, meg=True, eeg=False)
fwd_free = mne.convert_forward_solution(fwd_free, surf_ori=False)
fwd_surf = mne.convert_forward_solution(fwd_free, surf_ori=True,
use_cps=False)
fwd_fixed = mne.convert_forward_solution(fwd_free, force_fixed=True,
use_cps=False)
fwd_vol = mne.read_forward_solution(fname_fwd_vol)
label = mne.read_label(fname_label)
return fwd_free, fwd_surf, fwd_fixed, fwd_vol, label
开发者ID:jhouck,项目名称:mne-python,代码行数:13,代码来源:test_dics.py
示例16: test_restrict_forward_to_stc
def test_restrict_forward_to_stc():
"""Test restriction of source space to source SourceEstimate
"""
start = 0
stop = 5
n_times = stop - start - 1
sfreq = 10.0
t_start = 0.123
fwd = read_forward_solution(fname, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True)
vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
fwd_out = restrict_forward_to_stc(fwd, stc)
assert_true(isinstance(fwd_out, Forward))
assert_equal(fwd_out['sol']['ncol'], 20)
assert_equal(fwd_out['src'][0]['nuse'], 15)
assert_equal(fwd_out['src'][1]['nuse'], 5)
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])
fwd = read_forward_solution(fname, force_fixed=False)
fwd = pick_types_forward(fwd, meg=True)
vertno = [fwd['src'][0]['vertno'][0:15], fwd['src'][1]['vertno'][0:5]]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
fwd_out = restrict_forward_to_stc(fwd, stc)
assert_equal(fwd_out['sol']['ncol'], 60)
assert_equal(fwd_out['src'][0]['nuse'], 15)
assert_equal(fwd_out['src'][1]['nuse'], 5)
assert_equal(fwd_out['src'][0]['vertno'], fwd['src'][0]['vertno'][0:15])
assert_equal(fwd_out['src'][1]['vertno'], fwd['src'][1]['vertno'][0:5])
开发者ID:dengemann,项目名称:mne-python,代码行数:39,代码来源:test_forward.py
示例17: test_simulate_evoked
def test_simulate_evoked():
"""Test simulation of evoked data."""
raw = read_raw_fif(raw_fname)
fwd = read_forward_solution(fwd_fname)
fwd = convert_forward_solution(fwd, force_fixed=True, use_cps=False)
fwd = pick_types_forward(fwd, meg=True, eeg=True, exclude=raw.info['bads'])
cov = read_cov(cov_fname)
evoked_template = read_evokeds(ave_fname, condition=0, baseline=None)
evoked_template.pick_types(meg=True, eeg=True, exclude=raw.info['bads'])
cov = regularize(cov, evoked_template.info)
nave = evoked_template.nave
tmin = -0.1
sfreq = 1000. # Hz
tstep = 1. / sfreq
n_samples = 600
times = np.linspace(tmin, tmin + n_samples * tstep, n_samples)
# Generate times series for 2 dipoles
stc = simulate_sparse_stc(fwd['src'], n_dipoles=2, times=times,
random_state=42)
# Generate noisy evoked data
iir_filter = [1, -0.9]
evoked = simulate_evoked(fwd, stc, evoked_template.info, cov,
iir_filter=iir_filter, nave=nave)
assert_array_almost_equal(evoked.times, stc.times)
assert len(evoked.data) == len(fwd['sol']['data'])
assert_equal(evoked.nave, nave)
assert len(evoked.info['projs']) == len(cov['projs'])
evoked_white = whiten_evoked(evoked, cov)
assert abs(evoked_white.data[:, 0].std() - 1.) < 0.1
# make a vertex that doesn't exist in fwd, should throw error
stc_bad = stc.copy()
mv = np.max(fwd['src'][0]['vertno'][fwd['src'][0]['inuse']])
stc_bad.vertices[0][0] = mv + 1
pytest.raises(RuntimeError, simulate_evoked, fwd, stc_bad,
evoked_template.info, cov)
evoked_1 = simulate_evoked(fwd, stc, evoked_template.info, cov,
nave=np.inf)
evoked_2 = simulate_evoked(fwd, stc, evoked_template.info, cov,
nave=np.inf)
assert_array_equal(evoked_1.data, evoked_2.data)
cov['names'] = cov.ch_names[:-2] # Error channels are different.
with pytest.raises(RuntimeError, match='Not all channels present'):
simulate_evoked(fwd, stc, evoked_template.info, cov)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:51,代码来源:test_evoked.py
示例18: test_simulate_evoked
def test_simulate_evoked():
""" Test simulation of evoked data """
raw = Raw(raw_fname)
fwd = read_forward_solution(fwd_fname, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True, eeg=True, exclude=raw.info['bads'])
cov = read_cov(cov_fname)
label_names = ['Aud-lh', 'Aud-rh']
labels = [read_label(op.join(data_path, 'MEG', 'sample', 'labels',
'%s.label' % label)) for label in label_names]
evoked_template = read_evokeds(ave_fname, condition=0, baseline=None)
evoked_template = pick_types_evoked(evoked_template, meg=True, eeg=True,
exclude=raw.info['bads'])
snr = 6 # dB
tmin = -0.1
sfreq = 1000. # Hz
tstep = 1. / sfreq
n_samples = 600
times = np.linspace(tmin, tmin + n_samples * tstep, n_samples)
# Generate times series from 2 Morlet wavelets
stc_data = np.zeros((len(labels), len(times)))
Ws = morlet(sfreq, [3, 10], n_cycles=[1, 1.5])
stc_data[0][:len(Ws[0])] = np.real(Ws[0])
stc_data[1][:len(Ws[1])] = np.real(Ws[1])
stc_data *= 100 * 1e-9 # use nAm as unit
# time translation
stc_data[1] = np.roll(stc_data[1], 80)
stc = generate_sparse_stc(fwd['src'], labels, stc_data, tmin, tstep,
random_state=0)
# Generate noisy evoked data
iir_filter = [1, -0.9]
with warnings.catch_warnings(record=True):
warnings.simplefilter('always') # positive semidefinite warning
evoked = generate_evoked(fwd, stc, evoked_template, cov, snr,
tmin=0.0, tmax=0.2, iir_filter=iir_filter)
assert_array_almost_equal(evoked.times, stc.times)
assert_true(len(evoked.data) == len(fwd['sol']['data']))
# make a vertex that doesn't exist in fwd, should throw error
stc_bad = stc.copy()
mv = np.max(fwd['src'][0]['vertno'][fwd['src'][0]['inuse']])
stc_bad.vertices[0][0] = mv + 1
assert_raises(RuntimeError, generate_evoked, fwd, stc_bad,
evoked_template, cov, snr, tmin=0.0, tmax=0.2)
开发者ID:BushraR,项目名称:mne-python,代码行数:49,代码来源:test_evoked.py
示例19: test_apply_forward
def test_apply_forward():
"""Test projection of source space data to sensor space
"""
start = 0
stop = 5
n_times = stop - start - 1
sfreq = 10.0
t_start = 0.123
fwd = read_forward_solution(fname_meeg)
fwd = convert_forward_solution(fwd, surf_ori=True, force_fixed=True,
use_cps=True)
fwd = pick_types_forward(fwd, meg=True)
assert_true(isinstance(fwd, Forward))
vertno = [fwd['src'][0]['vertno'], fwd['src'][1]['vertno']]
stc_data = np.ones((len(vertno[0]) + len(vertno[1]), n_times))
stc = SourceEstimate(stc_data, vertno, tmin=t_start, tstep=1.0 / sfreq)
gain_sum = np.sum(fwd['sol']['data'], axis=1)
# Evoked
with warnings.catch_warnings(record=True) as w:
evoked = read_evokeds(fname_evoked, condition=0)
evoked.pick_types(meg=True)
evoked = apply_forward(fwd, stc, evoked.info, start=start, stop=stop)
assert_equal(len(w), 2)
data = evoked.data
times = evoked.times
# do some tests
assert_array_almost_equal(evoked.info['sfreq'], sfreq)
assert_array_almost_equal(np.sum(data, axis=1), n_times * gain_sum)
assert_array_almost_equal(times[0], t_start)
assert_array_almost_equal(times[-1], t_start + (n_times - 1) / sfreq)
# Raw
raw_proj = apply_forward_raw(fwd, stc, evoked.info, start=start,
stop=stop)
data, times = raw_proj[:, :]
# do some tests
assert_array_almost_equal(raw_proj.info['sfreq'], sfreq)
assert_array_almost_equal(np.sum(data, axis=1), n_times * gain_sum)
atol = 1. / sfreq
assert_allclose(raw_proj.first_samp / sfreq, t_start, atol=atol)
assert_allclose(raw_proj.last_samp / sfreq,
t_start + (n_times - 1) / sfreq, atol=atol)
开发者ID:nfoti,项目名称:mne-python,代码行数:48,代码来源:test_forward.py
示例20: test_simulate_evoked
def test_simulate_evoked():
""" Test simulation of evoked data """
raw = Raw(raw_fname)
fwd = read_forward_solution(fwd_fname, force_fixed=True)
fwd = pick_types_forward(fwd, meg=True, eeg=True, exclude=raw.info['bads'])
cov = read_cov(cov_fname)
evoked_template = read_evokeds(ave_fname, condition=0, baseline=None)
evoked_template.pick_types(meg=True, eeg=True, exclude=raw.info['bads'])
snr = 6 # dB
tmin = -0.1
sfreq = 1000. # Hz
tstep = 1. / sfreq
n_samples = 600
times = np.linspace(tmin,
|
请发表评论