本文整理汇总了Python中nilearn.datasets.load_mni152_template函数的典型用法代码示例。如果您正苦于以下问题:Python load_mni152_template函数的具体用法?Python load_mni152_template怎么用?Python load_mni152_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_mni152_template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fail_fetch_atlas_harvard_oxford
def test_fail_fetch_atlas_harvard_oxford():
# specify non-existing atlas item
assert_raises_regex(ValueError, 'Invalid atlas name',
datasets.fetch_atlas_harvard_oxford, 'not_inside')
# specify existing atlas item
target_atlas = 'cort-maxprob-thr0-1mm'
target_atlas_fname = 'HarvardOxford-' + target_atlas + '.nii.gz'
HO_dir = os.path.join(tmpdir, 'fsl', 'data', 'atlases')
os.makedirs(HO_dir)
nifti_dir = os.path.join(HO_dir, 'HarvardOxford')
os.makedirs(nifti_dir)
target_atlas_nii = os.path.join(nifti_dir, target_atlas_fname)
datasets.load_mni152_template().to_filename(target_atlas_nii)
dummy = open(os.path.join(HO_dir, 'HarvardOxford-Cortical.xml'), 'w')
dummy.write("<?xml version='1.0' encoding='us-ascii'?> "
"<metadata>"
"</metadata>")
dummy.close()
ho = datasets.fetch_atlas_harvard_oxford(target_atlas, data_dir=tmpdir)
assert_true(isinstance(nibabel.load(ho.maps), nibabel.Nifti1Image))
assert_true(isinstance(ho.labels, np.ndarray))
assert_true(len(ho.labels) > 0)
示例2: test_user_given_cmap_with_colorbar
def test_user_given_cmap_with_colorbar():
img = load_mni152_template()
oslicer = OrthoSlicer(cut_coords=(0, 0, 0))
# Test with cmap given as a string
oslicer.add_overlay(img, cmap='Paired', colorbar=True)
oslicer.close()
示例3: test_view_img
def test_view_img():
mni = datasets.load_mni152_template()
with warnings.catch_warnings(record=True) as w:
# Create a fake functional image by resample the template
img = image.resample_img(mni, target_affine=3 * np.eye(3))
html_view = html_stat_map.view_img(img)
_check_html(html_view)
html_view = html_stat_map.view_img(img, threshold='95%')
_check_html(html_view)
html_view = html_stat_map.view_img(img, bg_img=mni)
_check_html(html_view)
html_view = html_stat_map.view_img(img, bg_img=None)
_check_html(html_view)
html_view = html_stat_map.view_img(img, threshold=2., vmax=4.)
_check_html(html_view)
html_view = html_stat_map.view_img(img, symmetric_cmap=False)
img_4d = image.new_img_like(img, img.get_data()[:, :, :, np.newaxis])
assert len(img_4d.shape) == 4
html_view = html_stat_map.view_img(img_4d, threshold=2., vmax=4.)
_check_html(html_view)
# Check that all warnings were expected
warnings_set = set(warning_.category for warning_ in w)
expected_set = set([FutureWarning, UserWarning,
DeprecationWarning])
assert warnings_set.issubset(expected_set), (
"the following warnings were not expected: {}").format(
warnings_set.difference(expected_set))
示例4: test_vol_to_surf
def test_vol_to_surf():
# test 3d niimg to cortical surface projection and invariance to a change
# of affine
mni = datasets.load_mni152_template()
mesh = generate_surf()
_check_vol_to_surf_results(mni, mesh)
fsaverage = datasets.fetch_surf_fsaverage().pial_left
_check_vol_to_surf_results(mni, fsaverage)
示例5: test_demo_ortho_projector
def test_demo_ortho_projector():
# This is only a smoke test
img = load_mni152_template()
oprojector = OrthoProjector.init_with_figure(img=img)
oprojector.add_overlay(img, cmap=plt.cm.gray)
with tempfile.TemporaryFile() as fp:
oprojector.savefig(fp)
oprojector.close()
示例6: test_stacked_slicer
def test_stacked_slicer():
# Test stacked slicers, like the XSlicer
img = load_mni152_template()
slicer = XSlicer.init_with_figure(img=img, cut_coords=3)
slicer.add_overlay(img, cmap=plt.cm.gray)
# Forcing a layout here, to test the locator code
with tempfile.TemporaryFile() as fp:
slicer.savefig(fp)
slicer.close()
示例7: test_demo_ortho_slicer
def test_demo_ortho_slicer():
# This is only a smoke test
mp.use('template', warn=False)
import matplotlib.pyplot as plt
plt.switch_backend('template')
plt.clf()
oslicer = OrthoSlicer(cut_coords=(0, 0, 0))
img = load_mni152_template()
oslicer.add_overlay(img, cmap=plt.cm.gray)
oslicer.close()
示例8: test_plotting_functions_with_cmaps
def test_plotting_functions_with_cmaps():
img = load_mni152_template()
cmaps = ['Paired', 'Set1', 'Set2', 'Set3']
for cmap in cmaps:
plot_roi(img, cmap=cmap, colorbar=True)
plot_stat_map(img, cmap=cmap, colorbar=True)
plot_glass_brain(img, cmap=cmap, colorbar=True)
if LooseVersion(matplotlib.__version__) >= LooseVersion('2.0.0'):
plot_stat_map(img, cmap='viridis', colorbar=True)
plt.close()
示例9: test_demo_ortho_projector
def test_demo_ortho_projector():
# This is only a smoke test
mp.use('template', warn=False)
import matplotlib.pyplot as plt
plt.switch_backend('template')
plt.clf()
img = load_mni152_template()
oprojector = OrthoProjector.init_with_figure(img=img)
oprojector.add_overlay(img, cmap=plt.cm.gray)
with tempfile.TemporaryFile() as fp:
oprojector.savefig(fp)
oprojector.close()
示例10: test_view_stat_map
def test_view_stat_map():
mni = datasets.load_mni152_template()
# Create a fake functional image by resample the template
img = image.resample_img(mni, target_affine=3*np.eye(3))
html = html_stat_map.view_stat_map(img)
_check_html(html)
html = html_stat_map.view_stat_map(img, threshold='95%')
_check_html(html)
html = html_stat_map.view_stat_map(img, bg_img=mni)
_check_html(html)
html = html_stat_map.view_stat_map(img, threshold=2., vmax=4.)
_check_html(html)
示例11: test_contour_fillings_levels_in_add_contours
def test_contour_fillings_levels_in_add_contours():
oslicer = OrthoSlicer(cut_coords=(0, 0, 0))
img = load_mni152_template()
# levels should be atleast 2
# If single levels are passed then we force upper level to be inf
oslicer.add_contours(img, filled=True, colors='r',
alpha=0.2, levels=[0.])
# If two levels are passed, it should be increasing from zero index
# In this case, we simply omit appending inf
oslicer.add_contours(img, filled=True, colors='b',
alpha=0.1, levels=[0., 0.2])
示例12: test_stacked_slicer
def test_stacked_slicer():
# Test stacked slicers, like the XSlicer
mp.use('template', warn=False)
import matplotlib.pyplot as plt
plt.switch_backend('template')
plt.clf()
img = load_mni152_template()
slicer = XSlicer.init_with_figure(img=img, cut_coords=3)
slicer.add_overlay(img, cmap=plt.cm.gray)
# Forcing a layout here, to test the locator code
with tempfile.TemporaryFile() as fp:
slicer.savefig(fp)
slicer.close()
示例13: test_encode_nii
def test_encode_nii():
mni = datasets.load_mni152_template()
encoded = html_stat_map._encode_nii(mni)
decoded = html_stat_map._decode_nii(encoded)
assert np.allclose(mni.get_data(), decoded.get_data())
mni = image.new_img_like(mni, np.asarray(mni.get_data(), dtype='>f8'))
encoded = html_stat_map._encode_nii(mni)
decoded = html_stat_map._decode_nii(encoded)
assert np.allclose(mni.get_data(), decoded.get_data())
mni = image.new_img_like(mni, np.asarray(mni.get_data(), dtype='<i4'))
encoded = html_stat_map._encode_nii(mni)
decoded = html_stat_map._decode_nii(encoded)
assert np.allclose(mni.get_data(), decoded.get_data())
示例14: test_view_stat_map
def test_view_stat_map():
mni = datasets.load_mni152_template()
# Create a fake functional image by resample the template
img = image.resample_img(mni, target_affine=3 * np.eye(3))
html = html_stat_map.view_stat_map(img)
_check_html(html)
html = html_stat_map.view_stat_map(img, threshold='95%')
_check_html(html)
html = html_stat_map.view_stat_map(img, bg_img=mni)
_check_html(html)
html = html_stat_map.view_stat_map(img, bg_img=None)
_check_html(html)
html = html_stat_map.view_stat_map(img, threshold=2., vmax=4.)
_check_html(html)
html = html_stat_map.view_stat_map(img, symmetric_cmap=False)
img_4d = image.new_img_like(img, img.get_data()[:, :, :, np.newaxis])
assert len(img_4d.shape) == 4
html = html_stat_map.view_stat_map(img_4d, threshold=2., vmax=4.)
_check_html(html)
示例15: __init__
def __init__(
self,
sessions=None,
smoothing_fwhm=None,
standardize=False,
detrend=False,
low_pass=None,
high_pass=None,
t_r=None,
target_affine=None,
target_shape=None,
mask_strategy="background",
mask_args=None,
sample_mask=None,
memory_level=1,
memory=Memory(cachedir=None),
verbose=0,
):
# Create grey matter mask from mni template
target_img = datasets.load_mni152_template()
grey_voxels = (target_img.get_data() > 0).astype(int)
mask_img = new_img_like(target_img, grey_voxels, copy_header=True)
super(MniNiftiMasker, self).__init__(
mask_img=mask_img,
target_affine=mask_img.affine,
target_shape=mask_img.shape,
sessions=sessions,
smoothing_fwhm=smoothing_fwhm,
standardize=standardize,
detrend=detrend,
low_pass=low_pass,
high_pass=high_pass,
t_r=t_r,
mask_strategy=mask_strategy,
mask_args=mask_args,
sample_mask=sample_mask,
memory_level=memory_level,
memory=memory,
verbose=verbose,
)