#NEWLINE# def iterate( self ) : #NEWLINE# #INDENT# xfmsToAvg = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# lsq12ResampledFiles = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for inputFH in self . inputs : #NEWLINE# #INDENT# 'Create an array of xfms, to compute an average lsq12 xfm for each input' #NEWLINE# xfmsToAvg [ inputFH ] = [ ] #NEWLINE# if ( self . maxPairs is not None ) : #NEWLINE# #INDENT# if ( self . maxPairs >= ( len ( self . inputs ) - 1 ) ) : #NEWLINE# #INDENT# inputs = self . inputs #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# random . seed ( tuple ( map ( ( lambda fh : fh . inputFileName ) , self . inputs ) ) ) #NEWLINE# inputs = random . sample ( filter ( ( lambda fh : ( fh != inputFH ) ) , self . inputs ) , self . maxPairs ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# inputs = self . inputs #NEWLINE# #UNINDENT# for targetFH in inputs : #NEWLINE# #INDENT# if ( inputFH != targetFH ) : #NEWLINE# #INDENT# lsq12 = LSQ12 ( inputFH , targetFH , blurs = lsq12ResampledFiles . blurs , step = self . stepSize , gradient = self . useGradient , simplex = self . simplex , w_translations = self . w_translations ) #NEWLINE# self . p . addPipeline ( lsq12 . p ) #NEWLINE# xfmsToAvg [ inputFH ] . append ( inputFH . getLastXfm ( targetFH ) ) #NEWLINE# #UNINDENT# #UNINDENT# 'Create average xfm for inputFH using xfmsToAvg array' #NEWLINE# avgXfmOutput = createBaseName ( inputFH . transformsDir , ( inputFH . basename + '-avg-lsq12.xfm' ) ) #NEWLINE# cmd = ( ( [ 'xfmavg' , '-verbose' , '-clobber' ] + map ( InputFile , xfmsToAvg [ inputFH ] ) ) + [ OutputFile ( avgXfmOutput ) ] ) #NEWLINE# xfmavg = CmdStage ( cmd ) #NEWLINE# xfmavg . setLogFile ( LogFile ( logFromFile ( inputFH . logDir , avgXfmOutput ) ) ) #NEWLINE# self . p . addStage ( xfmavg ) #NEWLINE# self . lsq12AvgXfms [ inputFH ] = avgXfmOutput #NEWLINE# ' resample brain and add to array for mincAveraging' #NEWLINE# if ( not self . likeFile ) : #NEWLINE# #INDENT# likeFile = inputFH #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# likeFile = self . likeFile #NEWLINE# #UNINDENT# rslOutput = createBaseName ( inputFH . resampledDir , ( inputFH . basename + '-resampled-lsq12.mnc' ) ) #NEWLINE# res = ma . mincresample ( inputFH , inputFH , transform = avgXfmOutput , likeFile = likeFile , output = rslOutput , argArray = [ '-sinc' ] ) #NEWLINE# self . p . addStage ( res ) #NEWLINE# lsq12ResampledFiles [ inputFH ] = rslOutput #NEWLINE# #UNINDENT# ' After all registrations complete, setLastBasevol for each subject to be\n            resampled file in lsq12 space. We can then call mincAverage on fileHandlers,\n            as it will use the lastBasevol for each by default.' #NEWLINE# for inputFH in self . inputs : #NEWLINE# #INDENT# inputFH . setLastBasevol ( lsq12ResampledFiles [ inputFH ] ) #NEWLINE# #UNINDENT# ' mincAverage all resampled brains and put in lsq12Directory' #NEWLINE# self . lsq12Avg = ( ( ( abspath ( self . lsq12Dir ) + '/' ) + basename ( self . lsq12Dir ) ) + '-pairs.mnc' ) #NEWLINE# self . lsq12AvgFH = RegistrationPipeFH ( self . lsq12Avg , basedir = self . lsq12Dir ) #NEWLINE# avg = ma . average ( inputs , queue_type = self . queue_type , outputAvg = self . lsq12AvgFH , output = self . lsq12Avg , defaultDir = self . lsq12Dir ) #NEWLINE# self . p . addStage ( avg )