@@ -130,6 +130,8 @@ def _run_interface(self, runtime):
130
130
131
131
132
132
class AFNICommandInputSpec (CommandLineInputSpec ):
133
+ num_threads = traits .Int (1 , usedefault = True , nohash = True ,
134
+ desc = 'set number of threads' )
133
135
outputtype = traits .Enum ('AFNI' , list (Info .ftypes .keys ()),
134
136
desc = 'AFNI output filetype' )
135
137
out_file = File (name_template = "%s_afni" , desc = 'output image file name' ,
@@ -141,6 +143,7 @@ class AFNICommandOutputSpec(TraitedSpec):
141
143
out_file = File (desc = 'output file' ,
142
144
exists = True )
143
145
146
+
144
147
class AFNICommand (AFNICommandBase ):
145
148
"""Shared options for several AFNI commands """
146
149
input_spec = AFNICommandInputSpec
@@ -172,9 +175,33 @@ class AFNICommand(AFNICommandBase):
172
175
'tags' : ['implementation' ],
173
176
}]
174
177
178
+ @property
179
+ def num_threads (self ):
180
+ return self .inputs .num_threads
181
+
182
+ @num_threads .setter
183
+ def num_threads (self , value ):
184
+ self .inputs .num_threads = value
185
+
186
+ @classmethod
187
+ def set_default_output_type (cls , outputtype ):
188
+ """Set the default output type for AFNI classes.
189
+
190
+ This method is used to set the default output type for all afni
191
+ subclasses. However, setting this will not update the output
192
+ type for any existing instances. For these, assign the
193
+ <instance>.inputs.outputtype.
194
+ """
195
+
196
+ if outputtype in Info .ftypes :
197
+ cls ._outputtype = outputtype
198
+ else :
199
+ raise AttributeError ('Invalid AFNI outputtype: %s' % outputtype )
200
+
175
201
def __init__ (self , ** inputs ):
176
202
super (AFNICommand , self ).__init__ (** inputs )
177
203
self .inputs .on_trait_change (self ._output_update , 'outputtype' )
204
+ self .inputs .on_trait_change (self ._nthreads_update , 'num_threads' )
178
205
179
206
if self ._outputtype is None :
180
207
self ._outputtype = Info .outputtype ()
@@ -184,11 +211,9 @@ def __init__(self, **inputs):
184
211
else :
185
212
self ._output_update ()
186
213
187
- def _run_interface (self , runtime ):
188
- # Update num threads estimate from OMP_NUM_THREADS env var
189
- # Default to 1 if not set
190
- self .inputs .environ ['OMP_NUM_THREADS' ] = str (self .num_threads )
191
- return super (AFNICommand , self )._run_interface (runtime )
214
+ def _nthreads_update (self ):
215
+ """Update environment with new number of threads"""
216
+ self .inputs .environ ['OMP_NUM_THREADS' ] = '%d' % self .inputs .num_threads
192
217
193
218
def _output_update (self ):
194
219
""" i think? updates class private attribute based on instance input
@@ -197,21 +222,6 @@ def _output_update(self):
197
222
"""
198
223
self ._outputtype = self .inputs .outputtype
199
224
200
- @classmethod
201
- def set_default_output_type (cls , outputtype ):
202
- """Set the default output type for AFNI classes.
203
-
204
- This method is used to set the default output type for all afni
205
- subclasses. However, setting this will not update the output
206
- type for any existing instances. For these, assign the
207
- <instance>.inputs.outputtype.
208
- """
209
-
210
- if outputtype in Info .ftypes :
211
- cls ._outputtype = outputtype
212
- else :
213
- raise AttributeError ('Invalid AFNI outputtype: %s' % outputtype )
214
-
215
225
def _overload_extension (self , value , name = None ):
216
226
path , base , _ = split_filename (value )
217
227
return os .path .join (path , base + Info .output_type_to_ext (self .inputs .outputtype ))
@@ -274,6 +284,7 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True,
274
284
use_ext = False , newpath = cwd )
275
285
return fname
276
286
287
+
277
288
def no_afni ():
278
289
""" Checks if AFNI is available """
279
290
if Info .version () is None :
@@ -285,8 +296,9 @@ class AFNIPythonCommandInputSpec(CommandLineInputSpec):
285
296
outputtype = traits .Enum ('AFNI' , list (Info .ftypes .keys ()),
286
297
desc = 'AFNI output filetype' )
287
298
py27_path = traits .Either ('python2' , File (exists = True ),
288
- usedefault = True ,
289
- default = 'python2' )
299
+ usedefault = True ,
300
+ default = 'python2' )
301
+
290
302
291
303
class AFNIPythonCommand (AFNICommand ):
292
304
@property
0 commit comments