44"""Provide interface to AFNI commands."""
55from __future__ import (print_function , division , unicode_literals ,
66 absolute_import )
7- from builtins import object , str
87from future .utils import raise_from
98
109import os
1110from sys import platform
1211from distutils import spawn
1312
1413from ... import logging , LooseVersion
15- from ...utils .filemanip import split_filename , fname_presuffix
16-
14+ from ...utils .filemanip import split_filename
1715from ..base import (CommandLine , traits , CommandLineInputSpec , isdefined , File ,
1816 TraitedSpec , PackageInfo )
1917from ...external .due import BibTeX
2321
2422
2523class Info (PackageInfo ):
26- """Handle afni output type and version information.
27- """
24+ """Handle afni output type and version information."""
25+
2826 __outputtype = 'AFNI'
2927 ftypes = {'NIFTI' : '.nii' , 'AFNI' : '' , 'NIFTI_GZ' : '.nii.gz' }
3028 version_cmd = 'afni --version'
3129
3230 @staticmethod
3331 def parse_version (raw_info ):
32+ """Check and parse AFNI's version."""
3433 version_stamp = raw_info .split ('\n ' )[0 ].split ('Version ' )[1 ]
3534 if version_stamp .startswith ('AFNI' ):
3635 version_stamp = version_stamp .split ('AFNI_' )[1 ]
@@ -46,7 +45,8 @@ def parse_version(raw_info):
4645
4746 @classmethod
4847 def output_type_to_ext (cls , outputtype ):
49- """Get the file extension for the given output type.
48+ """
49+ Get the file extension for the given output type.
5050
5151 Parameters
5252 ----------
@@ -57,8 +57,8 @@ def output_type_to_ext(cls, outputtype):
5757 -------
5858 extension : str
5959 The file extension for the output type.
60- """
6160
61+ """
6262 try :
6363 return cls .ftypes [outputtype ]
6464 except KeyError as e :
@@ -67,24 +67,28 @@ def output_type_to_ext(cls, outputtype):
6767
6868 @classmethod
6969 def outputtype (cls ):
70- """AFNI has no environment variables,
71- Output filetypes get set in command line calls
72- Nipype uses AFNI as default
70+ """
71+ Set default output filetype.
72+
73+ AFNI has no environment variables, Output filetypes get set in command line calls
74+ Nipype uses ``AFNI`` as default
7375
7476
7577 Returns
7678 -------
7779 None
80+
7881 """
79- # warn(('AFNI has no environment variable that sets filetype '
80- # 'Nipype uses NIFTI_GZ as default'))
8182 return 'AFNI'
8283
8384 @staticmethod
8485 def standard_image (img_name ):
85- '''Grab an image from the standard location.
86+ """
87+ Grab an image from the standard location.
8688
87- Could be made more fancy to allow for more relocatability'''
89+ Could be made more fancy to allow for more relocatability
90+
91+ """
8892 clout = CommandLine (
8993 'which afni' ,
9094 ignore_exception = True ,
@@ -101,6 +105,7 @@ def standard_image(img_name):
101105class AFNICommandBase (CommandLine ):
102106 """
103107 A base class to fix a linking problem in OSX and afni.
108+
104109 See http://afni.nimh.nih.gov/afni/community/board/read.php?1,145346,145347#msg-145347
105110 """
106111
@@ -127,7 +132,8 @@ class AFNICommandOutputSpec(TraitedSpec):
127132
128133
129134class AFNICommand (AFNICommandBase ):
130- """Shared options for several AFNI commands """
135+ """Shared options for several AFNI commands."""
136+
131137 input_spec = AFNICommandInputSpec
132138 _outputtype = None
133139
@@ -162,6 +168,7 @@ class AFNICommand(AFNICommandBase):
162168
163169 @property
164170 def num_threads (self ):
171+ """Get number of threads."""
165172 return self .inputs .num_threads
166173
167174 @num_threads .setter
@@ -170,20 +177,21 @@ def num_threads(self, value):
170177
171178 @classmethod
172179 def set_default_output_type (cls , outputtype ):
173- """Set the default output type for AFNI classes.
180+ """
181+ Set the default output type for AFNI classes.
174182
175183 This method is used to set the default output type for all afni
176184 subclasses. However, setting this will not update the output
177185 type for any existing instances. For these, assign the
178186 <instance>.inputs.outputtype.
179187 """
180-
181188 if outputtype in Info .ftypes :
182189 cls ._outputtype = outputtype
183190 else :
184191 raise AttributeError ('Invalid AFNI outputtype: %s' % outputtype )
185192
186193 def __init__ (self , ** inputs ):
194+ """Instantiate an AFNI command tool wrapper."""
187195 super (AFNICommand , self ).__init__ (** inputs )
188196 self .inputs .on_trait_change (self ._output_update , 'outputtype' )
189197
@@ -199,13 +207,16 @@ def __init__(self, **inputs):
199207 self ._output_update ()
200208
201209 def _nthreads_update (self ):
202- """Update environment with new number of threads"""
210+ """Update environment with new number of threads. """
203211 self .inputs .environ ['OMP_NUM_THREADS' ] = '%d' % self .inputs .num_threads
204212
205213 def _output_update (self ):
206- """ i think? updates class private attribute based on instance input
207- in fsl also updates ENVIRON variable....not valid in afni
208- as it uses no environment variables
214+ """
215+ Update the internal property with the provided input.
216+
217+ i think? updates class private attribute based on instance input
218+ in fsl also updates ENVIRON variable....not valid in afni
219+ as it uses no environment variables
209220 """
210221 self ._outputtype = self .inputs .outputtype
211222
@@ -226,59 +237,9 @@ def _list_outputs(self):
226237 outputs [name ] = outputs [name ] + "+orig.BRIK"
227238 return outputs
228239
229- def _gen_fname (self ,
230- basename ,
231- cwd = None ,
232- suffix = None ,
233- change_ext = True ,
234- ext = None ):
235- """Generate a filename based on the given parameters.
236-
237- The filename will take the form: cwd/basename<suffix><ext>.
238- If change_ext is True, it will use the extentions specified in
239- <instance>intputs.output_type.
240-
241- Parameters
242- ----------
243- basename : str
244- Filename to base the new filename on.
245- cwd : str
246- Path to prefix to the new filename. (default is os.getcwd())
247- suffix : str
248- Suffix to add to the `basename`. (defaults is '' )
249- change_ext : bool
250- Flag to change the filename extension to the FSL output type.
251- (default True)
252-
253- Returns
254- -------
255- fname : str
256- New filename based on given parameters.
257-
258- """
259-
260- if basename == '' :
261- msg = 'Unable to generate filename for command %s. ' % self .cmd
262- msg += 'basename is not set!'
263- raise ValueError (msg )
264- if cwd is None :
265- cwd = os .getcwd ()
266- if ext is None :
267- ext = Info .output_type_to_ext (self .inputs .outputtype )
268- if change_ext :
269- if suffix :
270- suffix = '' .join ((suffix , ext ))
271- else :
272- suffix = ext
273- if suffix is None :
274- suffix = ''
275- fname = fname_presuffix (
276- basename , suffix = suffix , use_ext = False , newpath = cwd )
277- return fname
278-
279240
280241def no_afni ():
281- """ Checks if AFNI is available """
242+ """Check whether AFNI is not available. """
282243 if Info .version () is None :
283244 return True
284245 return False
@@ -292,8 +253,11 @@ class AFNIPythonCommandInputSpec(CommandLineInputSpec):
292253
293254
294255class AFNIPythonCommand (AFNICommand ):
256+ """A subtype of AFNI command line for Python scripts."""
257+
295258 @property
296259 def cmd (self ):
260+ """Revise the command path."""
297261 orig_cmd = super (AFNIPythonCommand , self ).cmd
298262 found = spawn .find_executable (orig_cmd )
299263 return found if found is not None else orig_cmd
0 commit comments