Skip to content

Commit 8ef0aa2

Browse files
committed
Merge pull request #471 from chrisfilo/fix/ants
ANTS: Removed unnecessary copyfiles and added output_image option.
2 parents c25c00f + ad0fb28 commit 8ef0aa2

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

nipype/interfaces/ants/resampling.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ def _list_outputs(self):
103103
class WarpImageMultiTransformInputSpec(ANTSCommandInputSpec):
104104
dimension = traits.Enum(3, 2, argstr='%d', usedefault=True,
105105
desc='image dimension (2 or 3)', position=1)
106-
input_image = File(argstr='%s', mandatory=True, copyfile=True,
106+
input_image = File(argstr='%s', mandatory=True,
107107
desc=('image to apply transformation to (generally a '
108-
'coregistered functional)') )
109-
out_postfix = traits.Str('_wimt', argstr='%s', usedefault=True,
110-
desc=('Postfix that is prepended to all output '
111-
'files (default = _wimt)'))
108+
'coregistered functional)'), position=2)
109+
output_image = File(genfile=True, usedefault=True, hash_files=False, argstr='%s',
110+
desc=('name of the output warped image'), position = 3, xor=['out_postfix'])
111+
out_postfix = File("_wimt", usedefault=True, hash_files=False,
112+
desc=('Postfix that is prepended to all output '
113+
'files (default = _wimt)'), xor=['output_image'])
112114
reference_image = File(argstr='-R %s', xor=['tightest_box'],
113115
desc='reference image space that you wish to warp INTO')
114116
tightest_box = traits.Bool(argstr='--tightest-bounding-box',
@@ -123,13 +125,16 @@ class WarpImageMultiTransformInputSpec(ANTSCommandInputSpec):
123125
desc='Use nearest neighbor interpolation')
124126
use_bspline = traits.Bool(argstr='--use-Bspline',
125127
desc='Use 3rd order B-Spline interpolation')
126-
transformation_series = InputMultiPath(File(exists=True, copyfile=False), argstr='%s',
128+
transformation_series = InputMultiPath(File(exists=True), argstr='%s',
127129
desc='transformation file(s) to be applied',
128-
mandatory=True, copyfile=False)
130+
mandatory=True)
129131
invert_affine = traits.List(traits.Int,
130-
desc=('List of Affine transformations to invert. '
132+
desc=('List of Affine transformations to invert.'
131133
'E.g.: [1,4,5] inverts the 1st, 4th, and 5th Affines '
132-
'found in transformation_series'))
134+
'found in transformation_series. Note that indexing '
135+
'starts with 1 and does not include warp fields. Affine '
136+
'transformations are distinguished '
137+
'from warp fields by the word "affine" included in their filenames.'))
133138

134139
class WarpImageMultiTransformOutputSpec(TraitedSpec):
135140
output_image = File(exists=True, desc='Warped image')
@@ -161,16 +166,19 @@ class WarpImageMultiTransform(ANTSCommand):
161166
_cmd = 'WarpImageMultiTransform'
162167
input_spec = WarpImageMultiTransformInputSpec
163168
output_spec = WarpImageMultiTransformOutputSpec
169+
170+
def _gen_filename(self, name):
171+
if name == 'out_file':
172+
_, name, ext = split_filename(os.path.abspath(self.inputs.input_image))
173+
return ''.join((name, self.inputs.out_postfix, ext))
174+
return None
164175

165176
def _format_arg(self, opt, spec, val):
166-
if opt == 'out_postfix':
167-
_, name, ext = split_filename(os.path.abspath(self.inputs.input_image))
168-
return name + val + ext
169177
if opt == 'transformation_series':
170178
series = []
171179
affine_counter = 0
172180
for transformation in val:
173-
if 'Affine' in transformation and \
181+
if "affine" in transformation.lower() and \
174182
isdefined(self.inputs.invert_affine):
175183
affine_counter += 1
176184
if affine_counter in self.inputs.invert_affine:
@@ -181,11 +189,10 @@ def _format_arg(self, opt, spec, val):
181189

182190
def _list_outputs(self):
183191
outputs = self._outputs().get()
184-
_, name, ext = split_filename(os.path.abspath(self.inputs.input_image))
185-
outputs['output_image'] = os.path.join(os.getcwd(),
186-
''.join((name,
187-
self.inputs.out_postfix,
188-
ext)))
192+
if isdefined(self.inputs.output_image):
193+
outputs['output_image'] = os.path.abspath(self.inputs.output_image)
194+
else:
195+
outputs['output_image'] = os.path.abspath(self._gen_filename('output_image'))
189196
return outputs
190197

191198

0 commit comments

Comments
 (0)