Skip to content

Commit 435c417

Browse files
committed
fixed documentation of fsl.Smooth. Close #1324
1 parent c1e811e commit 435c417

File tree

2 files changed

+49
-22
lines changed

2 files changed

+49
-22
lines changed

nipype/interfaces/fsl/tests/test_auto_Smooth.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ def test_Smooth_inputs():
99
environ=dict(nohash=True,
1010
usedefault=True,
1111
),
12-
fwhm=dict(argstr='-kernel gauss %f -fmean',
13-
mandatory=True,
12+
fwhm=dict(argstr='-kernel gauss %.03f -fmean',
1413
position=1,
14+
xor=['sigma'],
1515
),
1616
ignore_exception=dict(nohash=True,
1717
usedefault=True,
@@ -21,9 +21,14 @@ def test_Smooth_inputs():
2121
position=0,
2222
),
2323
output_type=dict(),
24+
sigma=dict(argstr='-kernel gauss %.03f -fmean',
25+
position=1,
26+
xor=['fwhm'],
27+
),
2428
smoothed_file=dict(argstr='%s',
25-
genfile=True,
2629
hash_files=False,
30+
name_source=['in_file'],
31+
name_template='%s_smooth',
2732
position=2,
2833
),
2934
terminal_output=dict(nohash=True,

nipype/interfaces/fsl/utils.py

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,44 +139,66 @@ def _gen_filename(self, name):
139139

140140
class SmoothInputSpec(FSLCommandInputSpec):
141141
in_file = File(exists=True, argstr="%s", position=0, mandatory=True)
142-
fwhm = traits.Float(argstr="-kernel gauss %f -fmean", position=1,
143-
mandatory=True)
142+
fwhm = traits.Float(
143+
argstr="-kernel gauss %.03f -fmean", position=1, xor=['sigma'],
144+
desc='gaussian kernel fwhm, will be converted to sigma in mm (not voxels)')
145+
sigma = traits.Float(
146+
argstr="-kernel gauss %.03f -fmean", position=1, xor=['fwhm'],
147+
desc='gaussian kernel sigma in mm (not voxels)')
144148
smoothed_file = File(
145-
argstr="%s", position=2, genfile=True, hash_files=False)
149+
argstr="%s", position=2, name_source=['in_file'], name_template='%s_smooth', hash_files=False)
146150

147151

148152
class SmoothOutputSpec(TraitedSpec):
149153
smoothed_file = File(exists=True)
150154

151155

152156
class Smooth(FSLCommand):
153-
'''Use fslmaths to smooth the image
154-
'''
157+
"""
158+
Use fslmaths to smooth the image
159+
160+
Example
161+
-------
162+
163+
>>> from nipype.interfaces.fsl import Smooth
164+
>>> sm = Smooth()
165+
>>> sm.inputs.in_file = 'functional2.nii'
166+
>>> sm.cmdline
167+
Traceback (most recent call last):
168+
...
169+
RuntimeError: either sigma (in mm) or fwhm need be specified.
170+
171+
Setting the kernel width using sigma:
172+
>>> sm = Smooth()
173+
>>> sm.inputs.in_file = 'functional2.nii'
174+
>>> sm.inputs.sigma = 8.0
175+
>>> sm.cmdline #doctest: +ELLIPSIS
176+
'fslmaths functional2.nii -kernel gauss 8.000 -fmean functional2_smooth.nii.gz'
177+
178+
Setting the kernel width using fwhm:
179+
>>> sm = Smooth()
180+
>>> sm.inputs.in_file = 'functional2.nii'
181+
>>> sm.inputs.fwhm = 8.0
182+
>>> sm.cmdline #doctest: +ELLIPSIS
183+
'fslmaths functional2.nii -kernel gauss 3.397 -fmean functional2_smooth.nii.gz'
184+
185+
"""
155186

156187
input_spec = SmoothInputSpec
157188
output_spec = SmoothOutputSpec
158189
_cmd = 'fslmaths'
159190

160-
def _gen_filename(self, name):
161-
if name == 'smoothed_file':
162-
return self._list_outputs()['smoothed_file']
163-
return None
164-
165-
def _list_outputs(self):
166-
outputs = self._outputs().get()
167-
outputs['smoothed_file'] = self.inputs.smoothed_file
168-
if not isdefined(outputs['smoothed_file']):
169-
outputs['smoothed_file'] = self._gen_fname(self.inputs.in_file,
170-
suffix='_smooth')
171-
outputs['smoothed_file'] = os.path.abspath(outputs['smoothed_file'])
172-
return outputs
173-
174191
def _format_arg(self, name, trait_spec, value):
175192
if name == 'fwhm':
176193
sigma = float(value) / np.sqrt(8 * np.log(2))
177194
return super(Smooth, self)._format_arg(name, trait_spec, sigma)
178195
return super(Smooth, self)._format_arg(name, trait_spec, value)
179196

197+
def _parse_inputs(self, skip=None):
198+
if not isdefined(self.inputs.sigma) and not isdefined(self.inputs.fwhm):
199+
raise RuntimeError('either sigma (in mm) or fwhm need be specified.')
200+
return super(Smooth, self)._parse_inputs(skip=skip)
201+
180202

181203
class MergeInputSpec(FSLCommandInputSpec):
182204
in_files = traits.List(File(exists=True), argstr="%s", position=2,

0 commit comments

Comments
 (0)