@@ -139,44 +139,66 @@ def _gen_filename(self, name):
139139
140140class 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
148152class SmoothOutputSpec (TraitedSpec ):
149153 smoothed_file = File (exists = True )
150154
151155
152156class 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
181203class MergeInputSpec (FSLCommandInputSpec ):
182204 in_files = traits .List (File (exists = True ), argstr = "%s" , position = 2 ,
0 commit comments