Skip to content

Commit 4ededb3

Browse files
committed
Merge pull request #1165 from satra/fix/tests
Updating and adjusting tests across recent PRs
2 parents 09dad57 + 717b29e commit 4ededb3

24 files changed

+207
-108
lines changed

nipype/algorithms/mesh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import numpy as np
1616
from numpy import linalg as nla
1717
import os.path as op
18-
from nipype.external import six
18+
from ..external import six
1919

2020
from .. import logging
2121

nipype/algorithms/tests/test_mesh_ops.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
from nipype.algorithms import mesh as m
1717

1818
notvtk = True
19-
try:
20-
from tvtk.api import tvtk
21-
notvtk = False
22-
except ImportError:
23-
pass
24-
19+
import platform
20+
if 'darwin' not in platform.system().lower():
21+
try:
22+
from tvtk.api import tvtk
23+
notvtk = False
24+
except ImportError:
25+
pass
2526

2627
@skipif(notvtk)
2728
def test_ident_distances():
2829
tempdir = mkdtemp()
2930
curdir = os.getcwd()
3031
os.chdir(tempdir)
3132
in_surf = example_data('surf01.vtk')
32-
3333
dist_ident = m.ComputeMeshWarp()
3434
dist_ident.inputs.surface1 = in_surf
3535
dist_ident.inputs.surface2 = in_surf

nipype/interfaces/ants/segmentation.py

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -576,36 +576,51 @@ def _list_outputs(self):
576576

577577

