Skip to content

[ENH] Improvements on fsl.Smooth #1341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ before_install:
fi
- if $INSTALL_DEB_DEPENDECIES; then source /etc/fsl/fsl.sh; fi
- if $INSTALL_DEB_DEPENDECIES; then source /etc/afni/afni.sh; fi
- export FSLOUTPUTTYPE=NIFTI_GZ
install:
- conda update --yes conda
- conda create -n testenv --yes pip python=$TRAVIS_PYTHON_VERSION
Expand Down
11 changes: 9 additions & 2 deletions nipype/interfaces/fsl/tests/test_auto_Smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ def test_Smooth_inputs():
environ=dict(nohash=True,
usedefault=True,
),
fwhm=dict(argstr='-kernel gauss %f -fmean',
fwhm=dict(argstr='-kernel gauss %.03f -fmean',
mandatory=True,
position=1,
xor=['sigma'],
),
ignore_exception=dict(nohash=True,
usedefault=True,
Expand All @@ -21,9 +22,15 @@ def test_Smooth_inputs():
position=0,
),
output_type=dict(),
sigma=dict(argstr='-kernel gauss %.03f -fmean',
mandatory=True,
position=1,
xor=['fwhm'],
),
smoothed_file=dict(argstr='%s',
genfile=True,
hash_files=False,
name_source=['in_file'],
name_template='%s_smooth',
position=2,
),
terminal_output=dict(nohash=True,
Expand Down
59 changes: 40 additions & 19 deletions nipype/interfaces/fsl/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,38 +139,59 @@ def _gen_filename(self, name):

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


class SmoothOutputSpec(TraitedSpec):
smoothed_file = File(exists=True)


class Smooth(FSLCommand):
'''Use fslmaths to smooth the image
'''
"""
Use fslmaths to smooth the image

Examples
--------

Setting the kernel width using sigma:

>>> sm = Smooth()
>>> sm.inputs.in_file = 'functional2.nii'
>>> sm.inputs.sigma = 8.0
>>> sm.cmdline #doctest: +ELLIPSIS
'fslmaths functional2.nii -kernel gauss 8.000 -fmean functional2_smooth.nii.gz'

Setting the kernel width using fwhm:

>>> sm = Smooth()
>>> sm.inputs.in_file = 'functional2.nii'
>>> sm.inputs.fwhm = 8.0
>>> sm.cmdline #doctest: +ELLIPSIS
'fslmaths functional2.nii -kernel gauss 3.397 -fmean functional2_smooth.nii.gz'

One of sigma or fwhm must be set:

>>> from nipype.interfaces.fsl import Smooth
>>> sm = Smooth()
>>> sm.inputs.in_file = 'functional2.nii'
>>> sm.cmdline #doctest: +ELLIPSIS
Traceback (most recent call last):
...
ValueError: Smooth requires a value for one of the inputs ...

"""

input_spec = SmoothInputSpec
output_spec = SmoothOutputSpec
_cmd = 'fslmaths'

def _gen_filename(self, name):
if name == 'smoothed_file':
return self._list_outputs()['smoothed_file']
return None

def _list_outputs(self):
outputs = self._outputs().get()
outputs['smoothed_file'] = self.inputs.smoothed_file
if not isdefined(outputs['smoothed_file']):
outputs['smoothed_file'] = self._gen_fname(self.inputs.in_file,
suffix='_smooth')
outputs['smoothed_file'] = os.path.abspath(outputs['smoothed_file'])
return outputs

def _format_arg(self, name, trait_spec, value):
if name == 'fwhm':
sigma = float(value) / np.sqrt(8 * np.log(2))
Expand Down