Exemplo n.º 1
0
    def estimateScatteringTimescale(self,
                                    searchtauds=None,
                                    ntauds=25,
                                    name=None,
                                    fourier=False,
                                    **kwargs):
        if searchtauds is None:
            fwhm = self.getFWHM(timeunits=False)  #in bin units
            tauds = np.linspace(fwhm / 4, fwhm, ntauds)

            tauds = np.linspace(2, self.nbins / 4, ntauds)
            tauds = np.linspace(2, fwhm, ntauds)
        else:
            tauds = np.copy(searchtauds)

        bins = np.array(self.bins, dtype=np.float)

        N_fs = np.zeros_like(tauds)
        sigma_offcs = np.zeros_like(tauds)
        Gammas = np.zeros_like(tauds)
        f_rs = np.zeros_like(tauds)
        for i, taud in enumerate(tauds):
            #print i,taud
            if fourier:
                Dy, C, N_f, sigma_offc, Gamma, f_r = u.pbf_fourier(
                    bins, self.data, taud=taud, opw=self.opw, **kwargs)
            else:
                Dy, C, N_f, sigma_offc, Gamma, f_r = u.pbf_clean(bins,
                                                                 self.data,
                                                                 taud=taud,
                                                                 opw=self.opw,
                                                                 **kwargs)
            N_fs[i] = N_f
            sigma_offcs[i] = sigma_offc
            Gammas[i] = Gamma
            f_rs[i] = f_r

        f_cs = (Gammas + f_rs) / 2.0

        fig = plt.figure(figsize=(8, 12))
        ax = fig.add_subplot(511)
        ax.plot(tauds, N_fs)
        ax.set_ylabel(r'$N_f/N_{\rm tot}$')
        ax = fig.add_subplot(512)
        ax.plot(tauds, sigma_offcs)
        ax.set_ylabel(r'$\sigma_{\rm offc}/\sigma_{\rm off}$')
        ax = fig.add_subplot(513)
        ax.plot(tauds, Gammas)
        ax.set_ylabel(r'$\Gamma$')
        ax = fig.add_subplot(514)
        ax.plot(tauds, f_rs)
        ax.set_ylabel(r'$f_r$')
        ax = fig.add_subplot(515)
        ax.plot(tauds, f_cs)
        ax.set_xlabel(r'$\tau_{\rm d}$')
        ax.set_ylabel(r'$f_c$')
        if name is None:
            plt.show()
        else:
            np.savez("cleandata/%s_clean_data.npz" % name,
                     tauds=(tauds * self.getTbin() * 1000),
                     N_fs=N_fs,
                     sigma_offcs=sigma_offcs,
                     Gammas=Gammas,
                     f_rs=f_rs,
                     f_cs=f_cs)
            plt.savefig("cleanimages/%s_clean_stats.png" % name)
            plt.close()

        ind = np.argmin(f_cs)
        #ind = np.argmin(Gammas)
        #print tauds[ind],tauds[ind]*self.getTbin()
        if fourier:
            Dy, C, N_f, sigma_offc, Gamma, f_r = u.pbf_fourier(bins,
                                                               self.data,
                                                               taud=tauds[ind],
                                                               opw=self.opw,
                                                               **kwargs)
        else:
            Dy, C, N_f, sigma_offc, Gamma, f_r = u.pbf_clean(bins,
                                                             self.data,
                                                             taud=tauds[ind],
                                                             opw=self.opw,
                                                             **kwargs)
        #Dy,C,N_f,sigma_offc,Gamma,f_r=clean(t,y,taud=10)
        #print "gamma",Gamma

        fig = plt.figure()
        ax = fig.add_subplot(111)
        #ax.plot(self.bins,self.data/np.max(self.data),'b')
        ax.plot(bins, Dy / np.max(self.data), '0.50')
        if fourier:
            ax.plot(bins, C / np.max(self.data), 'r')
        else:
            ax.plot(bins, C, 'r')
        ax.plot(bins, self.data / np.max(self.data), 'k')
        ax.set_xlim(0, bins[-1])
        ax.text(0.7,
                0.8,
                r'$\tau_d$ = %0.2f ms' % (tauds[ind] * self.getTbin() * 1000),
                transform=ax.transAxes,
                fontsize=14)
        if name is None:
            plt.show()
        else:
            plt.savefig("cleanimages/%s_clean.png" % name)
            plt.close()
