Exemple #1
0
def plot2dsig_old(r, dsig1, dsig1err, dsig2, dsig2err, **keys):
    """
    Plot delta sigma and a second delta sigma in two plots the second of which
    is linear.

    Parameters
    ----------
    show: bool, optional
        Show plot in a window, default True
    range1: [min,max]
        The y range of the delta sigma plot
    range2: [min,max]
        The y range of the ortho-delta sigma plot
    range2var: [min,max]
        The x range over which to calculate a osig variance
        and determine a plot range.  This is overridden by
        range2

    plot_label: string, optional
        a label for the top plot

    # label1,label2 go in a key in the bottom plot
    label1: string, optional
        a label for the first dsig
    label2: string, optional
        a label for the second dsig


    """

    show = keys.get('show',True)
    range1 = keys.get('range1',None)
    range2 = keys.get('range2',None)

    # this over-rides
    range4var = keys.get('range4var',None)
    if range2 is None:
        if range4var is not None:
            w=where1( (r >= range4var[0]) & (r <= range4var[1]))
            if w.size == 0:
                raise ValueError("no points in range [%d,%d]" % tuple(range4var))
            sdev = dsig2[w].std()
        else:
            sdev = dsig2.std()

        range2 = [-3.5*sdev, 3.5*sdev]
        print 'range2:',range2


    label  = keys.get('plot_label',None)
    label1 = keys.get('label1',None)
    label2 = keys.get('label2',None)

    # for overplotting
    dsig1_p = Points(r, dsig1, color='red')
    dsig1err_p = SymErrY(r, dsig1, dsig1err, color='red')
    dsig1_p.label=label1

    dsig2_p = Points(r, dsig1, color='red')
    dsig2err_p = SymErrY(r, dsig1, dsig1err, color='black')
    dsig2_p.label=label1

    arr = FramedArray(2,1)
    arr.aspect_ratio=2
    arr.xlabel = labels['rproj']
    arr.ylabel = labels['dsig']

    eu.plotting.bscatter(r, dsig1, yerr=dsig1err,
                         xlog=True, ylog=True, 
                         yrange=range1,
                         show=False, 
                         plt=arr[0,0],
                         **keys)

    if label is not None:
        arr[0,0].add(PlotLabel(0.9,0.9,label,halign='right'))


    pdict=eu.plotting.bscatter(r, dsig2, yerr=dsig2err,
                               xlog=True, 
                               yrange=range2,
                               label=label2,
                               show=False,
                               dict=True,
                               plt=arr[1,0],
                               **keys)
    c=Curve([1.e-5,1.e5],[0,0], type='solid')
    arr[1,0].add(c)
    arr[1,0].add(dsig1_p,dsig1err_p)

    if label1 is not None or label2 is not None:
        key = PlotKey(0.9,0.9, [dsig1_p,pdict['p']], halign='right')
        arr[1,0].add(key)


    if show:
        arr.show()
    return arr
Exemple #2
0
def plot2dsig(r1, dsig1, dsig1err, r2, dsig2, dsig2err, **keys):
    """
    Plot delta sigma and a second delta sigma in two plots the second of which
    is linear.

    Parameters
    ----------
    show: bool, optional
        Show plot in a window, default True
    yrange1: [min,max]
        The y range of the delta sigma plot
    yrange2: [min,max]
        The y range of the ortho-delta sigma plot
    range4var: [min,max]
        The x range over which to calculate a osig variance
        and determine a plot range.  This is overridden by
        range2

    plot_label: string, optional
        a label for the top plot

    # label1,label2 go in a key in the bottom plot
    label1: string, optional
        a label for the first dsig
    label2: string, optional
        a label for the second dsig


    """

    color2 = 'red'
    ptype1='filled circle'
    size1=1.5
    ptype2='filled circle'
    size2=1.5

    xmul = keys.get('xmul',1.)

    show = keys.get('show',True)
    yrange1 = keys.get('yrange1',None)
    yrange2 = keys.get('yrange2',None)

    isortho = keys.get('ortho',False)

    # this is a y-log plot, use more powerful range determination
    print dsig1
    print dsig1err
    yrange1 = eu.plotting.get_log_plot_range(dsig1, err=dsig1err, 
                                             input_range=yrange1)

    rr=numpy.concatenate((r1,r2))
    xrng = eu.plotting.get_log_plot_range(rr)

    # this over-rides
    range4var = keys.get('range4var',None)
    if yrange2 is None:
        if range4var is not None:
            w=where1( (r2 >= range4var[0]) & (r2 <= range4var[1]))
            if w.size == 0:
                raise ValueError("no points in range [%d,%d]" % tuple(range4var))
            sdev = dsig2[w].std()
        else:
            sdev = dsig2.std()

        yrange2 = [-3.5*sdev, 3.5*sdev]


    label  = keys.get('plot_label',None)
    label1 = keys.get('label1',None)
    label2 = keys.get('label2',None)

    # The points and zero curve
    dsig1_p = Points(r1, dsig1, color='black', type=ptype1, size=size1)
    dsig1err_p = SymErrY(r1, dsig1, dsig1err, color='black')
    dsig1_p.label=label1

    dsig2_p = Points(r2*xmul, dsig2, color=color2, type=ptype2, size=size2)
    dsig2err_p = SymErrY(r2*xmul, dsig2, dsig2err, color=color2)
    dsig2_p.label=label2

    c=Curve([1.e-5,1.e5],[0,0], type='solid')


    arr = FramedArray(2,1)
    arr.cellspacing=1
    arr.aspect_ratio=2
    arr.xlabel = labels['rproj']
    if isortho:
        arr.ylabel = labels['osig']
    else:
        arr.ylabel = labels['dsig']
    arr.xrange = xrng


    arr[0,0].yrange = yrange1
    arr[0,0].xlog=True
    arr[0,0].ylog=True

    # biggles chokes if you give it negative data for a log plot
    arr[0,0].add(dsig1_p, dsig2_p)
    eu.plotting.add_log_error_bars(arr[0,0],'y',r1,dsig1,dsig1err,yrange1)
    eu.plotting.add_log_error_bars(arr[0,0],'y',r2,dsig2,dsig2err,yrange1,color=color2)

    if label is not None:
        arr[0,0].add(PlotLabel(0.9,0.9,label,halign='right'))


    arr[1,0].yrange = yrange2
    arr[1,0].xlog=True
    arr[1,0].add(c)
    arr[1,0].add(dsig1_p, dsig1err_p, dsig2_p, dsig2err_p)

    if label1 is not None or label2 is not None:
        key = PlotKey(0.9,0.15, [dsig1_p,dsig2_p], halign='right')
        arr[1,0].add(key)


    if show:
        arr.show()
    return arr
Exemple #3
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)