Skip to content

Commit 2ed1344

Browse files
committed
ENH: Uses name_source/name_template instead of genfile
This removes the genfile and _gen_filename function. It now uses the name_source and name_template options to simplify the interface.
1 parent 334272c commit 2ed1344

File tree

2 files changed

+15
-40
lines changed

2 files changed

+15
-40
lines changed

nipype/interfaces/ants/segmentation.py

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,16 @@ class DenoiseImageInputSpec(ANTSCommandInputSpec):
813813
'the input image can be resampled. The shrink '
814814
'factor, specified as a single integer, describes '
815815
'this resampling. Shrink factor = 1 is the default.'))
816-
output_image = traits.Str(argstr="-o %s", genfile=True, hash_files=False,
817-
desc='The output consists of the noise corrected '
818-
'version of the input image.')
816+
output_image = File(argstr="-o %s", name_source=['input_image'], hash_files=False,
817+
keep_extension=True, name_template='%s_noise_corrected',
818+
desc='The output consists of the noise corrected '
819+
'version of the input image.')
819820
save_noise = traits.Bool(False, mandatory=True, usedefault=True,
820821
desc=('True if the estimated noise should be saved '
821822
'to file.'), xor=['noise_image'])
822-
noise_image = File(desc='Filename for the estimated noise.', hash_files=False)
823+
noise_image = File(name_source=['input_image'], hash_files=False,
824+
keep_extension=True, name_template='%s_noise',
825+
desc='Filename for the estimated noise.')
823826
verbose = traits.Bool(False, argstr="-v", desc=('Verbose output.'))
824827

825828

@@ -857,45 +860,12 @@ class DenoiseImage(ANTSCommand):
857860
output_spec = DenoiseImageOutputSpec
858861
_cmd = 'DenoiseImage'
859862

860-
def _gen_filename(self, name):
861-
if name == 'output_image':
862-
output = self.inputs.output_image
863-
if not isdefined(output):
864-
_, name, ext = split_filename(self.inputs.input_image)
865-
output = name + '_noise_corrected' + ext
866-
return output
867-
868-
if name == 'noise_image':
869-
output = self.inputs.noise_image
870-
if not isdefined(output):
871-
_, name, ext = split_filename(self.inputs.input_image)
872-
output = name + '_noise' + ext
873-
return output
874-
return None
875-
876863
def _format_arg(self, name, trait_spec, value):
877864
if ((name == 'output_image') and
878865
(self.inputs.save_noise or isdefined(self.inputs.noise_image))):
879-
noise_image = self._gen_filename('noise_image')
880-
output = self._gen_filename('output_image')
881-
newval = '[ %s, %s ]' % (output, noise_image)
866+
newval = '[ %s, %s ]' % (self._filename_from_source('output_image'),
867+
self._filename_from_source('noise_image'))
882868
return trait_spec.argstr % newval
883869

884870
return super(DenoiseImage,
885871
self)._format_arg(name, trait_spec, value)
886-
887-
def _parse_inputs(self, skip=None):
888-
if skip is None:
889-
skip = []
890-
skip += ['save_noise', 'noise_image']
891-
return super(DenoiseImage, self)._parse_inputs(skip=skip)
892-
893-
def _list_outputs(self):
894-
outputs = self._outputs().get()
895-
outputs['output_image'] = os.path.abspath(
896-
self._gen_filename('output_image'))
897-
898-
if self.inputs.save_noise or isdefined(self.inputs.noise_image):
899-
outputs['noise_image'] = os.path.abspath(
900-
self._gen_filename('noise_image'))
901-
return outputs

nipype/interfaces/ants/tests/test_auto_DenoiseImage.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def test_DenoiseImage_inputs():
1919
mandatory=True,
2020
),
2121
noise_image=dict(hash_files=False,
22+
keep_extension=True,
23+
name_source=['input_image'],
24+
name_template='%s_noise',
2225
),
2326
noise_model=dict(argstr='-n %s',
2427
usedefault=True,
@@ -27,8 +30,10 @@ def test_DenoiseImage_inputs():
2730
usedefault=True,
2831
),
2932
output_image=dict(argstr='-o %s',
30-
genfile=True,
3133
hash_files=False,
34+
keep_extension=True,
35+
name_source=['input_image'],
36+
name_template='%s_noise_corrected',
3237
),
3338
save_noise=dict(mandatory=True,
3439
usedefault=True,

0 commit comments

Comments
 (0)