def __call__(self, **kwargs): ''' The base class __call__ functor "runs" the stage. Each stage consists of three components: o preconditions o stage o postconditions By default, all three componets are executed in order pre- and/or post-conditions checking. If called with (stage=True) will execute the externally defined stage callback. ''' if self._b_canRun: b_preconditionsRun = True b_stageRun = True b_postconditionsRun = True b_preamble = True b_postamble = True for key, value in kwargs.iteritems(): if key == 'checkpreconditions': b_preconditionsRun = value if key == 'runstage': b_stageRun = value if key == 'checkpostconditions': b_postconditionsRun = value if key == 'preamble': b_preamble = value if key == 'postamble': b_postamble = value if b_preamble: misc.tic() self._log(Colors.GREEN + \ '<%s> START' % self.name() + \ Colors.NO_COLOUR +'...\n' ) if b_preconditionsRun: if not self.preconditions(): error.report(self, 'preconditions', self._b_fatalConditions) if b_stageRun: self._callCount += 1 if not self.stage(): error.report(self, 'stage', self._b_fatalConditions) if b_postconditionsRun: if not self.postconditions(): error.report(self, 'postconditions', self._b_fatalConditions) if b_postamble: self._log(Colors.GREEN + '<%s> END' % self.name() + \ Colors.NO_COLOUR + '. Elapsed time = ' + \ Colors.CYAN + '%f' % misc.toc() + \ Colors.NO_COLOUR + ' seconds.\n')
def __call__(self, **kwargs): ''' The base class __call__ functor "runs" the stage. Each stage consists of three components: o preconditions o stage o postconditions By default, all three componets are executed in order pre- and/or post-conditions checking. If called with (stage=True) will execute the externally defined stage callback. ''' if self._b_canRun: b_preconditionsRun = True b_stageRun = True b_postconditionsRun = True b_preamble = True b_postamble = True for key, value in kwargs.iteritems(): if key == 'checkpreconditions': b_preconditionsRun = value if key == 'runstage': b_stageRun = value if key == 'checkpostconditions': b_postconditionsRun = value if key == 'preamble': b_preamble = value if key == 'postamble': b_postamble = value if b_preamble: misc.tic() ; self._log(Colors.GREEN + \ '<%s> START' % self.name() + \ Colors.NO_COLOUR +'...\n' ) if b_preconditionsRun: if not self.preconditions(): error.report(self, 'preconditions', self._b_fatalConditions) if b_stageRun: self._callCount += 1 if not self.stage(): error.report(self, 'stage', self._b_fatalConditions) if b_postconditionsRun: if not self.postconditions(): error.report(self, 'postconditions', self._b_fatalConditions) if b_postamble: self._log(Colors.GREEN + '<%s> END' % self.name() + \ Colors.NO_COLOUR + '. Elapsed time = ' + \ Colors.CYAN + '%f' % misc.toc() + \ Colors.NO_COLOUR + ' seconds.\n')
def __init__( self, *args ): self.__name__ = 'C_CAE' self.mstr_obj = 'C_CAE'; # name of object class self.mstr_name = 'unnamed'; # name of object variable self.mstr_def = 'void'; # name of function being processed self.m_id = -1; # int id self.m_iter = 0; # current iteration in an #+ arbitrary processing #+ scheme self.m_verbosity = 0; # debug related value for #+ object self.m_warnings = 0; # show warnings #+ (and warnings level) # The core data containers are grids of cellular automata # machines self.mgg_current = None # Current grid self.mgg_next = None # Next iteration grid self.mb_syncGridSpectralArray = False # Controls whether or not # to synchronize grid spectra # and grid helper array # For the most part, the CAE accepts the same constructor # pattern as the C_ggrid: if len( args ) == 2: # Grid spectral elements are of type C_spectrum_CAM print "Creating current state grid...", ; misc.tic() self.mgg_current = C_ggrid( *args, name='currentState' ) print "done. %s" % misc.toc() print "Creating next state grid...", ; misc.tic() self.mgg_next = C_ggrid( *args, name='nextState' ) print "done. %s" % misc.toc() self.m_rows = self.mgg_current.rows_get() self.m_cols = self.mgg_current.cols_get() self.__neighbors = {}
if not b_htmlExt: C_dicomTag = dicomTag( inputFile = args.inputFile, outputDir = args.outputDir, outputFileStem = args.outputFileStem, outputFileType = args.outputFileType, tagFile = args.tagFile, tagList = args.tagList, rawType = args.rawType, imageFile = args.imageFile ) if b_htmlExt: C_dicomTag = dicomTag_html( inputFile = args.inputFile, outputDir = args.outputDir, outputFileStem = args.outputFileStem, outputFileType = args.outputFileType, tagFile = args.tagFile, tagList = args.tagList, imageFile = args.imageFile ) # And now run it! misc.tic() C_dicomTag.run() if args.printElapsedTime: print("Elapsed time = %f seconds" % misc.toc()) sys.exit(0)
if len(str_outputFileExtension): args.outputFileStem = str_outputFileStem b_niftiExt = (str_inputFileExtension == '.nii' or \ str_inputFileExtension == '.gz') b_dicomExt = str_inputFileExtension == '.dcm' if b_niftiExt: C_convert = med2image_nii(inputFile=args.inputFile, outputDir=args.outputDir, outputFileStem=args.outputFileStem, outputFileType=args.outputFileType, sliceToConvert=args.sliceToConvert, frameToConvert=args.frameToConvert, showSlices=args.showSlices, reslice=args.reslice) if b_dicomExt: C_convert = med2image_dcm(inputFile=args.inputFile, outputDir=args.outputDir, outputFileStem=args.outputFileStem, outputFileType=args.outputFileType, sliceToConvert=args.sliceToConvert, reslice=args.reslice) # And now run it! misc.tic() C_convert.run() if args.printElapsedTime: print("Elapsed time = %f seconds" % misc.toc()) sys.exit(0)
#!/usr/bin/env python from _common import systemMisc as misc import numpy as np col2sort = lambda A: np.sort(A.view('i8,i8'), order=['f0','f1'], axis=0).view(np.int) misc.tic() A1 = misc.neighbours_find(2,2, np.array((4,4)), gridSize = np.array((5,5)), wrapGridEdges = True, returnUnion = True) misc.toc() print col2sort(A1.astype(int)) misc.tic() A2 = misc.neighbours_findFast(2,2, np.array((4,4)), gridSize = np.array((5,5)), wrapGridEdges = True, returnUnion = True, includeOrigin = True) misc.toc() print col2sort(A2)
def state_transition( self ): """ The state transition machine for the CAE; determines the "next" state from the "current". PRECONDITIONS: o The "current" == "next" state TRANSITION: o The "next" state is changed according to "current" state in a decoupled element-by-element fashion. POSTCONDITIONS: o Once each element in the "current" state has been processed, the "next" state is copied into the "current" state. o A state transition is now complete. o Returns the number of elements processed. Primitive support for multithreaded/parallelization is planned... """ # Process the current grid, and determine all the changes required to # transition to the next state. elementProcessedCount = 0 misc.tic() for row in np.arange( 0, self.m_rows ): for col in np.arange( 0, self.m_cols ): dict_nextStateNeighbourSpectra = {} A_neighbours = None key = str( row ) + ':' + str( col ) if self.__neighbors.has_key( key ): # we already have the neighbors A_neighbours = self.__neighbors[key] else: # we don't have the neighbors, so let's calculate them A_neighbours = \ misc.neighbours_findFast( 2, 1, np.array( ( row, col ) ), gridSize=np.array( ( self.m_rows, self.m_cols ) ), wrapGridEdges=False, returnUnion=True, includeOrigin=False ) self.__neighbors[key] = A_neighbours dict_nextStateNeighbourSpectra = \ self.dict_createFromGridLocations( A_neighbours ) deltaSelf, deltaNeighbour = \ self.mgg_current.spectrum_get( row, col ).nextStateDelta_determine( dict_nextStateNeighbourSpectra ) if deltaNeighbour: for update in deltaNeighbour.keys(): elementProcessedCount += 1 updateRule = deltaNeighbour[update] dict_nextStateNeighbourSpectra[update].nextState_process( updateRule ) print "Update loop time: %f seconds (%d elements processed)." % \ ( misc.toc(), elementProcessedCount ) # Now update the current state with the next state misc.tic() b_setFromArray = False if self.mb_syncGridSpectralArray: self.mgg_next.internals_sync( b_setFromArray ) print misc.toc( sysprint="Synchronization: %f seconds." ) misc.tic() # self.mgg_current = copy.deepcopy(self.mgg_next) # use cPickle instead of deepcopy self.mgg_current = cPickle.loads( cPickle.dumps( self.mgg_next, -1 ) ) print misc.toc( sysprint="next->current deepcopy: %f seconds.\n" ) return elementProcessedCount
#!/usr/bin/env python from _common import systemMisc as misc import numpy as np col2sort = lambda A: np.sort(A.view('i8,i8'), order=['f0', 'f1'], axis=0).view( np.int) misc.tic() A1 = misc.neighbours_find(2, 2, np.array((4, 4)), gridSize=np.array((5, 5)), wrapGridEdges=True, returnUnion=True) misc.toc() print col2sort(A1.astype(int)) misc.tic() A2 = misc.neighbours_findFast(2, 2, np.array((4, 4)), gridSize=np.array((5, 5)), wrapGridEdges=True, returnUnion=True, includeOrigin=True) misc.toc() print col2sort(A2)