1010"""
1111
1212import os
13- from sys import platform
1413import os .path as op
1514import re
1615import numpy as np
1716
18- from .base import AFNICommand , AFNICommandInputSpec , AFNICommandOutputSpec , Info , no_afni
19- from ..base import CommandLineInputSpec , CommandLine
17+ from .base import (AFNICommandBase , AFNICommand , AFNICommandInputSpec , AFNICommandOutputSpec ,
18+ Info , no_afni )
19+ from ..base import CommandLineInputSpec
2020from ..base import (Directory , TraitedSpec ,
2121 traits , isdefined , File , InputMultiPath , Undefined )
2222from ...external .six import string_types
@@ -182,7 +182,7 @@ class RefitInputSpec(CommandLineInputSpec):
182182 ' template type, e.g. TLRC, MNI, ORIG' )
183183
184184
185- class Refit (CommandLine ):
185+ class Refit (AFNICommandBase ):
186186 """Changes some of the information inside a 3D dataset's header
187187
188188 For complete details, see the `3drefit Documentation.
@@ -1546,7 +1546,7 @@ class ROIStatsOutputSpec(TraitedSpec):
15461546 stats = File (desc = 'output tab separated values file' , exists = True )
15471547
15481548
1549- class ROIStats (CommandLine ):
1549+ class ROIStats (AFNICommandBase ):
15501550 """Display statistics over masked regions
15511551
15521552 For complete details, see the `3dROIstats Documentation.
@@ -2115,7 +2115,7 @@ class HistOutputSpec(TraitedSpec):
21152115 out_show = File (desc = 'output visual histogram' )
21162116
21172117
2118- class Hist (CommandLine ):
2118+ class Hist (AFNICommandBase ):
21192119 """Computes average of all voxels in the input dataset
21202120 which satisfy the criterion in the options list
21212121
@@ -2197,8 +2197,8 @@ class FWHMxInputSpec(CommandLineInputSpec):
21972197 combine = traits .Bool (argstr = '-combine' , desc = 'combine the final measurements along each axis' )
21982198 compat = traits .Bool (argstr = '-compat' , desc = 'be compatible with the older 3dFWHM' )
21992199 acf = traits .Either (
2200- traits .Bool (), File (exists = True ), traits .Tuple (File (exists = True ), traits .Float ()),
2201- argstr = '-acf' , desc = 'computes the spatial autocorrelation' )
2200+ traits .Bool (), File (), traits .Tuple (File (exists = True ), traits .Float ()),
2201+ default = False , usedefault = True , argstr = '-acf' , desc = 'computes the spatial autocorrelation' )
22022202
22032203
22042204class FWHMxOutputSpec (TraitedSpec ):
@@ -2209,9 +2209,14 @@ class FWHMxOutputSpec(TraitedSpec):
22092209 traits .Tuple (traits .Float (), traits .Float (), traits .Float ()),
22102210 traits .Tuple (traits .Float (), traits .Float (), traits .Float (), traits .Float ()),
22112211 desc = 'FWHM along each axis' )
2212+ acf_param = traits .Either (
2213+ traits .Tuple (traits .Float (), traits .Float (), traits .Float ()),
2214+ traits .Tuple (traits .Float (), traits .Float (), traits .Float (), traits .Float ()),
2215+ desc = 'fitted ACF model parameters' )
2216+ out_acf = File (exists = True , desc = 'output acf file' )
22122217
22132218
2214- class FWHMx (CommandLine ):
2219+ class FWHMx (AFNICommandBase ):
22152220 """
22162221 Unlike the older 3dFWHM, this program computes FWHMs for all sub-bricks
22172222 in the input dataset, each one separately. The output for each one is
@@ -2312,6 +2317,7 @@ class FWHMx(CommandLine):
23122317 _cmd = '3dFWHMx'
23132318 input_spec = FWHMxInputSpec
23142319 output_spec = FWHMxOutputSpec
2320+ _acf = True
23152321
23162322 def _parse_inputs (self , skip = None ):
23172323 if not self .inputs .detrend :
@@ -2331,20 +2337,18 @@ def _format_arg(self, name, trait_spec, value):
23312337 return trait_spec .argstr + ' %d' % value
23322338
23332339 if name == 'acf' :
2334- if isinstance (value , tuple ):
2340+ if isinstance (value , bool ):
2341+ if value :
2342+ return trait_spec .argstr
2343+ else :
2344+ self ._acf = False
2345+ return None
2346+ elif isinstance (value , tuple ):
23352347 return trait_spec .argstr + ' %s %f' % value
23362348 elif isinstance (value , string_types ):
23372349 return trait_spec .argstr + ' ' + value
23382350 return super (FWHMx , self )._format_arg (name , trait_spec , value )
23392351
2340- def _run_interface (self , runtime ):
2341- if platform == 'darwin' :
2342- # http://afni.nimh.nih.gov/afni/community/board/read.php?1,145346,145347#msg-145347
2343- runtime .environ ['DYLD_FALLBACK_LIBRARY_PATH' ] = '/usr/local/afni/'
2344-
2345- return super (FWHMx , self )._run_interface (runtime )
2346-
2347-
23482352 def _list_outputs (self ):
23492353 outputs = super (FWHMx , self )._list_outputs ()
23502354
@@ -2357,5 +2361,14 @@ def _list_outputs(self):
23572361 else :
23582362 outputs ['out_detrend' ] = Undefined
23592363
2360- outputs ['fwhm' ] = tuple (np .loadtxt (outputs ['out_file' ])) #pylint: disable=E1101
2364+ sout = np .loadtxt (outputs ['out_file' ]) #pylint: disable=E1101
2365+ if self ._acf :
2366+ outputs ['acf_param' ] = tuple (sout [1 ])
2367+ sout = tuple (sout [0 ])
2368+
2369+ outputs ['out_acf' ] = op .abspath ('3dFWHMx.1D' )
2370+ if isinstance (self .inputs .acf , string_types ):
2371+ outputs ['out_acf' ] = op .abspath (self .inputs .acf )
2372+
2373+ outputs ['fwhm' ] = tuple (sout )
23612374 return outputs
0 commit comments