示例#1
0
    def doplot(self, fitres, h, minmag, maxmag):
        tab=biggles.Table(2,1)

        plt=FramedPlot()
        plt.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag)
        plt.xlabel=r'$\sigma$'

        sprior=fitres.get_model()

        nrand=100000
        binsize=self.binsize

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='data'

        srand=sprior.sample(nrand)
        hrand=histogram(srand, binsize=binsize, min=h['low'][0], max=h['high'][-1], more=True)
        hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand

        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize,
                           color='blue')
        hpltrand.label='rand'


        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')

        plt.add(hplt, hpltrand, key)

        
        tplt=fitres.plot_trials(show=False,fontsize_min=0.88888888)
        
        tab[0,0] = plt
        tab[1,0] = tplt

        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofs-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.objtype)
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)

        return tab
示例#2
0
    def plot_fits(self, st):
        import biggles

        biggles.configure("default", "fontsize_min", 2)
        parnames = ["A", "a", "g0", "gmax"]

        npars = len(parnames)
        tab = Table(npars, 1)

        magmiddle = (st["minmag"] + st["maxmag"]) / 2
        for i in xrange(npars):

            yval = st["pars"][:, i]
            yerr = st["perr"][:, i]

            ymean = yval.mean()
            ystd = yval.std()
            yrange = [ymean - 3.5 * ystd, ymean + 3.5 * ystd]

            pts = Points(magmiddle, yval, type="filled circle")
            yerrpts = SymmetricErrorBarsY(magmiddle, yval, yerr)
            xerrpts = ErrorBarsX(yval, st["minmag"], st["maxmag"])

            plt = FramedPlot()
            plt.yrange = yrange
            plt.add(pts, xerrpts, yerrpts)
            plt.xlabel = "mag"
            plt.ylabel = parnames[i]

            tab[i, 0] = plt

        if self.show:
            tab.show()

        d = files.get_prior_dir()
        d = os.path.join(d, "plots")
        epsfile = "pofe-pars-%s.eps" % self.otype
        epsfile = os.path.join(d, epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system("converter -d 100 %s" % epsfile)
示例#3
0
    def plot_fits(self,st):
        import biggles
        biggles.configure( 'default', 'fontsize_min', 2)
        parnames=['A','a','g0','gmax']

        npars=len(parnames)
        tab=Table(npars,1)

        magmiddle=(st['minmag'] + st['maxmag'])/2
        for i in xrange(npars):

            yval=st['pars'][:,i]
            yerr=st['perr'][:,i]

            ymean=yval.mean()
            ystd=yval.std()
            yrange=[ymean-3.5*ystd, ymean+3.5*ystd]
            
            pts=Points(magmiddle, yval, type='filled circle')
            yerrpts=SymmetricErrorBarsY(magmiddle,yval,yerr)
            xerrpts=ErrorBarsX(yval, st['minmag'], st['maxmag'])

            
            plt=FramedPlot()
            plt.yrange=yrange
            plt.add(pts,xerrpts, yerrpts)
            plt.xlabel='mag'
            plt.ylabel=parnames[i]

            tab[i,0] = plt

        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofe-pars-%s.eps' % self.otype
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)
示例#4
0
    def doplot(self, gprior, minmag, maxmag):
        from lensing.util import eta1eta2_to_g1g2

        tab = Table(2, 2)
        tab.title = "%s %.2f %.2f " % (self.otype, minmag, maxmag)

        h1_g, h2_g, h_g = self.do_histograms(minmag, maxmag, "g")
        h1_eta, h2_eta, h_eta = self.do_histograms(minmag, maxmag, "eta")

        nrand = 1000000
        binsize_eta = self.binsize_eta
        binsize_g = self.binsize_g

        rbinsize_eta = binsize_eta * 0.2
        rbinsize_g = binsize_g * 0.2

        gr = gprior.sample(nrand)
        eta1_rand = gr[:, 0]
        eta2_rand = gr[:, 1]
        eta_rand = numpy.sqrt(eta1_rand ** 2 + eta2_rand ** 2)

        g1_rand, g2_rand = eta1eta2_to_g1g2(eta1_rand, eta2_rand)
        g_rand = numpy.sqrt(g1_rand ** 2 + g2_rand ** 2)

        hrand_eta = histogram(eta_rand, binsize=rbinsize_eta, min=0, max=self.max_eta, more=True)
        h1rand_eta = histogram(eta1_rand, binsize=rbinsize_eta, min=self.min_eta_2d, max=self.max_eta_2d, more=True)

        hrand_g = histogram(g_rand, binsize=rbinsize_g, min=0, max=self.max_g, more=True)
        h1rand_g = histogram(g1_rand, binsize=rbinsize_g, min=self.min_g_2d, max=self.max_g_2d, more=True)

        # eta 2d plots
        bratio_eta = self.binsize_eta / rbinsize_eta
        hrand_eta["hist"] = hrand_eta["hist"] * bratio_eta * float(h_eta["hist"].sum()) / nrand
        h1rand_eta["hist"] = h1rand_eta["hist"] * bratio_eta * float(h1_eta["hist"].sum()) / h1rand_eta["hist"].sum()

        pltboth_eta = FramedPlot()
        pltboth_eta.xlabel = r"$\eta$"

        hplt1_eta = Histogram(h1_eta["hist"], x0=h1_eta["low"][0], binsize=binsize_eta, color="darkgreen")
        hplt2_eta = Histogram(h2_eta["hist"], x0=h2_eta["low"][0], binsize=binsize_eta, color="blue")
        hpltrand_eta = Histogram(hrand_eta["hist"], x0=hrand_eta["low"][0], binsize=rbinsize_eta, color="red")
        hplt1rand_eta = Histogram(h1rand_eta["hist"], x0=h1rand_eta["low"][0], binsize=rbinsize_eta, color="red")

        hplt1_eta.label = r"$\eta_1$"
        hplt2_eta.label = r"$\eta_2$"
        hplt1rand_eta.label = "rand"
        hpltrand_eta.label = "rand"
        keyboth_eta = PlotKey(0.9, 0.9, [hplt1_eta, hplt2_eta, hplt1rand_eta], halign="right")

        pltboth_eta.add(hplt1_eta, hplt2_eta, hplt1rand_eta, keyboth_eta)

        tab[0, 0] = pltboth_eta

        plt1d_eta = FramedPlot()
        plt1d_eta.xlabel = r"$|\eta|$"

        hplt_eta = Histogram(h_eta["hist"], x0=h_eta["low"][0], binsize=binsize_eta)
        hplt_eta.label = r"$|\eta|$"

        key_eta = PlotKey(0.9, 0.9, [hplt_eta, hpltrand_eta], halign="right")
        plt1d_eta.add(hplt_eta, hpltrand_eta, key_eta)

        tab[1, 0] = plt1d_eta

        # g plots

        bratio_g = self.binsize_g / rbinsize_g
        hrand_g["hist"] = hrand_g["hist"] * bratio_g * float(h_g["hist"].sum()) / nrand
        h1rand_g["hist"] = h1rand_g["hist"] * bratio_g * float(h1_g["hist"].sum()) / h1rand_g["hist"].sum()

        pltboth_g = FramedPlot()
        pltboth_g.xlabel = r"$g$"

        hplt1_g = Histogram(h1_g["hist"], x0=h1_g["low"][0], binsize=binsize_g, color="darkgreen")
        hplt2_g = Histogram(h2_g["hist"], x0=h2_g["low"][0], binsize=binsize_g, color="blue")
        hpltrand_g = Histogram(hrand_g["hist"], x0=hrand_g["low"][0], binsize=rbinsize_g, color="red")
        hplt1rand_g = Histogram(h1rand_g["hist"], x0=h1rand_g["low"][0], binsize=rbinsize_g, color="red")

        hplt1_g.label = r"$g_1$"
        hplt2_g.label = r"$g_2$"
        hplt1rand_g.label = "rand"
        hpltrand_g.label = "rand"
        keyboth_g = PlotKey(0.9, 0.9, [hplt1_g, hplt2_g, hplt1rand_g], halign="right")

        pltboth_g.add(hplt1_g, hplt2_g, hplt1rand_g, keyboth_g)

        tab[0, 1] = pltboth_g

        plt1d_g = FramedPlot()
        plt1d_g.xlabel = r"$|g|$"

        hplt_g = Histogram(h_g["hist"], x0=h_g["low"][0], binsize=binsize_g)
        hplt_g.label = "|g|"

        key_g = PlotKey(0.9, 0.9, [hplt_g, hpltrand_g], halign="right")
        plt1d_g.add(hplt_g, hpltrand_g, key_g)

        tab[1, 1] = plt1d_g

        if self.show:
            tab.show()

        d = files.get_prior_dir()
        d = os.path.join(d, "plots")
        epsfile = "pofe-pofeta-%.2f-%.2f-%s.eps" % (minmag, maxmag, self.otype)
        epsfile = os.path.join(d, epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system("converter -d 100 %s" % epsfile)

        return tab
示例#5
0
    def doplot(self, gprior, h1, h2, h, minmag, maxmag):
        tab=Table(2,1)
        tab.title='%s %.2f %.2f ' % (self.otype, minmag, maxmag)


        nrand=1000000
        binsize=self.binsize
        rbinsize=binsize*0.2


        gr = gprior.sample(nrand)
        g1rand=gr[:,0]
        g2rand=gr[:,1]

        grand = numpy.sqrt( g1rand**2 + g2rand**2 )

        #hrand=histogram(grand, binsize=rbinsize, min=h['low'][0], max=h['high'][-1], more=True)
        hrand=histogram(grand, binsize=rbinsize, min=0,max=self.maxe, more=True)
        h1rand=histogram(g1rand, binsize=rbinsize, min=self.mine_2d, max=self.maxe_2d, more=True)

        bratio = self.binsize/rbinsize
        hrand['hist'] = hrand['hist']*bratio*float(h['hist'].sum())/nrand
        h1rand['hist'] = h1rand['hist']*bratio*float(h1['hist'].sum())/h1rand['hist'].sum()


        pltboth=FramedPlot()
        pltboth.xlabel=r'$%s$' % self.ellip_name

        hplt1=Histogram(h1['hist'], x0=h1['low'][0], binsize=binsize,color='darkgreen')
        hplt2=Histogram(h2['hist'], x0=h2['low'][0], binsize=binsize,color='blue')
        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=rbinsize,
                           color='red')
        hplt1rand=Histogram(h1rand['hist'], x0=h1rand['low'][0], binsize=rbinsize,
                           color='red')

        hplt1.label=r'$g_1$'
        hplt2.label=r'$g_2$'
        hplt1rand.label='rand'
        hpltrand.label='rand'
        keyboth=PlotKey(0.9,0.9,[hplt1,hplt2,hplt1rand],halign='right')

        pltboth.add(hplt1, hplt2, hplt1rand, keyboth)


        tab[0,0]=pltboth
        

        plt=FramedPlot()
        plt.xlabel=r'$|%s|$' % self.ellip_name

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='|%s|' % self.ellip_name

        
        #line=Curve(xfit, yfit, color='blue')
        #line.label='model'

        #key=PlotKey(0.9,0.9,[hplt,line,hpltrand],halign='right')
        #plt.add(line, hplt, hpltrand, key)
        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')
        plt.add(hplt, hpltrand, key)


        tab[1,0]=plt
        
        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofe-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.otype)
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)

        return tab
