@@ -139,38 +139,59 @@ 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+ 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
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+ 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