コード例 #1
0
ファイル: archivehandler.py プロジェクト: mtlam/Quicklook
    def getDeltaDM(self,nchan=None,barycenter=True): 
        """
        Calculate the DM offset 
        """
        if nchan is None:
            nchan = self.NCHAN
        data = np.mean(self.data,axis=0)
        newdata = np.zeros((nchan,self.nbins))
        window = len(data)/nchan
        for i in range(nchan):
            newdata[i,:] = np.mean(data[i*window:(i+1)*window],axis=0)
        F = u.decimate(self.F,window)



        freqs = []
        tauhats = []
        sigma_taus = []
        for i,prof in enumerate(newdata):
            spprof = SinglePulse(prof,mpw=self.spavgprof.mpw,opw=self.spavgprof.opw)                
            #plot(u.normalize(prof))
            #plot(self.sptemp.data)
            #show()
            retval = spprof.fitPulse(self.sptemp.data) #WHAT IF NO TEMPLATE?

            if retval is None:
                continue
            tauhat,sigma_tau = retval[1],retval[3]
            freqs.append(F[i])
            tauhats.append(tauhat)
            sigma_taus.append(sigma_tau)

        freqs = np.array(freqs)
        tauhats = np.array(tauhats)
        sigma_taus = np.array(sigma_taus)

        out = optimize.leastsq(errfuncDM,pinitDM,args=(freqs,tauhats,sigma_taus),full_output=1)
        residuals = tauhats-fitfuncDM(out[0],freqs)
        s_sq = np.sum(residuals**2)/(len(tauhats)-len(pinitDM))

        #print "DM",out[0][0],np.sqrt(out[1][0,0]*s_sq)
        #errorbar(freqs,tauhats,yerr=sigma_taus,fmt='k.')
        #plot(freqs,fitfuncDM(out[0],freqs))
        #show()
        #errorbar(freqs,residuals,yerr=sigma_taus,fmt='k.')
        #show()

        DM, DMerr = out[0][0],np.sqrt(out[1][0,0]*s_sq) #check the inversion of DM?

        if barycenter:
            #print "DM",DM
            return DM, DMerr
            #DM = bary.convertDMtopo(DM,self.ar.getTelescopeCoords(),self.ar.getPulsarCoords(parse=False),self.ar.getMJD(full=True))
            #print "DMnew",DM
            #err?


        return DM, DMerr
コード例 #2
0
ファイル: archivehandler.py プロジェクト: mtlam/Quicklook
    def getProfiles(self,nchan = None,difference=False, reset = False): #may run several times due to there deing difference option
        """
        Return profiles of a given frequency channelization
        """
        if nchan is None:
            nchan = self.NCHAN

        if self.profiles is None:
            reset = True
        if self.difference_profiles is None:
            reset = True
        if reset:
            if self.npz is None:
                if np.ndim(self.data) <= 2: #patch
                    data = self.data
                else:
                    data = np.mean(self.data,axis=0)
                newdata = np.zeros((nchan,self.nbins))
                window = len(data)/nchan
                for i in range(nchan):
                    newdata[i,:] = np.mean(data[i*window:(i+1)*window],axis=0)
                F = u.decimate(self.F,window)
                self.profiles = newdata
        
                if difference:
                    if self.templatefilename is None:
                        sptemp = self.spavgprof                
                    else:
                        sptemp = self.sptemp
                    for i,prof in enumerate(newdata):
                        spprof = SinglePulse(prof,mpw=sptemp.mpw,opw=sptemp.opw)
                        retval = spprof.fitPulse(sptemp.data)
                        if retval is None:
                            continue
                        tauhat,bhat = retval[1],retval[2]
        
                        newdata[i] = prof - bhat*sptemp.shiftit(tauhat)
                    self.diff_profiles = newdata 
                return newdata
            
            else:
                if difference:
                    return self.npz['differenceprofiles']
                else:
                    return self.npz['profiles']
        else:
            if difference:
                return self.difference_profiles
            else:
                return self.profiles