Esempio n. 1
0
    def dedisperse(self,dm,gulp=10000):
        """Dedisperse filterbank to timeseries.

        Args:
        dm        -- Dispersion measure to dedisperse to 
        gulp      -- size of block to read at a time, if chosen gulp
                     is less than maximum dispersion delay gulp is taken as 2 * max delay.

        Returns: TimeSeries instance
        """
        chanDelays = self.getDMdelays(dm)
        delayPointer = arrayToPointer(chanDelays)
        maxDelay = int(chanDelays.max())
        gulp = max(2*maxDelay,gulp)
        timLen = self.info["nsamples"]-maxDelay
        timBuffer = Buffer(timLen,C.c_float)
        readBuffer = Buffer(self.info["nchans"]*gulp,self.ctype)
        passPlan = ReadPlan(self,readBuffer)
        passPlan.readSkipBack(gulp,maxDelay)
        for nsamps,ii in passPlan.makePass():
            self.lib.dedisperse(readBuffer.Cbuffer,timBuffer.Cbuffer,delayPointer,
                                maxDelay, self.info["nchans"], nsamps, ii*(gulp-maxDelay))
        timInfo = self.info.copy()
        timInfo["nsamples"] = timLen
        timInfo["refdm"] = dm
        return TimeSeries(timInfo,timBuffer)
Esempio n. 2
0
    def fold(self,period,dm,nbins=50,nints=32,nbands=32,gulp=10000):
        """Fold filterbank phase bins, subintegrations and subbands. 

        Args:
        period -- period in seconds to fold with
        nbins  -- number of phase bins in output
        nints  -- number of subintegrations in output
        
        Returns: FoldedData instance
        """
        nbands = min(nbands,self.info["nchans"])
        chanDelays = self.getDMdelays(dm)
        delayPointer = arrayToPointer(chanDelays)
        maxDelay = int(chanDelays.max())
        gulp = max(2*maxDelay,gulp)
        foldBuffer  = Buffer(nbins*nints*nbands,C.c_float)
        countBuffer = Buffer(nbins*nints*nbands,C.c_int)
        readBuffer = Buffer(self.info["nchans"]*gulp,self.ctype)
        passPlan = ReadPlan(self,readBuffer)
        passPlan.readSkipBack(gulp,maxDelay)
        for nsamps,ii in passPlan.makePass():
            self.lib.foldFil(readBuffer.Cbuffer, foldBuffer.Cbuffer, countBuffer.Cbuffer,
                        delayPointer, maxDelay, C.c_double(self.info["tsamp"]),
                        C.c_double(period), gulp, self.info["nchans"], nbins,
                        nints, nbands, ii*(gulp-maxDelay))
        parentInfo = self.info.copy()
        return FoldedData(parentInfo,foldBuffer,countBuffer,
                          period,dm,nbins,nints,nbands)
Esempio n. 3
0
    def dropBits32to8(self,gulp=1024,flag=0,clip=0):
        if self.stats is None:
            raise AttributeError,"First run getStatistics()"
        
        readBuffer = Buffer(self.info["nchans"]*gulp,self.ctype)
        writeBuffer = Buffer(self.info["nchans"]*gulp,C.c_ubyte)
        
        passPlan = ReadPlan(self,readBuffer)
        passPlan.readOnce(gulp)
        
        if flag is not 0:
            flagBuffer = Buffer(self.info["nchans"]*gulp,C.c_ubyte)
            flagMax = flag*self.stats["sigma"].astype("float32")
            flagMin = -flag*self.stats["sigma"].astype("float32")
        if clip is not 0:
            chanMax = numpy.array([min(a,b) for a,b in zip(clip*self.stats["sigma"],self.stats["maxima"])])
            chanMin = numpy.array([max(a,b) for a,b in zip(-clip*self.stats["sigma"],self.stats["minima"])])
        else:
            chanMax = self.stats["maxima"]
            chanMin = self.stats["minima"]
        chanFactor = ((chanMax-chanMin)/255.)
        chanPlus = (chanMin/chanFactor)
        outFile = self.prepOutfile("%s_8bit.fil"%(self.basename),(("nbits",8)))
        
        if flag is not 0:
            changes = (("nbits",8),("source_name","%s_mask"%(self.info["source_name"].split()[0])))
            flagFile = self.prepOutfile("%s_8bit_mask.fil"%(self.basename),changes)

        for nsamps,ii in passPlan.makePass():
            self.lib.to8bit(readBuffer.Cbuffer,writeBuffer.Cbuffer,
                            arrayToPointer(chanFactor),arrayToPointer(chanPlus),
                            nsamps,self.info["nchans"])
            outFile.cwrite(writeBuffer)
            if flag is not 0:
                lib.flagBlock(readBuffer.Cbuffer,flagBuffer.Cbuffer,
                              arrayToPointer(flagMax),arrayToPointer(flagMin),
                              nsamps,self.info["nchans"])
                flagFile.cwrite(flagBuffer)
        if flag is not 0:
            return(Filterbank(outFile.name),Filterbank(flagFile.name))
        else:
            return Filterbank(outFile.name)