578578
class JointFusionInputSpec(ANTSCommandInputSpec):
579-
dimension = traits.Enum(3, 2, 4, argstr='%d', position=0, usedefault=True, mandatory=True,
579+
dimension = traits.Enum(3, 2, 4, argstr='%d', position=0, usedefault=True,
580+
mandatory=True,
580581
desc='image dimension (2, 3, or 4)')
581-
modalities = traits.Int(argstr='%d', position=1, mandatory=True, desc='Number of modalities or features')
582-
warped_intensity_images = InputMultiPath(File(exists=True), argstr="-g %s...", mandatory=True, desc='Warped atlas images')
583-
target_image = InputMultiPath(File(exists=True), argstr='-tg %s...', mandatory=True, desc='Target image(s)')
584-
warped_label_images = InputMultiPath(File(exists=True), argstr="-l %s...", mandatory=True, desc='Warped atlas segmentations')
585-
method = traits.Str(default='Joint', argstr='-m %s', usedefault=True, desc='Select voting method. Options: Joint (Joint Label Fusion). May be followed by optional parameters in brackets, e.g., -m Joint[0.1,2]')
586-
alpha = traits.Float(default=0.1, usedefault=True, requires=['method'], desc='Regularization term added to matrix Mx for inverse')
587-
beta = traits.Int(default=2, usedefault=True, requires=['method'], desc='Exponent for mapping intensity difference to joint error')
588-
output_label_image = File(argstr='%s', mandatory=True, position=-1, desc='Output fusion label map image')
589-
patch_radius = traits.ListInt(minlen=3, maxlen=3, argstr='-rp %s', desc='Patch radius for similarity measures, scalar or vector. Default: 2x2x2')
590-
search_radius = traits.ListInt(minlen=3, maxlen=3, argstr='-rs %s', desc='Local search radius. Default: 3x3x3')
591-
exclusion_region = File(exists=True, argstr='-x %s', desc='Specify an exclusion region for the given label.')
592-
# TODO: These are almost never needed except for debugging
593-
# output_posteriors_name_template = traits.Str('POSTERIOR_%02d.nii.gz', argstr='-p %s',
594-
# desc="Save the posterior maps (probability that each voxel belongs to each " +\
595-
# "label) as images. The number of images saved equals the number of labels. " +\
596-
# "The filename pattern must be in C printf format, e.g. posterior%04d.nii.gz")
597-
# output_voting_weights_name_template = traits.Str('WEIGHTED_%04d.nii.gz', argstr='-w %s', desc="Save the voting weights as " +\
598-
# "images. The number of images saved equals the number of atlases. The " +\
599-
# "filename pattern must be in C printf format, e.g. weight%04d.nii.gz")
600-
atlas_group_id = traits.ListInt(argstr='-gp %d...', desc='Assign a group ID for each atlas')
601-
atlas_group_weights = traits.ListInt(argstr='-gpw %d...', desc='Assign the voting weights to each atlas group')
582+
modalities = traits.Int(argstr='%d', position=1, mandatory=True,
583+
desc='Number of modalities or features')
584+
warped_intensity_images = InputMultiPath(File(exists=True),
585+
argstr="-g %s...", mandatory=True,
586+
desc='Warped atlas images')
587+
target_image = InputMultiPath(File(exists=True), argstr='-tg %s...',
588+
mandatory=True, desc='Target image(s)')
589+
warped_label_images = InputMultiPath(File(exists=True), argstr="-l %s...",
590+
mandatory=True,
591+
desc='Warped atlas segmentations')
592+
method = traits.Str(default='Joint', argstr='-m %s', usedefault=True,
593+
desc=('Select voting method. Options: Joint (Joint '
594+
'Label Fusion). May be followed by optional '
595+
'parameters in brackets, e.g., -m Joint[0.1,2]'))
596+
alpha = traits.Float(default=0.1, usedefault=True, requires=['method'],
597+
desc=('Regularization term added to matrix Mx for '
598+
'inverse'))
599+
beta = traits.Int(default=2, usedefault=True, requires=['method'],
600+
desc=('Exponent for mapping intensity difference to joint'
601+
' error'))
602+
output_label_image = File(argstr='%s', mandatory=True, position=-1,
603+
name_template='%s',
604+
output_name='output_label_image',
605+
desc='Output fusion label map image')
606+
patch_radius = traits.ListInt(minlen=3, maxlen=3, argstr='-rp %s',
607+
desc=('Patch radius for similarity measures, '
608+
'scalar or vector. Default: 2x2x2'))
609+
search_radius = traits.ListInt(minlen=3, maxlen=3, argstr='-rs %s',
610+
desc='Local search radius. Default: 3x3x3')
611+
exclusion_region = File(exists=True, argstr='-x %s',
612+
desc=('Specify an exclusion region for the given '
613+
'label.'))
614+
atlas_group_id = traits.ListInt(argstr='-gp %d...',
615+
desc=('Assign a group ID for each atlas'))
616+
atlas_group_weights = traits.ListInt(argstr='-gpw %d...',
617+
desc=('Assign the voting weights to '
618+
'each atlas group'))
602619

603620

604621
class JointFusionOutputSpec(TraitedSpec):
605-
output_label_image = File(exists=True)
606-
# TODO: These are almost never needed except for debugging,
607-
# so delay complicated implementation until a need arises
608-
# optional outputs - output_posteriors, output_voting_weights
622+
output_label_image = File(exists=True, desc='Output fusion label map image')
623+
609624

610625
class JointFusion(ANTSCommand):
611626
"""
@@ -657,8 +672,3 @@ def _format_arg(self, opt, spec, val):
657672
assert len(val) == len(self.inputs.warped_label_images), "Number of intensity images and label maps must be the same"
658673
return super(ANTSCommand, self)._format_arg(opt, spec, val)
659674
return retval
660-
661-
def _list_outputs(self):
662-
outputs = self._outputs().get()
663-
outputs['output_label_image'] = os.path.abspath(self.inputs.output_label_image)
664-
return outputs
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.ants.segmentation import JointFusion
4+
5+
def test_JointFusion_inputs():
6+
input_map = dict(alpha=dict(requires=['method'],
7+
usedefault=True,
8+
),
9+
args=dict(argstr='%s',
10+
),
11+
atlas_group_id=dict(argstr='-gp %d...',
12+
),
13+
atlas_group_weights=dict(argstr='-gpw %d...',
14+
),
15+
beta=dict(requires=['method'],
16+
usedefault=True,
17+
),
18+
dimension=dict(argstr='%d',
19+
mandatory=True,
20+
position=0,
21+
usedefault=True,
22+
),
23+
environ=dict(nohash=True,
24+
usedefault=True,
25+
),
26+
exclusion_region=dict(argstr='-x %s',
27+
),
28+
ignore_exception=dict(nohash=True,
29+
usedefault=True,
30+
),
31+
method=dict(argstr='-m %s',
32+
usedefault=True,
33+
),
34+
modalities=dict(argstr='%d',
35+
mandatory=True,
36+
position=1,
37+
),
38+
num_threads=dict(nohash=True,
39+
usedefault=True,
40+
),
41+
output_label_image=dict(argstr='%s',
42+
mandatory=True,
43+
name_template='%s',
44+
output_name='output_label_image',
45+
position=-1,
46+
),
47+
patch_radius=dict(argstr='-rp %s',
48+
maxlen=3,
49+
minlen=3,
50+
),
51+
search_radius=dict(argstr='-rs %s',
52+
maxlen=3,
53+
minlen=3,
54+
),
55+
target_image=dict(argstr='-tg %s...',
56+
mandatory=True,
57+
),
58+
terminal_output=dict(nohash=True,
59+
),
60+
warped_intensity_images=dict(argstr='-g %s...',
61+
mandatory=True,
62+
),
63+
warped_label_images=dict(argstr='-l %s...',
64+
mandatory=True,
65+
),
66+
)
67+
inputs = JointFusion.input_spec()
68+
69+
for key, metadata in input_map.items():
70+
for metakey, value in metadata.items():
71+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
72+
73+
def test_JointFusion_outputs():
74+
output_map = dict(output_label_image=dict(),
75+
)
76+
outputs = JointFusion.output_spec()
77+
78+
for key, metadata in output_map.items():
79+
for metakey, value in metadata.items():
80+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
81+

nipype/interfaces/ants/tests/test_auto_Registration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def test_Registration_inputs():
2424
),
2525
fixed_image_mask=dict(argstr='%s',
2626
),
27+
float=dict(argstr='--float %d',
28+
),
2729
ignore_exception=dict(nohash=True,
2830
usedefault=True,
2931
),

nipype/interfaces/ants/tests/test_JointFusion.py renamed to nipype/interfaces/ants/tests/test_spec_JointFusion.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
from nose import with_setup
2-
from nipype.testing import assert_equal, assert_raises
1+
from nipype.testing import assert_equal, assert_raises, example_data
32
from nipype.interfaces.base import InputMultiPath
43
from traits.trait_errors import TraitError
54
from nipype.interfaces.ants import JointFusion
@@ -54,24 +53,24 @@ def test_JointFusion_cmd():
5453
at.inputs.dimension = 3
5554
at.inputs.modalities = 1
5655
at.inputs.method = 'Joint[0.1,2]'
57-
at.inputs.output_label_image ='fusion_labelimage_output.nii'
58-
at.inputs.warped_intensity_images = ['im1.nii',
59-
'im2.nii']
60-
at.inputs.warped_label_images = ['segmentation0.nii.gz',
61-
'segmentation1.nii.gz']
62-
at.inputs.target_image = 'T1.nii'
56+
at.inputs.output_label_image = 'fusion_labelimage_output.nii'
57+
warped_intensity_images = [example_data('im1.nii'),
58+
example_data('im2.nii')]
59+
at.inputs.warped_intensity_images = warped_intensity_images
60+
segmentation_images = [example_data('segmentation0.nii.gz'),
61+
example_data('segmentation1.nii.gz')]
62+
at.inputs.warped_label_images = segmentation_images
63+
T1_image = example_data('T1.nii')
64+
at.inputs.target_image = T1_image
6365
at.inputs.patch_radius = [3,2,1]
6466
at.inputs.search_radius = [1,2,3]
65-
yield assert_equal, at.cmdline, 'jointfusion 3 1' + \
66-
' -m Joint[0.1,2]' + \
67-
' -rp 3x2x1' + \
68-
' -rs 1x2x3' + \
69-
' -tg T1.nii' + \
70-
' -g im1.nii' + \
71-
' -g im2.nii' + \
72-
' -l segmentation0.nii.gz' + \
73-
' -l segmentation1.nii.gz' + \
74-
' fusion_labelimage_output.nii',
75-
"Command line generation failure", True
67+
expected_command = ('jointfusion 3 1 -m Joint[0.1,2] -rp 3x2x1 -rs 1x2x3'
68+
' -tg %s -g %s -g %s -l %s -l %s'
69+
' fusion_labelimage_output.nii') % (T1_image,
70+
warped_intensity_images[0],
71+
warped_intensity_images[1],
72+
segmentation_images[0],
73+
segmentation_images[1])
74+
yield assert_equal, at.cmdline, expected_command
7675
# setting intensity or labels with unequal lengths raises error
77-
yield assert_raises, AssertionError, at._format_arg, 'warped_intensity_images', InputMultiPath, ['im1.nii', 'im2.nii', 'im3.nii']
76+
yield assert_raises, AssertionError, at._format_arg, 'warped_intensity_images', InputMultiPath, warped_intensity_images + [example_data('im3.nii')]

nipype/interfaces/dipy/tensors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class DTIInputSpec(TraitedSpec):
7171
desc='The input b-vector text file')
7272
bvals = File(exists=True, mandatory=True,
7373
desc='The input b-value text file')
74-
mask_file = File(exists=True, mandatory=False,
74+
mask_file = File(exists=True,
7575
desc='An optional white matter mask')
7676
out_filename = File(
7777
genfile=True, desc='The output filename for the DTI parameters image')
@@ -133,7 +133,7 @@ class TensorModeInputSpec(TraitedSpec):
133133
desc='The input b-vector text file')
134134
bvals = File(exists=True, mandatory=True,
135135
desc='The input b-value text file')
136-
mask_file = File(exists=True, mandatory=False,
136+
mask_file = File(exists=True,
137137
desc='An optional white matter mask')
138138
out_filename = File(
139139
genfile=True, desc='The output filename for the Tensor mode image')

nipype/interfaces/dipy/tests/test_auto_DTI.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def test_DTI_inputs():
99
),
1010
in_file=dict(mandatory=True,
1111
),
12-
mask_file=dict(mandatory=False,
13-
),
12+
mask_file=dict(),
1413
out_filename=dict(genfile=True,
1514
),
1615
)

nipype/interfaces/dipy/tests/test_auto_TensorMode.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def test_TensorMode_inputs():
99
),
1010
in_file=dict(mandatory=True,
1111
),
12-
mask_file=dict(mandatory=False,
13-
),
12+
mask_file=dict(),
1413
out_filename=dict(genfile=True,
1514
),
1615
)

nipype/interfaces/elastix/tests/test_auto_AnalyzeWarp.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def test_AnalyzeWarp_inputs():
1212
usedefault=True,
1313
),
1414
num_threads=dict(argstr='-threads %01d',
15+
nohash=True,
1516
),
1617
output_path=dict(argstr='-out %s',
1718
mandatory=True,

0 commit comments

Comments
 (0)