本文整理汇总了Python中nipype.testing.example_data函数的典型用法代码示例。如果您正苦于以下问题:Python example_data函数的具体用法?Python example_data怎么用?Python example_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了example_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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)