def format( self, rec ): #{{{ stack = istack() cur = _ab.len(stack) - self.baseline if self.current is None: self.current = cur # cur_len = cur - self.current cur_len = max((cur - self.current) - 5, 0) rec.indent = self.create_indent(cur_len) out = logging.Formatter.format(self, rec) del rec.indent return out
def create_indent(self, indent_count): #{{{ lead = ' ' * 4 cur_stack = istack()[13] line_num = cur_stack[2] len = _ab.len if line_num > 9999999: line_num = '+9999999' else: line_num = '%i' %line_num cur_line = ' '.join([',', 'line', _ab.str(cur_stack[2])]) filename = cur_stack[1] if len(filename) > 10: filename = ''.join(filename[:7], '...') file = ''.join(['<', filename, cur_line, '>']) flen = len(file) if flen < 27: lead = ''.join([lead, ' ' * (27 - flen)]) cur_file = ''.join([file, lead]) spaces = (' ' * 4) * max(0, indent_count) pre = ' ' * indent_count marker = ''.join(['+ ', '-' * 2]) * indent_count post = ' ' * min(1, indent_count) return ''.join([cur_file, spaces, pre])
def readPlan(self,gulp,skipback=0,start=0,nsamps=None,verbose=True): """A generator used to perform filterbank reading. :param gulp: number of samples in each read :type gulp: int :param skipback: number of samples to skip back after each read (def=0) :type skipback: int :param start: first sample to read from filterbank (def=start of file) :type start: int :param nsamps: total number samples to read (def=end of file) :type nsamps: int :param verbose: flag for display of reading plan information (def=True) :type verbose: bool :return: An generator that can read through the file. :rtype: generator object .. note:: For each read, the generator yields a tuple ``x``, where: * ``x[0]`` is the number of samples read * ``x[1]`` is the index of the read (i.e. ``x[1]=0`` is the first read) * ``x[2]`` is a 1-D numpy array containing the data that was read The normal calling syntax for this is function is: .. code-block:: python for nsamps, ii, data in self.readPlan(*args,**kwargs): # do something where data always has contains ``nchans*nsamps`` points. """ if nsamps is None: nsamps = self.header.nsamples-start if nsamps<gulp: gulp = nsamps tstart = time.time() skipback = abs(skipback) if skipback >= gulp: raise ValueError,"readsamps must be > skipback value" self._file.seek(self.header.hdrlen+start*self.sampsize) nreads = nsamps//(gulp-skipback) lastread = nsamps-(nreads*(gulp-skipback)) if lastread<skipback: nreads -= 1 lastread = nsamps-(nreads*(gulp-skipback)) blocks = [(ii,gulp*self.header.nchans,-skipback*self.header.nchans) for ii in range(nreads)] blocks.append((nreads,lastread*self.header.nchans,0)) if verbose: print print "Filterbank reading plan:" print "------------------------" print "Called on file: ",self.filename print "Called by: ",istack()[1][3] print "Number of samps: ",nsamps print "Number of reads: ",nreads print "Nsamps per read: ",blocks[0][1]/self.header.nchans print "Nsamps of final read: ",blocks[-1][1]/self.header.nchans print "Nsamps to skip back: ",-1*blocks[0][2]/self.header.nchans print for ii,block,skip in blocks: if verbose: stdout.write("Percentage complete: %d%%\r"%(100*ii/nreads)) stdout.flush() data = self._file.cread(block) self._file.seek(skip*self.itemsize/self.bitfact,os.SEEK_CUR) yield int(block/self.header.nchans),int(ii),data if verbose: print "Execution time: %f seconds \n"%(time.time()-tstart)
def readPlan(self, gulp, skipback=0, start=0, nsamps=None, verbose=True): """A generator used to perform filterbank reading. :param gulp: number of samples in each read :type gulp: int :param skipback: number of samples to skip back after each read (def=0) :type skipback: int :param start: first sample to read from filterbank (def=start of file) :type start: int :param nsamps: total number samples to read (def=end of file) :type nsamps: int :param verbose: flag for display of reading plan information (def=True) :type verbose: bool :return: An generator that can read through the file. :rtype: generator object .. note:: For each read, the generator yields a tuple ``x``, where: * ``x[0]`` is the number of samples read * ``x[1]`` is the index of the read (i.e. ``x[1]=0`` is the first read) * ``x[2]`` is a 1-D numpy array containing the data that was read The normal calling syntax for this is function is: .. code-block:: python for nsamps, ii, data in self.readPlan(*args,**kwargs): # do something where data always has contains ``nchans*nsamps`` points. """ if nsamps is None: nsamps = self.header.nsamples - start if nsamps < gulp: gulp = nsamps tstart = time.time() skipback = abs(skipback) if skipback >= gulp: raise ValueError, "readsamps must be > skipback value" self._file.seek(self.header.hdrlen + start * self.sampsize) nreads = nsamps // (gulp - skipback) lastread = nsamps - (nreads * (gulp - skipback)) if lastread < skipback: nreads -= 1 lastread = nsamps - (nreads * (gulp - skipback)) blocks = [(ii, gulp * self.header.nchans, -skipback * self.header.nchans) for ii in range(nreads)] blocks.append((nreads, lastread * self.header.nchans, 0)) if verbose: print print "Filterbank reading plan:" print "------------------------" print "Called on file: ", self.filename print "Called by: ", istack()[1][3] print "Number of samps: ", nsamps print "Number of reads: ", nreads print "Nsamps per read: ", blocks[0][1] / self.header.nchans print "Nsamps of final read: ", blocks[-1][1] / self.header.nchans print "Nsamps to skip back: ", -1 * blocks[0][ 2] / self.header.nchans print for ii, block, skip in blocks: if verbose: stdout.write("Percentage complete: %d%%\r" % (100 * ii / nreads)) stdout.flush() data = self._file.cread(block) self._file.seek(skip * self.itemsize / self.bitfact, os.SEEK_CUR) yield int(block / self.header.nchans), int(ii), data if verbose: print "Execution time: %f seconds \n" % (time.time() - tstart)
def __init__( self, fmt=None, datefmt=None ): #{{{ logging.Formatter.__init__(self, fmt, datefmt) self.baseline = _ab.len(istack()) self.current = None