本文整理汇总了Python中nilearn.input_data.nifti_masker.NiftiMasker.inverse_transform方法的典型用法代码示例。如果您正苦于以下问题:Python NiftiMasker.inverse_transform方法的具体用法?Python NiftiMasker.inverse_transform怎么用?Python NiftiMasker.inverse_transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nilearn.input_data.nifti_masker.NiftiMasker
的用法示例。
在下文中一共展示了NiftiMasker.inverse_transform方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_joblib_cache
# 需要导入模块: from nilearn.input_data.nifti_masker import NiftiMasker [as 别名]
# 或者: from nilearn.input_data.nifti_masker.NiftiMasker import inverse_transform [as 别名]
def test_joblib_cache():
if not LooseVersion(nibabel.__version__) > LooseVersion('1.1.0'):
# Old nibabel do not pickle
raise SkipTest
from sklearn.externals.joblib import hash, Memory
mask = np.zeros((40, 40, 40))
mask[20, 20, 20] = 1
mask_img = Nifti1Image(mask, np.eye(4))
with testing.write_tmp_imgs(mask_img, create_files=True)\
as filename:
masker = NiftiMasker(mask_img=filename)
masker.fit()
mask_hash = hash(masker.mask_img_)
masker.mask_img_.get_data()
assert_true(mask_hash == hash(masker.mask_img_))
# Test a tricky issue with memmapped joblib.memory that makes
# imgs return by inverse_transform impossible to save
cachedir = mkdtemp()
try:
masker.memory = Memory(cachedir=cachedir, mmap_mode='r',
verbose=0)
X = masker.transform(mask_img)
# inverse_transform a first time, so that the result is cached
out_img = masker.inverse_transform(X)
out_img = masker.inverse_transform(X)
out_img.to_filename(os.path.join(cachedir, 'test.nii'))
finally:
shutil.rmtree(cachedir, ignore_errors=True)
示例2: test_matrix_orientation
# 需要导入模块: from nilearn.input_data.nifti_masker import NiftiMasker [as 别名]
# 或者: from nilearn.input_data.nifti_masker.NiftiMasker import inverse_transform [as 别名]
def test_matrix_orientation():
"""Test if processing is performed along the correct axis."""
# the "step" kind generate heavyside-like signals for each voxel.
# all signals being identical, standardizing along the wrong axis
# would leave a null signal. Along the correct axis, the step remains.
fmri, mask = testing.generate_fake_fmri(shape=(40, 41, 42), kind="step")
masker = NiftiMasker(mask_img=mask, standardize=True, detrend=True)
timeseries = masker.fit_transform(fmri)
assert(timeseries.shape[0] == fmri.shape[3])
assert(timeseries.shape[1] == mask.get_data().sum())
std = timeseries.std(axis=0)
assert(std.shape[0] == timeseries.shape[1]) # paranoid
assert(not np.any(std < 0.1))
# Test inverse transform
masker = NiftiMasker(mask_img=mask, standardize=False, detrend=False)
masker.fit()
timeseries = masker.transform(fmri)
recovered = masker.inverse_transform(timeseries)
np.testing.assert_array_almost_equal(recovered.get_data(), fmri.get_data())