Skip to content

Commit 267e42a

Browse files
committed
Merge pull request #1341 from oesteban/enh/DocFSLUtils
[ENH] Improvements on fsl.Smooth
2 parents c1e811e + 1f9f942 commit 267e42a

File tree

3 files changed

+50
-21
lines changed

3 files changed

+50
-21
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ before_install:
2424
fi
2525
- if $INSTALL_DEB_DEPENDECIES; then source /etc/fsl/fsl.sh; fi
2626
- if $INSTALL_DEB_DEPENDECIES; then source /etc/afni/afni.sh; fi
27+
- export FSLOUTPUTTYPE=NIFTI_GZ
2728
install:
2829
- conda update --yes conda
2930
- conda create -n testenv --yes pip python=$TRAVIS_PYTHON_VERSION

nipype/interfaces/fsl/tests/test_auto_Smooth.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ def test_Smooth_inputs():
99
environ=dict(nohash=True,
1010
usedefault=True,
1111
),
12-
fwhm=dict(argstr='-kernel gauss %f -fmean',
12+
fwhm=dict(argstr='-kernel gauss %.03f -fmean',
1313
mandatory=True,
1414
position=1,
15+
xor=['sigma'],
1516
),
1617
ignore_exception=dict(nohash=True,
1718
usedefault=True,
@@ -21,9 +22,15 @@ def test_Smooth_inputs():
2122
position=0,
2223
),
2324
output_type=dict(),
25+
sigma=dict(argstr='-kernel gauss %.03f -fmean',
26+
mandatory=True,
27+
position=1,
28+
xor=['fwhm'],
29+
),
2430
smoothed_file=dict(argstr='%s',
25-
genfile=True,
2631
hash_files=False,
32+
name_source=['in_file'],
33+
name_template='%s_smooth',
2734
position=2,
2835
),
2936
terminal_output=dict(nohash=True,

nipype/interfaces/fsl/utils.py

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -139,38 +139,59 @@ 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+
sigma = traits.Float(
143+
argstr="-kernel gauss %.03f -fmean", position=1, xor=['fwhm'], mandatory=True,
144+
desc='gaussian kernel sigma in mm (not voxels)')
145+
fwhm = traits.Float(
146+
argstr="-kernel gauss %.03f -fmean", position=1, xor=['sigma'], mandatory=True,
147+
desc='gaussian kernel fwhm, will be converted to 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+
Examples
161+
--------
162+
163+
Setting the kernel width using sigma:
164+
165+
>>> sm = Smooth()
166+
>>> sm.inputs.in_file = 'functional2.nii'
167+
>>> sm.inputs.sigma = 8.0
168+
>>> sm.cmdline #doctest: +ELLIPSIS
169+
'fslmaths functional2.nii -kernel gauss 8.000 -fmean functional2_smooth.nii.gz'
170+
171+
Setting the kernel width using fwhm:
172+
173+
>>> sm = Smooth()
174+
>>> sm.inputs.in_file = 'functional2.nii'
175+
>>> sm.inputs.fwhm = 8.0
176+
>>> sm.cmdline #doctest: +ELLIPSIS
177+
'fslmaths functional2.nii -kernel gauss 3.397 -fmean functional2_smooth.nii.gz'
178+
179+
One of sigma or fwhm must be set:
180+
181+
>>> from nipype.interfaces.fsl import Smooth
182+
>>> sm = Smooth()
183+
>>> sm.inputs.in_file = 'functional2.nii'
184+
>>> sm.cmdline #doctest: +ELLIPSIS
185+
Traceback (most recent call last):
186+
...
187+
ValueError: Smooth requires a value for one of the inputs ...
188+
189+
"""
155190

156191
input_spec = SmoothInputSpec
157192
output_spec = SmoothOutputSpec
158193
_cmd = 'fslmaths'
159194

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-
174195
def _format_arg(self, name, trait_spec, value):
175196
if name == 'fwhm':
176197
sigma = float(value) / np.sqrt(8 * np.log(2))

0 commit comments

Comments
 (0)