本文整理汇总了Python中nipype.testing.example_data函数的典型用法代码示例。如果您正苦于以下问题:Python example_data函数的具体用法?Python example_data怎么用?Python example_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了example_data函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_reg_transform_comp_nii
def test_reg_transform_comp_nii():
# Create a reg_transform object
nr = RegTransform()
# Check if the command is properly defined
assert nr.cmd == get_custom_path('reg_transform')
# Assign some input data
ref_file = example_data('im1.nii')
trans_file = example_data('warpfield.nii')
trans2_file = example_data('anatomical.nii')
nr.inputs.ref1_file = ref_file
nr.inputs.comp_input2 = trans2_file
nr.inputs.comp_input = trans_file
nr.inputs.omp_core_val = 4
cmd_tmp = '{cmd} -ref {ref_file} -omp 4 -comp {trans1} {trans2} {out_file}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('reg_transform'),
ref_file=ref_file,
trans1=trans_file,
trans2=trans2_file,
out_file=os.path.join(os.getcwd(), 'warpfield_trans.nii.gz'))
assert nr.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:26,代码来源:test_Reg_Transform.py
示例2: test_overlap
def test_overlap():
from nipype.algorithms.metrics import Overlap
def check_close(val1, val2):
import numpy.testing as npt
return npt.assert_almost_equal(val1, val2, decimal=3)
tempdir = mkdtemp()
in1 = example_data('segmentation0.nii.gz')
in2 = example_data('segmentation1.nii.gz')
os.chdir(tempdir)
overlap = Overlap()
overlap.inputs.volume1 = in1
overlap.inputs.volume2 = in1
res = overlap.run()
yield check_close, res.outputs.jaccard, 1.0
overlap = Overlap()
overlap.inputs.volume1 = in1
overlap.inputs.volume2 = in2
res = overlap.run()
yield check_close, res.outputs.jaccard, 0.99705
overlap = Overlap()
overlap.inputs.volume1 = in1
overlap.inputs.volume2 = in2
overlap.inputs.vol_units = 'mm'
res = overlap.run()
yield check_close, res.outputs.jaccard, 0.99705
yield (check_close, res.outputs.roi_voldiff,
np.array([0.0063086, -0.0025506, 0.0]))
rmtree(tempdir)
开发者ID:Alunisiira,项目名称:nipype,代码行数:35,代码来源:test_overlap.py
示例3: test_reg_jacobian_jac_l
def test_reg_jacobian_jac_l():
# Create a reg_jacobian object
nr = RegJacobian()
# Check if the command is properly defined
assert nr.cmd == get_custom_path('reg_jacobian')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
nr.run()
# Assign some input data
ref_file = example_data('im1.nii')
trans_file = example_data('warpfield.nii')
nr.inputs.ref_file = ref_file
nr.inputs.trans_file = trans_file
nr.inputs.type = 'jacL'
nr.inputs.omp_core_val = 4
cmd_tmp = '{cmd} -omp 4 -ref {ref} -trans {trans} -jacL {jac}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('reg_jacobian'),
ref=ref_file,
trans=trans_file,
jac=os.path.join(os.getcwd(), 'warpfield_jacL.nii.gz'))
assert nr.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:28,代码来源:test_Reg_Jacobian.py
示例4: test_seg_calctopncc
def test_seg_calctopncc():
""" Test interfaces for seg_CalctoNCC"""
# Create a node object
calctopncc = CalcTopNCC()
# Check if the command is properly defined
assert calctopncc.cmd == get_custom_path('seg_CalcTopNCC')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
calctopncc.run()
# Assign some input data
in_file = example_data('im1.nii')
file1 = example_data('im2.nii')
file2 = example_data('im3.nii')
calctopncc.inputs.in_file = in_file
calctopncc.inputs.num_templates = 2
calctopncc.inputs.in_templates = [file1, file2]
calctopncc.inputs.top_templates = 1
cmd_tmp = '{cmd} -target {in_file} -templates 2 {file1} {file2} -n 1'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('seg_CalcTopNCC'),
in_file=in_file,
file1=file1,
file2=file2
)
assert calctopncc.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:30,代码来源:test_label_fusion.py
示例5: test_seg_patchmatch
def test_seg_patchmatch():
# Create a node object
seg_patchmatch = PatchMatch()
# Check if the command is properly defined
cmd = get_custom_path('seg_PatchMatch', env_dir='NIFTYSEGDIR')
assert seg_patchmatch.cmd == cmd
# test raising error with mandatory args absent
with pytest.raises(ValueError):
seg_patchmatch.run()
# Assign some input data
in_file = example_data('im1.nii')
mask_file = example_data('im2.nii')
db_file = example_data('db.xml')
seg_patchmatch.inputs.in_file = in_file
seg_patchmatch.inputs.mask_file = mask_file
seg_patchmatch.inputs.database_file = db_file
cmd_tmp = '{cmd} -i {in_file} -m {mask_file} -db {db} -o {out_file}'
expected_cmd = cmd_tmp.format(
cmd=cmd,
in_file=in_file,
mask_file=mask_file,
db=db_file,
out_file='im1_pm.nii.gz',
)
assert seg_patchmatch.cmdline == expected_cmd
开发者ID:ashgillman,项目名称:nipype,代码行数:31,代码来源:test_patchmatch.py
示例6: test_seg_filllesions
def test_seg_filllesions():
# Create a node object
seg_fill = FillLesions()
# Check if the command is properly defined
assert seg_fill.cmd == get_custom_path('seg_FillLesions')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
seg_fill.run()
# Assign some input data
in_file = example_data('im1.nii')
lesion_mask = example_data('im2.nii')
seg_fill.inputs.in_file = in_file
seg_fill.inputs.lesion_mask = lesion_mask
expected_cmd = '{cmd} -i {in_file} -l {lesion_mask} -o {out_file}'.format(
cmd=get_custom_path('seg_FillLesions'),
in_file=in_file,
lesion_mask=lesion_mask,
out_file=os.path.join(os.getcwd(), 'im1_lesions_filled.nii'))
assert seg_fill.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:25,代码来源:test_Seg_FillLesions.py
示例7: test_reg_f3d
def test_reg_f3d():
""" tests for reg_f3d interface"""
# Create a reg_f3d object
nr_f3d = RegF3D()
# Check if the command is properly defined
assert nr_f3d.cmd == get_custom_path('reg_f3d')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
nr_f3d.run()
# Assign some input data
ref_file = example_data('im1.nii')
flo_file = example_data('im2.nii')
rmask_file = example_data('mask.nii')
nr_f3d.inputs.ref_file = ref_file
nr_f3d.inputs.flo_file = flo_file
nr_f3d.inputs.rmask_file = rmask_file
nr_f3d.inputs.omp_core_val = 4
nr_f3d.inputs.vel_flag = True
nr_f3d.inputs.be_val = 0.1
nr_f3d.inputs.le_val = 0.1
cmd_tmp = '{cmd} -be 0.100000 -cpp {cpp} -flo {flo} -le 0.100000 -omp 4 \
-ref {ref} -res {res} -rmask {rmask} -vel'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('reg_f3d'),
cpp=os.path.join(os.getcwd(), 'im2_cpp.nii.gz'),
flo=flo_file,
ref=ref_file,
res=os.path.join(os.getcwd(), 'im2_res.nii.gz'),
rmask=rmask_file)
assert nr_f3d.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:35,代码来源:test_reg.py
示例8: test_staple
def test_staple():
# Create a node object
staple = LabelFusion()
# Check if the command is properly defined
assert staple.cmd == get_custom_path('seg_LabFusion')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
staple.run()
# Assign some input data
in_file = example_data('im1.nii')
file_to_seg = example_data('im2.nii')
template_file = example_data('im3.nii')
staple.inputs.in_file = in_file
staple.inputs.kernel_size = 2.0
staple.inputs.file_to_seg = file_to_seg
staple.inputs.template_file = template_file
staple.inputs.template_num = 2
staple.inputs.classifier_type = 'STAPLE'
cmd_tmp = '{cmd} -in {in_file} -STAPLE -ALL -out {out_file}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('seg_LabFusion'),
in_file=in_file,
file_to_seg=file_to_seg,
template_file=template_file,
out_file=os.path.join(os.getcwd(), 'im1_staple.nii'))
assert staple.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:32,代码来源:test_Seg_LabFusion.py
示例9: test_mv
def test_mv():
# Create a node object
mv = LabelFusion()
# Check if the command is properly defined
assert mv.cmd == get_custom_path('seg_LabFusion')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
mv.run()
# Assign some input data
in_file = example_data('im1.nii')
file_to_seg = example_data('im2.nii')
template_file = example_data('im3.nii')
mv.inputs.in_file = in_file
mv.inputs.file_to_seg = file_to_seg
mv.inputs.template_file = template_file
mv.inputs.template_num = 2
mv.inputs.classifier_type = 'MV'
mv.inputs.sm_ranking = 'ROINCC'
mv.inputs.dilation_roi = 2
cmd_tmp = '{cmd} -in {in_file} -MV -ROINCC 2 2 {file_to_seg} \
{template_file} -out {out_file}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('seg_LabFusion'),
in_file=in_file,
file_to_seg=file_to_seg,
template_file=template_file,
out_file=os.path.join(os.getcwd(), 'im1_mv.nii'))
assert mv.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:34,代码来源:test_Seg_LabFusion.py
示例10: test_reg_measure
def test_reg_measure():
""" tests for reg_measure interface """
# Create a reg_measure object
nr_measure = RegMeasure()
# Check if the command is properly defined
assert nr_measure.cmd == get_custom_path('reg_measure')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
nr_measure.run()
# Assign some input data
ref_file = example_data('im1.nii')
flo_file = example_data('im2.nii')
nr_measure.inputs.ref_file = ref_file
nr_measure.inputs.flo_file = flo_file
nr_measure.inputs.measure_type = 'lncc'
nr_measure.inputs.omp_core_val = 4
cmd_tmp = '{cmd} -flo {flo} -lncc -omp 4 -out {out} -ref {ref}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('reg_measure'),
flo=flo_file,
out='im2_lncc.txt',
ref=ref_file)
assert nr_measure.cmdline == expected_cmd
开发者ID:ashgillman,项目名称:nipype,代码行数:28,代码来源:test_regutils.py
示例11: test_dvars
def test_dvars(tmpdir):
ground_truth = np.loadtxt(example_data('ds003_sub-01_mc.DVARS'))
dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
in_mask=example_data('ds003_sub-01_mc_brainmask.nii.gz'),
save_all=True,
intensity_normalization=0)
os.chdir(str(tmpdir))
res = dvars.run()
dv1 = np.loadtxt(res.outputs.out_all, skiprows=1)
assert (np.abs(dv1[:, 0] - ground_truth[:, 0]).sum()/ len(dv1)) < 0.05
assert (np.abs(dv1[:, 1] - ground_truth[:, 1]).sum() / len(dv1)) < 0.05
assert (np.abs(dv1[:, 2] - ground_truth[:, 2]).sum() / len(dv1)) < 0.05
dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
in_mask=example_data(
'ds003_sub-01_mc_brainmask.nii.gz'),
save_all=True)
res = dvars.run()
dv1 = np.loadtxt(res.outputs.out_all, skiprows=1)
assert (np.abs(dv1[:, 0] - ground_truth[:, 0]).sum() / len(dv1)) < 0.05
assert (np.abs(dv1[:, 1] - ground_truth[:, 1]).sum() / len(dv1)) > 0.05
assert (np.abs(dv1[:, 2] - ground_truth[:, 2]).sum() / len(dv1)) < 0.05
开发者ID:LJWilliams,项目名称:nipype,代码行数:28,代码来源:test_confounds.py
示例12: test_merge
def test_merge():
# Create a node object
merge = Merge()
# Check if the command is properly defined
assert merge.cmd == get_custom_path('seg_maths')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
merge.run()
# Assign some input data
in_file = example_data('im1.nii')
file1 = example_data('im2.nii')
file2 = example_data('im3.nii')
merge.inputs.in_file = in_file
merge.inputs.merge_files = [file1, file2]
merge.inputs.dimension = 2
merge.inputs.output_datatype = 'float'
cmd_tmp = '{cmd} {in_file} -merge 2 2 {f1} {f2} -odt float {out_file}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('seg_maths'),
in_file=in_file,
f1=file1,
f2=file2,
out_file=os.path.join(os.getcwd(), 'im1_merged.nii'))
assert merge.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:30,代码来源:test_maths.py
示例13: test_tuple_maths
def test_tuple_maths():
# Create a node object
tuplem = TupleMaths()
# Check if the command is properly defined
assert tuplem.cmd == get_custom_path('seg_maths')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
tuplem.run()
# Assign some input data
in_file = example_data('im1.nii')
op_file = example_data('im2.nii')
tuplem.inputs.in_file = in_file
tuplem.inputs.operation = 'lncc'
tuplem.inputs.operand_file1 = op_file
tuplem.inputs.operand_value2 = 2.0
tuplem.inputs.output_datatype = 'float'
cmd_tmp = '{cmd} {in_file} -lncc {op} 2.00000000 -odt float {out_file}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('seg_maths'),
in_file=in_file,
op=op_file,
out_file=os.path.join(os.getcwd(), 'im1_lncc.nii'))
assert tuplem.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:29,代码来源:test_maths.py
示例14: test_reg_aladin
def test_reg_aladin():
# Create a reg_aladin object
nr = RegAladin()
# Check if the command is properly defined
assert nr.cmd == get_custom_path('reg_aladin')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
nr.run()
# Assign some input data
ref_file = example_data('im1.nii')
flo_file = example_data('im2.nii')
rmask_file = example_data('mask.nii')
nr.inputs.ref_file = ref_file
nr.inputs.flo_file = flo_file
nr.inputs.rmask_file = rmask_file
nr.inputs.omp_core_val = 4
cmd_tmp = '{cmd} -aff {aff} -flo {flo} -omp 4 -ref {ref} -res {res} \
-rmask {rmask}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('reg_aladin'),
aff=os.path.join(os.getcwd(), 'im2_aff.txt'),
flo=flo_file,
ref=ref_file,
res=os.path.join(os.getcwd(), 'im2_res.nii.gz'),
rmask=rmask_file)
assert nr.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:32,代码来源:test_Reg_Aladin.py
示例15: test_normalize_tpms
def test_normalize_tpms(tmpdir):
tempdir = str(tmpdir)
in_mask = example_data('tpms_msk.nii.gz')
mskdata = nb.load(in_mask, mmap=NUMPY_MMAP).get_data()
mskdata[mskdata > 0.0] = 1.0
mapdata = []
in_files = []
out_files = []
for i in range(3):
mapname = example_data('tpm_%02d.nii.gz' % i)
filename = os.path.join(tempdir, 'modtpm_%02d.nii.gz' % i)
out_files.append(os.path.join(tempdir, 'normtpm_%02d.nii.gz' % i))
im = nb.load(mapname, mmap=NUMPY_MMAP)
data = im.get_data()
mapdata.append(data.copy())
nb.Nifti1Image(2.0 * (data * mskdata), im.affine,
im.header).to_filename(filename)
in_files.append(filename)
normalize_tpms(in_files, in_mask, out_files=out_files)
sumdata = np.zeros_like(mskdata)
for i, tstfname in enumerate(out_files):
normdata = nb.load(tstfname, mmap=NUMPY_MMAP).get_data()
sumdata += normdata
assert np.all(normdata[mskdata == 0] == 0)
assert np.allclose(normdata, mapdata[i])
assert np.allclose(sumdata[sumdata > 0.0], 1.0)
开发者ID:Gilles86,项目名称:nipype,代码行数:35,代码来源:test_normalize_tpms.py
示例16: test_JointFusion_cmd
def test_JointFusion_cmd():
at = JointFusion()
at.inputs.dimension = 3
at.inputs.modalities = 1
at.inputs.method = 'Joint[0.1,2]'
at.inputs.output_label_image = 'fusion_labelimage_output.nii'
warped_intensity_images = [example_data('im1.nii'),
example_data('im2.nii')]
at.inputs.warped_intensity_images = warped_intensity_images
segmentation_images = [example_data('segmentation0.nii.gz'),
example_data('segmentation1.nii.gz')]
at.inputs.warped_label_images = segmentation_images
T1_image = example_data('T1.nii')
at.inputs.target_image = T1_image
at.inputs.patch_radius = [3,2,1]
at.inputs.search_radius = [1,2,3]
expected_command = ('jointfusion 3 1 -m Joint[0.1,2] -rp 3x2x1 -rs 1x2x3'
' -tg %s -g %s -g %s -l %s -l %s'
' fusion_labelimage_output.nii') % (T1_image,
warped_intensity_images[0],
warped_intensity_images[1],
segmentation_images[0],
segmentation_images[1])
yield assert_equal, at.cmdline, expected_command
# setting intensity or labels with unequal lengths raises error
yield assert_raises, AssertionError, at._format_arg, 'warped_intensity_images', InputMultiPath, warped_intensity_images + [example_data('im3.nii')]
开发者ID:vsaase,项目名称:nipype,代码行数:26,代码来源:test_spec_JointFusion.py
示例17: test_overlap
def test_overlap(tmpdir):
from nipype.algorithms.metrics import Overlap
def check_close(val1, val2):
import numpy.testing as npt
return npt.assert_almost_equal(val1, val2, decimal=3)
in1 = example_data("segmentation0.nii.gz")
in2 = example_data("segmentation1.nii.gz")
os.chdir(str(tmpdir))
overlap = Overlap()
overlap.inputs.volume1 = in1
overlap.inputs.volume2 = in1
res = overlap.run()
check_close(res.outputs.jaccard, 1.0)
overlap = Overlap()
overlap.inputs.volume1 = in1
overlap.inputs.volume2 = in2
res = overlap.run()
check_close(res.outputs.jaccard, 0.99705)
overlap = Overlap()
overlap.inputs.volume1 = in1
overlap.inputs.volume2 = in2
overlap.inputs.vol_units = "mm"
res = overlap.run()
check_close(res.outputs.jaccard, 0.99705)
check_close(res.outputs.roi_voldiff, np.array([0.0063086, -0.0025506, 0.0]))
开发者ID:nipy,项目名称:nipype,代码行数:31,代码来源:test_overlap.py
示例18: test_reg_resample_blank
def test_reg_resample_blank():
# Create a reg_resample object
nr = RegResample()
# Check if the command is properly defined
assert nr.cmd == get_custom_path('reg_resample')
# test raising error with mandatory args absent
with pytest.raises(ValueError):
nr.run()
# Assign some input data
ref_file = example_data('im1.nii')
flo_file = example_data('im2.nii')
trans_file = example_data('warpfield.nii')
nr.inputs.ref_file = ref_file
nr.inputs.flo_file = flo_file
nr.inputs.trans_file = trans_file
nr.inputs.type = 'blank'
nr.inputs.inter_val = 'LIN'
nr.inputs.omp_core_val = 4
cmd_tmp = '{cmd} -flo {flo} -inter 1 -omp 4 -ref {ref} -trans {trans} \
-blank {blank}'
expected_cmd = cmd_tmp.format(
cmd=get_custom_path('reg_resample'),
flo=flo_file,
ref=ref_file,
trans=trans_file,
blank=os.path.join(os.getcwd(), 'im2_blank.nii.gz'))
assert nr.cmdline == expected_cmd
开发者ID:NifTK,项目名称:nipype,代码行数:33,代码来源:test_Reg_Resample.py
示例19: test_bedpostx2
def test_bedpostx2():
filelist, outdir, cwd = create_files_in_directory()
bpx = fsl.BEDPOSTX()
# make sure command gets called
yield assert_equal, bpx.cmd, 'bedpostx'
# test raising error with mandatory args absent
yield assert_raises, ValueError, bpx.run
# .inputs based parameters setting
bpx2 = fsl.BEDPOSTX()
bpx2.inputs.mask = example_data('mask.nii')
bpx2.inputs.dwi = example_data('diffusion.nii')
bpx2.inputs.bvals = example_data('bvals')
bpx2.inputs.bvecs = example_data('bvecs')
bpx2.inputs.fibres = 2
bpx2.inputs.weight = 0.3
bpx2.inputs.burn_period = 200
bpx2.inputs.jumps = 500
bpx2.inputs.sampling = 20
actualCmdline = sorted(bpx2.cmdline.split())
cmd = 'bedpostx bedpostx -b 200 -n 2 -j 500 -s 20 -w 0.30'
desiredCmdline = sorted(cmd.split())
yield assert_equal, actualCmdline, desiredCmdline
开发者ID:Alunisiira,项目名称:nipype,代码行数:25,代码来源:test_dti.py
示例20: test_dvars
def test_dvars(tmpdir):
ground_truth = np.loadtxt(example_data('ds003_sub-01_mc.DVARS'))
dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
in_mask=example_data('ds003_sub-01_mc_brainmask.nii.gz'),
save_all=True)
os.chdir(str(tmpdir))
res = dvars.run()
dv1 = np.loadtxt(res.outputs.out_std)
assert (np.abs(dv1 - ground_truth).sum()/ len(dv1)) < 0.05
开发者ID:shoshber,项目名称:nipype,代码行数:10,代码来源:test_confounds.py
注:本文中的nipype.testing.example_data函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论