Beispiel #1
0
    def plot_detrend(self, data, e1dt, e2dt, w, camcol, rmag_min, rmag_max, 
                     coeffs, show=False):
        """
        Make a table of plots.  
        """
        band=self.band
        d=self.plotdir()
        f = 'rg-%(run)s%(band)s-meane-vs-R-%(rmag_max)0.2f-%(camcol)s-detrend.eps'
        f = f % {'run':self.procrun,'band':self.band,
                 'rmag_max':rmag_max,'camcol':camcol}
        epsfile=path_join(d,'bycamcol',f)

        # one column for each type (R,e1psf,e2psf)
        tab=Table(1,3)
        gratio=1.61803399
        #tab.aspect_ratio = 1/gratio
        tab.aspect_ratio = 1./2.

        weights = 1.0/(0.32**2 + data['uncer_rg_'+band][w]**2)
        nperbin = 200000

        # trends vs R
        print("\n* R")
        xmin=0.29
        xmax=1.01
        if band=='r':
            ymin = -0.03
            ymax =  0.03
        else:
            ymin = -0.03
            ymax =  0.06
        pe1,pe1err,pe2,pe2err,ph,t1,t2 = \
            self.make_plot_components(data['R_rg_'+band][w],
                                      data['e1_rg_'+band][w], 
                                      data['e2_rg_'+band][w], 
                                      weights, nperbin, ymin, ymax,
                                      fmin=xmin,fmax=xmax,
                                      coeffs=coeffs)

        pe1dt,pe1dterr,pe2dt,pe2dterr,phdt = \
            self.make_plot_components(data['R_rg_'+band][w],
                                      e1dt[w], 
                                      e2dt[w], 
                                      weights, nperbin, ymin, ymax,
                                      fmin=xmin,fmax=xmax)



        # one row for before and after detrend
        Ra=FramedArray(2,1)
        Ra.xrange = [xmin,xmax]
        Ra.yrange = [ymin,ymax]
        Ra.xlabel = 'R'
        Ra.ylabel = '<e>'

        rmag_lab = \
            PlotLabel(0.1,0.07,'%0.2f < rmag < %0.2f' % (rmag_min,rmag_max), 
                      halign='left')
        cflab = PlotLabel(0.1,0.15,
                          'camcol: %s filter: %s' % (camcol, self.band), 
                          halign='left')

        key = PlotKey(0.1,0.9, [pe1,pe2])
        keydt = PlotKey(0.1,0.9, [pe1dt,pe2dt])
        Rz=Curve([xmin,xmax],[0,0])
        Ra[0,0].add( Rz,pe1,pe1err,pe2,pe2err,ph,t1,t2,key)
        Ra[1,0].add( Rz,pe1dt,pe1dterr,pe2dt,pe2dterr,phdt,keydt,rmag_lab,cflab)

        if show:
            Ra.show()
        tab[0,0] = Ra

        # trends vs e1 psf
        print("\n* e1_psf")
        xmin = -0.275
        xmax =  0.275
        #ymin = -0.015
        #ymax =  0.015

        pe1psf_e1,pe1psf_e1err,pe1psf_e2,pe1psf_e2err,pe1psf_ph = \
                self.make_plot_components(data['e1_psf_'+band][w],
                                          data['e1_rg_'+band][w], 
                                          data['e2_rg_'+band][w], 
                                          weights, nperbin, ymin, ymax,
                                          fmin=xmin,fmax=xmax)

        pe1psf_e1_dt,pe1psf_e1_dterr,pe1psf_e2_dt,pe1psf_e2_dterr,pe1psf_ph_dt = \
                self.make_plot_components(data['e1_psf_'+band][w],
                                          e1dt[w], 
                                          e2dt[w], 
                                          weights, nperbin, ymin, ymax,
                                          fmin=xmin,fmax=xmax)



        # one row for before and after detrend
        e1psf_a=FramedArray(2,1)
        e1psf_a.xrange = [xmin,xmax]
        e1psf_a.yrange = [ymin,ymax]
        e1psf_a.xlabel = r'$e1_{PSF}$'
        #e1psf_a.ylabel = '<e>'

        e1psf_key = PlotKey(0.1,0.9, [pe1psf_e1,pe1psf_e2])
        e1psf_keydt = PlotKey(0.1,0.9, [pe1psf_e1_dt,pe1psf_e2_dt])
        e1psf_z=Curve([xmin,xmax],[0,0])
        e1psf_a[0,0].add(e1psf_z, 
                         pe1psf_e1,pe1psf_e1err, 
                         pe1psf_e2, pe1psf_e2err,
                         pe1psf_ph, e1psf_key)
        e1psf_a[1,0].add(e1psf_z, 
                         pe1psf_e1_dt, pe1psf_e1_dterr,
                         pe1psf_e2_dt, pe1psf_e2_dterr,
                         pe1psf_ph_dt, 
                         e1psf_keydt)

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


        # trends vs e2 psf
        print("\n* e2_psf")
        pe2psf_e1,pe2psf_e1err,pe2psf_e2,pe2psf_e2err,pe2psf_ph = \
                self.make_plot_components(data['e2_psf_'+band][w],
                                          data['e1_rg_'+band][w], 
                                          data['e2_rg_'+band][w], 
                                          weights, nperbin, ymin, ymax,
                                          fmin=xmin,fmax=xmax)

        pe2psf_e1_dt,pe2psf_e1_dterr,pe2psf_e2_dt,pe2psf_e2_dterr,pe2psf_ph_dt = \
                self.make_plot_components(data['e2_psf_'+band][w],
                                          e1dt[w], 
                                          e2dt[w], 
                                          weights, nperbin, ymin, ymax,
                                          fmin=xmin,fmax=xmax)



        # one row for before and after detrend
        e2psf_a=FramedArray(2,1)
        e2psf_a.xrange = [xmin,xmax]
        e2psf_a.yrange = [ymin,ymax]
        e2psf_a.xlabel = r'$e2_{PSF}$'
        #e2psf_a.ylabel = '<e>'

        e2psf_key = PlotKey(0.1,0.9, [pe2psf_e1,pe2psf_e2])
        e2psf_keydt = PlotKey(0.1,0.9, [pe2psf_e1_dt,pe2psf_e2_dt])
        e2psf_z=Curve([xmin,xmax],[0,0])
        e2psf_a[0,0].add(e2psf_z, 
                         pe2psf_e1, pe2psf_e1err,
                         pe2psf_e2, pe2psf_e2err,
                         pe2psf_ph, e2psf_key)
        e2psf_a[1,0].add(e2psf_z, 
                         pe2psf_e1_dt, pe2psf_e1_dterr,
                         pe2psf_e2_dt, pe2psf_e2_dterr,
                         pe2psf_ph_dt, 
                         e2psf_keydt)

        if show:
            e2psf_a.show()
        tab[0,2] = e2psf_a

        if show:
            tab.show()

        tab.write_eps(epsfile)
        converter.convert(epsfile, dpi=150, verbose=True)
