Skip to content

Commit 15dae8e

Browse files
committed
fix trait all_rois and tests
1 parent f907499 commit 15dae8e

File tree

2 files changed

+71
-8
lines changed

2 files changed

+71
-8
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..utils import CenterMass
4+
5+
6+
def test_CenterMass_inputs():
7+
input_map = dict(all_rois=dict(argstr='-all_rois',
8+
),
9+
args=dict(argstr='%s',
10+
),
11+
automask=dict(argstr='-automask',
12+
),
13+
cm_file=dict(argstr='> %s',
14+
descr='File to write center of mass to',
15+
keep_extension=False,
16+
name_source='in_file',
17+
name_template='%s_cm.out',
18+
position=-1,
19+
),
20+
environ=dict(nohash=True,
21+
usedefault=True,
22+
),
23+
ignore_exception=dict(nohash=True,
24+
usedefault=True,
25+
),
26+
in_file=dict(argstr='%s',
27+
copyfile=True,
28+
mandatory=True,
29+
position=-2,
30+
),
31+
local_ijk=dict(argstr='-local_ijk',
32+
),
33+
mask_file=dict(argstr='-mask %s',
34+
),
35+
roi_vals=dict(argstr='-roi_vals %s',
36+
),
37+
set_cm=dict(argstr='-set %f %f %f',
38+
),
39+
terminal_output=dict(nohash=True,
40+
),
41+
)
42+
inputs = CenterMass.input_spec()
43+
44+
for key, metadata in list(input_map.items()):
45+
for metakey, value in list(metadata.items()):
46+
assert getattr(inputs.traits()[key], metakey) == value
47+
48+
49+
def test_CenterMass_outputs():
50+
output_map = dict(cm=dict(),
51+
cm_file=dict(),
52+
out_file=dict(),
53+
)
54+
outputs = CenterMass.output_spec()
55+
56+
for key, metadata in list(output_map.items()):
57+
for metakey, value in list(metadata.items()):
58+
assert getattr(outputs.traits()[key], metakey) == value

nipype/interfaces/afni/utils.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ class CenterMassInputSpec(CommandLineInputSpec):
656656
name_template='%s_cm.out',
657657
keep_extension=False,
658658
descr="File to write center of mass to",
659-
argstr=" > %s",
659+
argstr="> %s",
660660
position=-1)
661661
mask_file = File(
662662
desc='Only voxels with nonzero values in the provided mask will be '
@@ -681,7 +681,7 @@ class CenterMassInputSpec(CommandLineInputSpec):
681681
'v1, v2, etc. This option is handy for getting ROI centers of '
682682
'mass.',
683683
argstr='-roi_vals %s')
684-
automask = traits.Bool(
684+
all_rois = traits.Bool(
685685
desc='Don\'t bother listing the values of ROIs you want: The program '
686686
'will find all of them and produce a full list',
687687
argstr='-all_rois')
@@ -693,8 +693,10 @@ class CenterMassOutputSpec(TraitedSpec):
693693
desc='output file')
694694
cm_file = File(
695695
desc='file with the center of mass coordinates')
696-
cm = traits.Tuple(
697-
traits.Float(), traits.Float(), traits.Float(),
696+
cm = traits.Either(
697+
traits.Tuple(traits.Float(), traits.Float(), traits.Float()),
698+
traits.List(traits.Tuple(traits.Float(), traits.Float(),
699+
traits.Float())),
698700
desc='center of mass')
699701

700702

@@ -716,10 +718,10 @@ class CenterMass(AFNICommandBase):
716718
>>> from nipype.interfaces import afni
717719
>>> cm = afni.CenterMass()
718720
>>> cm.inputs.in_file = 'structural.nii'
719-
>>> cm.inputs.out_file = 'cm.txt'
720-
>>> cm.inputs.set_cm = (0, 0, 0)
721+
>>> cm.inputs.cm_file = 'cm.txt'
722+
>>> cm.inputs.roi_vals = [2, 10]
721723
>>> cm.cmdline # doctest: +ALLOW_UNICODE
722-
'3dcm -set 0 0 0 structural.nii > cm.txt'
724+
'3dCM -roi_vals 2 10 structural.nii > cm.txt'
723725
>>> res = 3dcm.run() # doctest: +SKIP
724726
"""
725727

@@ -732,7 +734,10 @@ def _list_outputs(self):
732734
outputs['out_file'] = os.path.abspath(self.inputs.in_file)
733735
outputs['cm_file'] = os.path.abspath(self.inputs.cm_file)
734736
sout = np.loadtxt(outputs['cm_file']) # pylint: disable=E1101
735-
outputs['cm'] = tuple(sout)
737+
if len(sout) > 1:
738+
outputs['cm'] = [tuple(s) for s in sout]
739+
else:
740+
outputs['cm'] = tuple(sout)
736741
return outputs
737742

738743

0 commit comments

Comments
 (0)