本文整理汇总了Python中mne.SourceEstimate.morph方法的典型用法代码示例。如果您正苦于以下问题:Python SourceEstimate.morph方法的具体用法?Python SourceEstimate.morph怎么用?Python SourceEstimate.morph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.SourceEstimate
的用法示例。
在下文中一共展示了SourceEstimate.morph方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_morphed_source_space_return
# 需要导入模块: from mne import SourceEstimate [as 别名]
# 或者: from mne.SourceEstimate import morph [as 别名]
def test_morphed_source_space_return():
"""Test returning a morphed source space to the original subject"""
# let's create some random data on fsaverage
data = rng.randn(20484, 1)
tmin, tstep = 0, 1.
src_fs = read_source_spaces(fname_fs)
stc_fs = SourceEstimate(data, [s['vertno'] for s in src_fs],
tmin, tstep, 'fsaverage')
# Create our morph source space
src_morph = morph_source_spaces(src_fs, 'sample',
subjects_dir=subjects_dir)
# Morph the data over using standard methods
stc_morph = stc_fs.morph('sample', [s['vertno'] for s in src_morph],
smooth=1, subjects_dir=subjects_dir)
# We can now pretend like this was real data we got e.g. from an inverse.
# To be complete, let's remove some vertices
keeps = [np.sort(rng.permutation(np.arange(len(v)))[:len(v) - 10])
for v in stc_morph.vertices]
stc_morph = SourceEstimate(
np.concatenate([stc_morph.lh_data[keeps[0]],
stc_morph.rh_data[keeps[1]]]),
[v[k] for v, k in zip(stc_morph.vertices, keeps)], tmin, tstep,
'sample')
# Return it to the original subject
stc_morph_return = stc_morph.to_original_src(
src_fs, subjects_dir=subjects_dir)
# Compare to the original data
stc_morph_morph = stc_morph.morph('fsaverage', stc_morph_return.vertices,
smooth=1,
subjects_dir=subjects_dir)
assert_equal(stc_morph_return.subject, stc_morph_morph.subject)
for ii in range(2):
assert_array_equal(stc_morph_return.vertices[ii],
stc_morph_morph.vertices[ii])
# These will not match perfectly because morphing pushes data around
corr = np.corrcoef(stc_morph_return.data[:, 0],
stc_morph_morph.data[:, 0])[0, 1]
assert_true(corr > 0.99, corr)
# Degenerate cases
stc_morph.subject = None # no .subject provided
assert_raises(ValueError, stc_morph.to_original_src,
src_fs, subject_orig='fsaverage', subjects_dir=subjects_dir)
stc_morph.subject = 'sample'
del src_fs[0]['subject_his_id'] # no name in src_fsaverage
assert_raises(ValueError, stc_morph.to_original_src,
src_fs, subjects_dir=subjects_dir)
src_fs[0]['subject_his_id'] = 'fsaverage' # name mismatch
assert_raises(ValueError, stc_morph.to_original_src,
src_fs, subject_orig='foo', subjects_dir=subjects_dir)
src_fs[0]['subject_his_id'] = 'sample'
src = read_source_spaces(fname) # wrong source space
assert_raises(RuntimeError, stc_morph.to_original_src,
src, subjects_dir=subjects_dir)