@@ -139,44 +139,66 @@ def _gen_filename(self, name):
139
139
140
140
class SmoothInputSpec (FSLCommandInputSpec ):
141
141
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)' )
144
148
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 )
146
150
147
151
148
152
class SmoothOutputSpec (TraitedSpec ):
149
153
smoothed_file = File (exists = True )
150
154
151
155
152
156
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
+ """
155
186
156
187
input_spec = SmoothInputSpec
157
188
output_spec = SmoothOutputSpec
158
189
_cmd = 'fslmaths'
159
190
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
-
174
191
def _format_arg (self , name , trait_spec , value ):
175
192
if name == 'fwhm' :
176
193
sigma = float (value ) / np .sqrt (8 * np .log (2 ))
177
194
return super (Smooth , self )._format_arg (name , trait_spec , sigma )
178
195
return super (Smooth , self )._format_arg (name , trait_spec , value )
179
196
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
+
180
202
181
203
class MergeInputSpec (FSLCommandInputSpec ):
182
204
in_files = traits .List (File (exists = True ), argstr = "%s" , position = 2 ,
0 commit comments