Exemplo n.º 2
0
    def estimateScatteringTimescale(self,searchtauds=None,ntauds=25,name=None,fourier=False,**kwargs):
        if searchtauds is None:
            fwhm = self.getFWHM(timeunits=False) #in bin units
            tauds = np.linspace(fwhm/4,fwhm,ntauds)

            tauds = np.linspace(2,self.getNbins()/4,ntauds)
            tauds = np.linspace(2,fwhm,ntauds)
        else:
            tauds = np.copy(searchtauds)

        bins = np.array(self.bins,dtype=np.float)

        N_fs = np.zeros_like(tauds)
        sigma_offcs = np.zeros_like(tauds)
        Gammas = np.zeros_like(tauds)
        f_rs = np.zeros_like(tauds)
        for i,taud in enumerate(tauds):
            #print i,taud
            if fourier:
                Dy,C,N_f,sigma_offc,Gamma,f_r = u.pbf_fourier(bins,self.data,taud=taud,opw=self.opw,**kwargs)
            else:
                Dy,C,N_f,sigma_offc,Gamma,f_r = u.pbf_clean(bins,self.data,taud=taud,opw=self.opw,**kwargs)
            N_fs[i] = N_f
            sigma_offcs[i] = sigma_offc
            Gammas[i] = Gamma
            f_rs[i] = f_r


            
        f_cs = (Gammas+f_rs)/2.0

        fig = plt.figure(figsize=(8,12))
        ax=fig.add_subplot(511)
        ax.plot(tauds,N_fs)
        ax.set_ylabel(r'$N_f/N_{\rm tot}$')
        ax=fig.add_subplot(512)
        ax.plot(tauds,sigma_offcs)
        ax.set_ylabel(r'$\sigma_{\rm offc}/\sigma_{\rm off}$')
        ax=fig.add_subplot(513)
        ax.plot(tauds,Gammas)
        ax.set_ylabel(r'$\Gamma$')
        ax=fig.add_subplot(514)
        ax.plot(tauds,f_rs)
        ax.set_ylabel(r'$f_r$')
        ax=fig.add_subplot(515)
        ax.plot(tauds,f_cs)
        ax.set_xlabel(r'$\tau_{\rm d}$')
        ax.set_ylabel(r'$f_c$')
        if name is None:
            plt.show()
        else:
            np.savez("cleandata/%s_clean_data.npz"%name,tauds=(tauds*self.getTbin()*1000),N_fs=N_fs,sigma_offcs=sigma_offcs,Gammas=Gammas,f_rs=f_rs,f_cs=f_cs)
            plt.savefig("cleanimages/%s_clean_stats.png"%name)
            plt.close()
            



        ind = np.argmin(f_cs)
        #ind = np.argmin(Gammas)
        #print tauds[ind],tauds[ind]*self.getTbin()
        if fourier:
            Dy,C,N_f,sigma_offc,Gamma,f_r=u.pbf_fourier(bins,self.data,taud=tauds[ind],opw=self.opw,**kwargs)
        else:
            Dy,C,N_f,sigma_offc,Gamma,f_r=u.pbf_clean(bins,self.data,taud=tauds[ind],opw=self.opw,**kwargs)
        #Dy,C,N_f,sigma_offc,Gamma,f_r=clean(t,y,taud=10)
        #print "gamma",Gamma

        fig = plt.figure()
        ax = fig.add_subplot(111)
        #ax.plot(self.bins,self.data/np.max(self.data),'b')
        ax.plot(bins,Dy/np.max(self.data),'0.50')
        if fourier:
            ax.plot(bins,C/np.max(self.data),'r')
        else:
            ax.plot(bins,C,'r')
        ax.plot(bins,self.data/np.max(self.data),'k')
        ax.set_xlim(0,bins[-1])
        ax.text(0.7,0.8,r'$\tau_d$ = %0.2f ms'%(tauds[ind]*self.getTbin()*1000),transform=ax.transAxes,fontsize=14)
        if name is None:
            plt.show()
        else:
            plt.savefig("cleanimages/%s_clean.png"%name)
            plt.close()