本文整理汇总了Python中mne.convert_forward_solution函数的典型用法代码示例。如果您正苦于以下问题:Python convert_forward_solution函数的具体用法?Python convert_forward_solution怎么用?Python convert_forward_solution使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了convert_forward_solution函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _compare_forwards
def _compare_forwards(fwd, fwd_py, n_sensors, n_src,
meg_rtol=1e-4, meg_atol=1e-9,
eeg_rtol=1e-3, eeg_atol=1e-3):
"""Helper to test forwards"""
# check source spaces
assert_equal(len(fwd['src']), len(fwd_py['src']))
_compare_source_spaces(fwd['src'], fwd_py['src'], mode='approx')
for surf_ori in [False, True]:
if surf_ori:
# use copy here to leave our originals unmodified
fwd = convert_forward_solution(fwd, surf_ori, copy=True)
fwd_py = convert_forward_solution(fwd, surf_ori, copy=True)
for key in ['nchan', 'source_nn', 'source_rr', 'source_ori',
'surf_ori', 'coord_frame', 'nsource']:
print(key)
assert_allclose(fwd_py[key], fwd[key], rtol=1e-4, atol=1e-7)
assert_allclose(fwd_py['mri_head_t']['trans'],
fwd['mri_head_t']['trans'], rtol=1e-5, atol=1e-8)
assert_equal(fwd_py['sol']['data'].shape, (n_sensors, n_src))
assert_equal(len(fwd['sol']['row_names']), n_sensors)
assert_equal(len(fwd_py['sol']['row_names']), n_sensors)
# check MEG
assert_allclose(fwd['sol']['data'][:306],
fwd_py['sol']['data'][:306],
rtol=meg_rtol, atol=meg_atol,
err_msg='MEG mismatch')
# check EEG
if fwd['sol']['data'].shape[0] > 306:
assert_allclose(fwd['sol']['data'][306:],
fwd_py['sol']['data'][306:],
rtol=eeg_rtol, atol=eeg_atol,
err_msg='EEG mismatch')
开发者ID:pombreda,项目名称:mne-python,代码行数:35,代码来源:test_make_forward.py
示例2: _compare_forwards
def _compare_forwards(fwd, fwd_py, n_sensors, n_src, meg_rtol=1e-4, meg_atol=1e-9):
"""Helper to test forwards"""
# check source spaces
assert_equal(len(fwd["src"]), len(fwd_py["src"]))
_compare_source_spaces(fwd["src"], fwd_py["src"], mode="approx")
for surf_ori in [False, True]:
if surf_ori:
# use copy here to leave our originals unmodified
fwd = convert_forward_solution(fwd, surf_ori, copy=True)
fwd_py = convert_forward_solution(fwd, surf_ori, copy=True)
for key in ["nchan", "source_nn", "source_rr", "source_ori", "surf_ori", "coord_frame", "nsource"]:
print(key)
assert_allclose(fwd_py[key], fwd[key], rtol=1e-4, atol=1e-7)
assert_allclose(fwd_py["mri_head_t"]["trans"], fwd["mri_head_t"]["trans"], rtol=1e-5, atol=1e-8)
assert_equal(fwd_py["sol"]["data"].shape, (n_sensors, n_src))
assert_equal(len(fwd["sol"]["row_names"]), n_sensors)
assert_equal(len(fwd_py["sol"]["row_names"]), n_sensors)
# check MEG
print("check MEG")
assert_allclose(fwd["sol"]["data"][:306], fwd_py["sol"]["data"][:306], rtol=meg_rtol, atol=meg_atol)
# check EEG
if fwd["sol"]["data"].shape[0] > 306:
print("check EEG")
assert_allclose(fwd["sol"]["data"][306:], fwd_py["sol"]["data"][306:], rtol=1e-3, atol=1e-3)
开发者ID:rgoj,项目名称:mne-python,代码行数:27,代码来源:test_make_forward.py
示例3: test_convert_forward
def test_convert_forward():
"""Test converting forward solution between different representations
"""
fwd = read_forward_solution(fname_meeg)
print(fwd) # __repr__
assert_true(isinstance(fwd, Forward))
# look at surface orientation
fwd_surf = convert_forward_solution(fwd, surf_ori=True)
fwd_surf_io = read_forward_solution(fname_meeg, surf_ori=True)
compare_forwards(fwd_surf, fwd_surf_io)
# go back
fwd_new = convert_forward_solution(fwd_surf, surf_ori=False)
print(fwd_new)
assert_true(isinstance(fwd, Forward))
compare_forwards(fwd, fwd_new)
# now go to fixed
fwd_fixed = convert_forward_solution(fwd_surf, surf_ori=False,
force_fixed=True)
print(fwd_fixed)
assert_true(isinstance(fwd_fixed, Forward))
fwd_fixed_io = read_forward_solution(fname_meeg, surf_ori=False,
force_fixed=True)
compare_forwards(fwd_fixed, fwd_fixed_io)
# now go back to cartesian (original condition)
fwd_new = convert_forward_solution(fwd_fixed)
print(fwd_new)
assert_true(isinstance(fwd_new, Forward))
compare_forwards(fwd, fwd_new)
开发者ID:dengemann,项目名称:mne-python,代码行数:28,代码来源:test_forward.py
示例4: test_convert_forward
def test_convert_forward():
"""Test converting forward solution between different representations
"""
fwd = read_forward_solution(fname_meeg_grad)
fwd_repr = repr(fwd)
assert_true('306' in fwd_repr)
assert_true('60' in fwd_repr)
assert_true(fwd_repr)
assert_true(isinstance(fwd, Forward))
# look at surface orientation
fwd_surf = convert_forward_solution(fwd, surf_ori=True)
# go back
fwd_new = convert_forward_solution(fwd_surf, surf_ori=False)
assert_true(repr(fwd_new))
assert_true(isinstance(fwd_new, Forward))
compare_forwards(fwd, fwd_new)
del fwd_new
gc.collect()
# now go to fixed
fwd_fixed = convert_forward_solution(fwd_surf, surf_ori=True,
force_fixed=True, use_cps=False)
del fwd_surf
gc.collect()
assert_true(repr(fwd_fixed))
assert_true(isinstance(fwd_fixed, Forward))
assert_true(is_fixed_orient(fwd_fixed))
# now go back to cartesian (original condition)
fwd_new = convert_forward_solution(fwd_fixed, surf_ori=False,
force_fixed=False)
assert_true(repr(fwd_new))
assert_true(isinstance(fwd_new, Forward))
compare_forwards(fwd, fwd_new)
del fwd, fwd_new, fwd_fixed
gc.collect()
开发者ID:HSMin,项目名称:mne-python,代码行数:35,代码来源:test_forward.py
示例5: test_priors
def test_priors():
"""Test prior computations."""
# Depth prior
fwd = read_forward_solution(fname_meeg)
assert not is_fixed_orient(fwd)
n_sources = fwd['nsource']
info = read_info(fname_evoked)
depth_prior = compute_depth_prior(fwd, info, exp=0.8)
assert depth_prior.shape == (3 * n_sources,)
depth_prior = compute_depth_prior(fwd, info, exp=0.)
assert_array_equal(depth_prior, 1.)
with pytest.raises(ValueError, match='must be "whiten"'):
compute_depth_prior(fwd, info, limit_depth_chs='foo')
with pytest.raises(ValueError, match='noise_cov must be a Covariance'):
compute_depth_prior(fwd, info, limit_depth_chs='whiten')
fwd_fixed = convert_forward_solution(fwd, force_fixed=True)
with pytest.deprecated_call():
depth_prior = compute_depth_prior(
fwd_fixed['sol']['data'], info, is_fixed_ori=True)
assert depth_prior.shape == (n_sources,)
# Orientation prior
orient_prior = compute_orient_prior(fwd, 1.)
assert_array_equal(orient_prior, 1.)
orient_prior = compute_orient_prior(fwd_fixed, 0.)
assert_array_equal(orient_prior, 1.)
with pytest.raises(ValueError, match='oriented in surface coordinates'):
compute_orient_prior(fwd, 0.5)
fwd_surf_ori = convert_forward_solution(fwd, surf_ori=True)
orient_prior = compute_orient_prior(fwd_surf_ori, 0.5)
assert all(np.in1d(orient_prior, (0.5, 1.)))
with pytest.raises(ValueError, match='between 0 and 1'):
compute_orient_prior(fwd_surf_ori, -0.5)
with pytest.raises(ValueError, match='with fixed orientation'):
compute_orient_prior(fwd_fixed, 0.5)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:34,代码来源:test_forward.py
示例6: _compare_forwards
def _compare_forwards(fwd, fwd_py, n_sensors, n_src):
"""Helper to test forwards"""
# check source spaces
assert_equal(len(fwd['src']), len(fwd_py['src']))
_compare_source_spaces(fwd['src'], fwd_py['src'], mode='approx')
for surf_ori in [False, True]:
if surf_ori:
fwd = convert_forward_solution(fwd, surf_ori, copy=False)
fwd_py = convert_forward_solution(fwd, surf_ori, copy=False)
for key in ['nchan', 'source_nn', 'source_rr', 'source_ori',
'surf_ori', 'coord_frame', 'nsource']:
print key
assert_allclose(fwd_py[key], fwd[key], rtol=1e-4, atol=1e-7)
assert_allclose(fwd_py['mri_head_t']['trans'],
fwd['mri_head_t']['trans'], rtol=1e-5, atol=1e-8)
# check MEG
assert_allclose(fwd['sol']['data'][:306],
fwd_py['sol']['data'][:306],
rtol=1e-4, atol=1e-9)
# check EEG
if fwd['sol']['data'].shape[0] > 306:
assert_allclose(fwd['sol']['data'][306:],
fwd_py['sol']['data'][306:],
rtol=1e-3, atol=1e-3)
assert_equal(fwd_py['sol']['data'].shape, (n_sensors, n_src))
assert_equal(len(fwd['sol']['row_names']), n_sensors)
assert_equal(len(fwd_py['sol']['row_names']), n_sensors)
开发者ID:dichaelen,项目名称:mne-python,代码行数:29,代码来源:test_make_forward.py
示例7: 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
示例8: test_make_forward_solution_discrete
def test_make_forward_solution_discrete():
"""Test making and converting a forward solution with discrete src."""
# smoke test for depth weighting and discrete source spaces
src = read_source_spaces(fname_src)[0]
src = SourceSpaces([src] + setup_volume_source_space(
pos=dict(rr=src['rr'][src['vertno'][:3]].copy(),
nn=src['nn'][src['vertno'][:3]].copy())))
sphere = make_sphere_model()
fwd = make_forward_solution(fname_raw, fname_trans, src, sphere,
meg=True, eeg=False)
convert_forward_solution(fwd, surf_ori=True)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:11,代码来源:test_make_forward.py
示例9: test_inverse_operator_channel_ordering
def test_inverse_operator_channel_ordering():
"""Test MNE inverse computation is immune to channel reorderings
"""
# These are with original ordering
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
fwd_orig = make_forward_solution(evoked.info, fname_trans, src_fname,
fname_bem, eeg=True, mindist=5.0)
fwd_orig = convert_forward_solution(fwd_orig, surf_ori=True)
inv_orig = make_inverse_operator(evoked.info, fwd_orig, noise_cov,
loose=0.2, depth=0.8,
limit_depth_chs=False)
stc_1 = apply_inverse(evoked, inv_orig, lambda2, "dSPM")
# Assume that a raw reordering applies to both evoked and noise_cov,
# so we don't need to create those from scratch. Just reorder them,
# then try to apply the original inverse operator
new_order = np.arange(len(evoked.info['ch_names']))
randomiser = np.random.RandomState(42)
randomiser.shuffle(new_order)
evoked.data = evoked.data[new_order]
evoked.info['chs'] = [evoked.info['chs'][n] for n in new_order]
evoked.info._update_redundant()
evoked.info._check_consistency()
cov_ch_reorder = [c for c in evoked.info['ch_names']
if (c in noise_cov.ch_names)]
new_order_cov = [noise_cov.ch_names.index(name) for name in cov_ch_reorder]
noise_cov['data'] = noise_cov.data[np.ix_(new_order_cov, new_order_cov)]
noise_cov['names'] = [noise_cov['names'][idx] for idx in new_order_cov]
fwd_reorder = make_forward_solution(evoked.info, fname_trans, src_fname,
fname_bem, eeg=True, mindist=5.0)
fwd_reorder = convert_forward_solution(fwd_reorder, surf_ori=True)
inv_reorder = make_inverse_operator(evoked.info, fwd_reorder, noise_cov,
loose=0.2, depth=0.8,
limit_depth_chs=False)
stc_2 = apply_inverse(evoked, inv_reorder, lambda2, "dSPM")
assert_equal(stc_1.subject, stc_2.subject)
assert_array_equal(stc_1.times, stc_2.times)
assert_allclose(stc_1.data, stc_2.data, rtol=1e-5, atol=1e-5)
assert_true(inv_orig['units'] == inv_reorder['units'])
# Reload with original ordering & apply reordered inverse
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
stc_3 = apply_inverse(evoked, inv_reorder, lambda2, "dSPM")
assert_allclose(stc_1.data, stc_3.data, rtol=1e-5, atol=1e-5)
开发者ID:hoechenberger,项目名称:mne-python,代码行数:53,代码来源:test_inverse.py
示例10: _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
示例11: test_make_inverse_operator_loose
def test_make_inverse_operator_loose(evoked):
"""Test MNE inverse computation (precomputed and non-precomputed)."""
# Test old version of inverse computation starting from forward operator
noise_cov = read_cov(fname_cov)
inverse_operator = read_inverse_operator(fname_inv)
fwd_op = convert_forward_solution(read_forward_solution_meg(fname_fwd),
surf_ori=True, copy=False)
with catch_logging() as log:
with pytest.deprecated_call(): # limit_depth_chs
my_inv_op = make_inverse_operator(
evoked.info, fwd_op, noise_cov, loose=0.2, depth=0.8,
limit_depth_chs=False, verbose=True)
log = log.getvalue()
assert 'MEG: rank 302 computed' in log
assert 'limit = 1/%d' % fwd_op['nsource'] in log
_compare_io(my_inv_op)
assert_equal(inverse_operator['units'], 'Am')
_compare_inverses_approx(my_inv_op, inverse_operator, evoked,
rtol=1e-2, atol=1e-5, depth_atol=1e-3)
# Test MNE inverse computation starting from forward operator
with catch_logging() as log:
my_inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov,
loose='auto', depth=0.8,
fixed=False, verbose=True)
log = log.getvalue()
assert 'MEG: rank 302 computed from 305' in log
_compare_io(my_inv_op)
_compare_inverses_approx(my_inv_op, inverse_operator, evoked,
rtol=1e-3, atol=1e-5)
assert ('dev_head_t' in my_inv_op['info'])
assert ('mri_head_t' in my_inv_op)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:31,代码来源:test_inverse.py
示例12: test_make_inverse_operator
def test_make_inverse_operator():
"""Test MNE inverse computation (precomputed and non-precomputed)."""
# Test old version of inverse computation starting from forward operator
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
inverse_operator = read_inverse_operator(fname_inv)
fwd_op = convert_forward_solution(read_forward_solution_meg(fname_fwd),
surf_ori=True, copy=False)
with catch_logging() as log:
my_inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov,
loose=0.2, depth=0.8,
limit_depth_chs=False, verbose=True)
log = log.getvalue()
assert 'rank 302 (3 small eigenvalues omitted)' in log
_compare_io(my_inv_op)
assert_equal(inverse_operator['units'], 'Am')
_compare_inverses_approx(my_inv_op, inverse_operator, evoked,
rtol=1e-2, atol=1e-5, depth_atol=1e-3)
# Test MNE inverse computation starting from forward operator
with catch_logging() as log:
my_inv_op = make_inverse_operator(evoked.info, fwd_op, noise_cov,
loose=0.2, depth=0.8, verbose=True)
log = log.getvalue()
assert 'rank 302 (3 small eigenvalues omitted)' in log
_compare_io(my_inv_op)
_compare_inverses_approx(my_inv_op, inverse_operator, evoked,
rtol=1e-3, atol=1e-5)
assert ('dev_head_t' in my_inv_op['info'])
assert ('mri_head_t' in my_inv_op)
开发者ID:palday,项目名称:mne-python,代码行数:29,代码来源:test_inverse.py
示例13: 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
示例14: _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
示例15: run_forward
def run_forward(subject_id):
subject = "sub%03d" % subject_id
print("processing subject: %s" % subject)
data_path = op.join(meg_dir, subject)
fname_ave = op.join(data_path, '%s-ave.fif' % subject)
fname_fwd = op.join(data_path, '%s-meg-%s-fwd.fif' % (subject, spacing))
fname_trans = op.join(study_path, 'ds117', subject, 'MEG', '%s-trans.fif' % subject)
src = mne.setup_source_space(subject, spacing=spacing,
subjects_dir=subjects_dir, overwrite=True,
n_jobs=1, add_dist=False)
src_fname = op.join(subjects_dir, subject, '%s-src.fif' % spacing)
mne.write_source_spaces(src_fname, src)
bem_model = mne.make_bem_model(subject, ico=4, subjects_dir=subjects_dir,
conductivity=(0.3,))
bem = mne.make_bem_solution(bem_model)
info = mne.read_evokeds(fname_ave, condition=0).info
fwd = mne.make_forward_solution(info, trans=fname_trans, src=src, bem=bem,
fname=None, meg=True, eeg=False,
mindist=mindist, n_jobs=1, overwrite=True)
fwd = mne.convert_forward_solution(fwd, surf_ori=True)
mne.write_forward_solution(fname_fwd, fwd, overwrite=True)
开发者ID:dengemann,项目名称:mne-biomag-group-demo,代码行数:25,代码来源:05-make_forward.py
示例16: test_simulate_round_trip
def test_simulate_round_trip():
"""Test simulate_raw round trip calculations."""
# Check a diagonal round-trip
raw, src, stc, trans, sphere = _get_data()
raw.pick_types(meg=True, stim=True)
bem = read_bem_solution(bem_1_fname)
old_bem = bem.copy()
old_src = src.copy()
old_trans = trans.copy()
fwd = make_forward_solution(raw.info, trans, src, bem)
# no omissions
assert (sum(len(s['vertno']) for s in src) ==
sum(len(s['vertno']) for s in fwd['src']) ==
36)
# make sure things were not modified
assert (old_bem['surfs'][0]['coord_frame'] ==
bem['surfs'][0]['coord_frame'])
assert trans == old_trans
_compare_source_spaces(src, old_src)
data = np.eye(fwd['nsource'])
raw.crop(0, (len(data) - 1) / raw.info['sfreq'])
stc = SourceEstimate(data, [s['vertno'] for s in fwd['src']],
0, 1. / raw.info['sfreq'])
for use_cps in (False, True):
this_raw = simulate_raw(raw, stc, trans, src, bem, cov=None,
use_cps=use_cps)
this_raw.pick_types(meg=True, eeg=True)
assert (old_bem['surfs'][0]['coord_frame'] ==
bem['surfs'][0]['coord_frame'])
assert trans == old_trans
_compare_source_spaces(src, old_src)
this_fwd = convert_forward_solution(fwd, force_fixed=True,
use_cps=use_cps)
assert_allclose(this_raw[:][0], this_fwd['sol']['data'],
atol=1e-12, rtol=1e-6)
开发者ID:jdammers,项目名称:mne-python,代码行数:35,代码来源:test_raw.py
示例17: test_simulate_round_trip
def test_simulate_round_trip(raw_data):
"""Test simulate_raw round trip calculations."""
# Check a diagonal round-trip
raw, src, stc, trans, sphere = raw_data
raw.pick_types(meg=True, stim=True)
bem = read_bem_solution(bem_1_fname)
old_bem = bem.copy()
old_src = src.copy()
old_trans = trans.copy()
fwd = make_forward_solution(raw.info, trans, src, bem)
# no omissions
assert (sum(len(s['vertno']) for s in src) ==
sum(len(s['vertno']) for s in fwd['src']) ==
36)
# make sure things were not modified
assert (old_bem['surfs'][0]['coord_frame'] ==
bem['surfs'][0]['coord_frame'])
assert trans == old_trans
_compare_source_spaces(src, old_src)
data = np.eye(fwd['nsource'])
raw.crop(0, (len(data) - 1) / raw.info['sfreq'])
stc = SourceEstimate(data, [s['vertno'] for s in fwd['src']],
0, 1. / raw.info['sfreq'])
for use_fwd in (None, fwd):
if use_fwd is None:
use_trans, use_src, use_bem = trans, src, bem
else:
use_trans = use_src = use_bem = None
with pytest.deprecated_call():
this_raw = simulate_raw(raw, stc, use_trans, use_src, use_bem,
cov=None, forward=use_fwd)
this_raw.pick_types(meg=True, eeg=True)
assert (old_bem['surfs'][0]['coord_frame'] ==
bem['surfs'][0]['coord_frame'])
assert trans == old_trans
_compare_source_spaces(src, old_src)
this_fwd = convert_forward_solution(fwd, force_fixed=True)
assert_allclose(this_raw[:][0], this_fwd['sol']['data'],
atol=1e-12, rtol=1e-6)
with pytest.raises(ValueError, match='If forward is not None then'):
simulate_raw(raw.info, stc, trans, src, bem, forward=fwd)
# Not iterable
with pytest.raises(TypeError, match='SourceEstimate, tuple, or iterable'):
simulate_raw(raw.info, 0., trans, src, bem, None)
# STC with a source that `src` does not have
assert 0 not in src[0]['vertno']
vertices = [[0, fwd['src'][0]['vertno'][0]], []]
stc_bad = SourceEstimate(data[:2], vertices, 0, 1. / raw.info['sfreq'])
with pytest.warns(RuntimeWarning,
match='1 of 2 SourceEstimate vertices'):
simulate_raw(raw.info, stc_bad, trans, src, bem)
assert 0 not in fwd['src'][0]['vertno']
with pytest.warns(RuntimeWarning,
match='1 of 2 SourceEstimate vertices'):
simulate_raw(raw.info, stc_bad, None, None, None, forward=fwd)
# dev_head_t mismatch
fwd['info']['dev_head_t']['trans'][0, 0] = 1.
with pytest.raises(ValueError, match='dev_head_t.*does not match'):
simulate_raw(raw.info, stc, None, None, None, forward=fwd)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:59,代码来源:test_raw.py
示例18: 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
示例19: test_make_inverse_operator_fixed
def test_make_inverse_operator_fixed():
"""Test MNE inverse computation (fixed orientation)."""
fwd = read_forward_solution_meg(fname_fwd)
evoked = _get_evoked()
noise_cov = read_cov(fname_cov)
# can't make fixed inv with depth weighting without free ori fwd
fwd_fixed = convert_forward_solution(fwd, force_fixed=True,
use_cps=True)
pytest.raises(ValueError, make_inverse_operator, evoked.info, fwd_fixed,
noise_cov, depth=0.8, fixed=True)
# now compare to C solution
# note that the forward solution must not be surface-oriented
# to get equivalency (surf_ori=True changes the normals)
with catch_logging() as log:
inv_op = make_inverse_operator( # test depth=0. alias for depth=None
evoked.info, fwd, noise_cov, depth=0., fixed=True,
use_cps=False, verbose=True)
log = log.getvalue()
assert 'rank 302 (3 small eigenvalues omitted)' in log
assert 'EEG channels: 0' in repr(inv_op)
assert 'MEG channels: 305' in repr(inv_op)
del fwd_fixed
inverse_operator_nodepth = read_inverse_operator(fname_inv_fixed_nodepth)
# XXX We should have this but we don't (MNE-C doesn't restrict info):
# assert 'EEG channels: 0' in repr(inverse_operator_nodepth)
assert 'MEG channels: 305' in repr(inverse_operator_nodepth)
_compare_inverses_approx(inverse_operator_nodepth, inv_op, evoked,
rtol=1e-5, atol=1e-4)
# Inverse has 306 channels - 6 proj = 302
assert (compute_rank_inverse(inverse_operator_nodepth) == 302)
# Now with depth
fwd_surf = convert_forward_solution(fwd, surf_ori=True) # not fixed
for kwargs, use_fwd in zip([dict(fixed=True), dict(loose=0.)],
[fwd, fwd_surf]): # Should be equiv.
inv_op_depth = make_inverse_operator(
evoked.info, use_fwd, noise_cov, depth=0.8, use_cps=True,
**kwargs)
inverse_operator_depth = read_inverse_operator(fname_inv_fixed_depth)
# Normals should be the adjusted ones
assert_allclose(inverse_operator_depth['source_nn'],
fwd_surf['source_nn'][2::3], atol=1e-5)
_compare_inverses_approx(inverse_operator_depth, inv_op_depth, evoked,
rtol=1e-3, atol=1e-4)
开发者ID:palday,项目名称:mne-python,代码行数:45,代码来源:test_inverse.py
示例20: test_warn_inverse_operator
def test_warn_inverse_operator(evoked, noise_cov):
"""Test MNE inverse warning without average EEG projection."""
bad_info = evoked.info
bad_info['projs'] = list()
fwd_op = convert_forward_solution(read_forward_solution(fname_fwd),
surf_ori=True, copy=False)
noise_cov['projs'].pop(-1) # get rid of avg EEG ref proj
with pytest.warns(RuntimeWarning, match='reference'):
make_inverse_operator(bad_info, fwd_op, noise_cov)
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:9,代码来源:test_inverse.py
注:本文中的mne.convert_forward_solution函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论