Beispiel #2
0
def plot_lens_s2n(zl, zslow, zshigh, pzs, cumulative=True):
    """

    Calculate the cumulative expected usefulness of lenses as a function of
    redshift for the given source N(z).

    """

    import biggles
    from biggles import FramedPlot, Curve, PlotLabel, PlotKey, Table, Histogram

    biggles.configure('screen','width',1140)
    biggles.configure('screen','height',1140)
    nzl=zshigh.size
    zlmin = 0.0
    zlmax = max([zl.max(), zshigh.max()])

    # first get the mean inverse critical density as a function
    # of lens redshift
    zsmid = (zshigh+zslow)/2.
    sc = lensing.sigmacrit.ScinvCalculator(zlmin, zlmax, nzl, zsmid[0], zsmind[-1])

    mean_scinv = sc.calc_mean_scinv(pzs)


    # histogram the lens redshifts in a binning corresponding
    # to the mean_scinv

    hdict = eu.stat.histogram(zl, min=zlmin, max=zlmax, binsize=dz, more=True)

    # get distances to the bin centers
    cosmo=cosmology.Cosmo()
    Dlens = cosmo.Da(0.0, hdict['center'])

    # interpolate the mean_scinv onto the centers
    mean_scinv = eu.stat.interplin(mean_scinv, sc.zlvals, hdict['center'])

    # this is the S/N at a given lens redshift
    s2n = sqrt(hdict['hist']/Dlens**2)*mean_scinv

    hd = hdict['hist']/Dlens**2
    hdcum = hd.cumsum()
    s2ncum = (mean_scinv*hd).cumsum()/sqrt(hdcum.clip(1.,hdcum.max()))


    s2n /= s2n.max()
    s2ncum /= s2ncum.max()

    
    tab = Table(2,2)
    tab.aspect_ratio=1

    # redshift histograms
    tab[0,0] = FramedPlot()
    zl_histp = Histogram(hdict['hist']/float(hdict['hist'].sum()), x0=hdict['low'][0], binsize=dz, color='blue')
    zl_histp.label = 'lenses'
    zs_histp = Histogram(pzs/float(pzs.sum()), x0=zslow[0], binsize=dz, color='red')
    zs_histp.label = 'sources'

    hkey=PlotKey(0.9,0.9,[zl_histp,zs_histp],halign='right')
    tab[0,0].add(zl_histp, zs_histp, hkey)
    tab[0,0].xlabel = 'z'

    # mean inverse critical density
    tab[0,1] = FramedPlot()
    tab[0,1].xlabel = 'lens redshift'
    tab[0,1].ylabel = r'$\langle \Sigma_{crit}^{-1} \rangle$'

    mc = Curve(hdict['center'], mean_scinv)
    tab[0,1].add(mc)


    # cumulative volume
    tab[1,0] = FramedPlot()
    tab[1,0].xlabel = 'z'
    tab[1,0].ylabel = 'cumulative volume'
    v=zeros(hdict['center'].size)
    for i in xrange(v.size):
        v[i] = cosmo.V(0.0, hdict['center'][i])
    v /= v.max()
    cv=Curve(hdict['center'], v)
    tab[1,0].add(cv)


    # S/N
    tab[1,1] = FramedPlot()
    tab[1,1].xlabel = 'lens redshift'
    tab[1,1].ylabel = 'S/N'

    cs2n = Curve(hdict['center'], s2n, color='blue')
    cs2ncum = Curve(hdict['center'], s2ncum, color='red')

    cs2n.label = 'S/N'
    cs2ncum.label = 'Cumulative S/N'
    ckey=PlotKey(0.9,0.9,[cs2n, cs2ncum],halign='right')

    tab[1,1].add(cs2n, cs2ncum, ckey)


    tab.show()

    return tab