示例#6
0
    def doplot(self, fitres, h1, h2, h, minmag, maxmag):
        tab=Table(2,1)
        tab.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag)

        #xfit,yfit,gprior = self.get_prior_vals(fitres, h)
        gprior=self.get_prior(fitres)

        nrand=100000
        binsize=self.binsize


        g1rand,g2rand=gprior.sample2d(nrand)
        grand=gprior.sample1d(nrand)

        #hrand=histogram(grand, binsize=binsize, min=0., max=1., more=True)
        hrand=histogram(grand, binsize=binsize, min=h['low'][0], max=h['high'][-1], more=True)
        h1rand=histogram(g1rand, binsize=binsize, min=-1., max=1., more=True)

        #fbinsize=xfit[1]-xfit[0]
        #hrand['hist'] = hrand['hist']*float(yfit.sum())/hrand['hist'].sum()*fbinsize/binsize
        hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand
        h1rand['hist'] = h1rand['hist']*float(h1['hist'].sum())/h1rand['hist'].sum()


        pltboth=FramedPlot()
        pltboth.xlabel=r'$g$'

        hplt1=Histogram(h1['hist'], x0=h1['low'][0], binsize=binsize,color='red')
        hplt2=Histogram(h2['hist'], x0=h2['low'][0], binsize=binsize,color='blue')
        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize,
                           color='magenta')
        hplt1rand=Histogram(h1rand['hist'], x0=h1rand['low'][0], binsize=binsize,
                           color='magenta')

        hplt1.label=r'$g_1$'
        hplt2.label=r'$g_2$'
        hplt1rand.label='rand'
        hpltrand.label='rand'
        keyboth=PlotKey(0.9,0.9,[hplt1,hplt2,hplt1rand],halign='right')

        pltboth.add(hplt1, hplt2, hplt1rand, keyboth)
        tab[0,0]=pltboth
        

        plt=FramedPlot()
        plt.xlabel=r'$|g|$'

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='|g|'

        
        #line=Curve(xfit, yfit, color='blue')
        #line.label='model'

        #key=PlotKey(0.9,0.9,[hplt,line,hpltrand],halign='right')
        #plt.add(line, hplt, hpltrand, key)
        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')
        plt.add(hplt, hpltrand, key)


        tab[1,0]=plt
        
        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofe-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.objtype)
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)

        return tab