Esempio n. 1
0
def doplot(x, y, e1, e2, ccd, ewcs, scale=5.0, 
           plt=None, color='black'):
    """
    Just plot the e1/e2 whiskers for the input objects
    """

    if plt is None:
        plt = biggles.FramedPlot()

    ra = x.copy()
    dec = x.copy()
    ra[:] = -9999
    dec[:] = -9999
    for this_ccd in xrange(1,62+1):
        # put the x,y from each ccd onto the camera location
        # of our fiducial pointing, held in ewcs

        ccd_wcs = ewcs[this_ccd]

        wccd, = where(ccd == this_ccd)
        if wccd.size > 0:
            tra, tdec = ccd_wcs.image2sky(x[wccd],y[wccd])

            tra -= 337.3
            tdec += 15.0
            ra[wccd] = numpy.float32( tra )
            dec[wccd] = numpy.float32( tdec)

    # ok, let's make a plot

    # add whiskers for each e1/e2 to the plot
    u,v = polar2whisker(e1,e2)
    plt = bwhiskers(ra, dec, u, v, plt=plt, color=color, scale=scale)

    one_percent = 0.01*scale

    one_percent_x = numpy.array([0.9,0.9],dtype='f4')
    one_percent_y = numpy.array([1.0,1.0],dtype='f4')
    one_percent_x[0] -= one_percent*0.5
    one_percent_x[1] += one_percent*0.5
    one_percent_curve = biggles.Curve(one_percent_x,one_percent_y,color='blue',
                                      linewidth=2)
    plt.add(one_percent_curve)

    one_percent_label = biggles.PlotLabel(0.935,0.885,"0.01")
    plt.add(one_percent_label)

    plt.xrange = -1.3,1.3
    plt.yrange = -1.3,1.3
    plt.xlabel = r'$\Delta$RA'
    plt.ylabel = r'$\Delta$DEC'

    return plt
Esempio n. 2
0
def doplot(serun, exposurename, example_wcs_byccd, nx=3,ny=3,diff=False,
           imageformat='png', ptypes=['unbinned','comparebinned']):

    stdout.write("serun: %s\n" % serun)
    stdout.write("exposurename: %s\n" % exposurename)
    stdout.write("\tReading checkpsf data\n")

    alldata = []
    allstats = []

    for ccd in range(1,62+1):

        try:
            data = deswl.files.wlse_read(exposurename,ccd,'checkpsf',
                                         serun=serun)

            fields=['e1','e2','e1interp','e2interp']
            stats = du.stats_xy(data, fields, nx=nx, ny=ny, typ='median')

            ccd_wcs = example_wcs_byccd[ccd]
            fx,fy = ccd_wcs.image2sky(data['x'], data['y'])
            mfx,mfy = ccd_wcs.image2sky(stats['mx'],stats['my'])

            newdata = numpy_util.add_fields(data, [('fx','f4'),('fy','f4')])
            newdata['fx'] = fx - 337.3
            newdata['fy'] = fy + 15.0

            fadd=[('mfx','f4'),('mfy','f4'),('me1diff','f4'),('me2diff','f4')]
            newstats = numpy_util.add_fields(stats,fadd)
            newstats['mfx'] = mfx - 337.3
            newstats['mfy'] = mfy + 15.0
            newstats['me1diff'] = newstats['me1interp']-newstats['me1']
            newstats['me2diff'] = newstats['me2interp']-newstats['me2']

            alldata.append(newdata)
            allstats.append(newstats)

        except:
            stdout.write("Failed ccd=%s\n" % ccd)
            print sys.exc_info()

    data = numpy_util.combine_arrlist(alldata)
    stats = numpy_util.combine_arrlist(allstats)

    stdout.write("\tPlotting whiskers\n")
    plt = du.setuplot('Agg')
    plt.clf()

    nplots = len(ptypes)
    xsize=8*nplots
    fig=plt.figure(figsize=(xsize,7))

    iplot = 1

    u, v = polar2whisker(data['e1'], data['e2'])
    uinterp, vinterp = polar2whisker(data['e1interp'], data['e2interp'])
    mu, mv = polar2whisker(stats['me1'],stats['me2'])
    muinterp, mvinterp = polar2whisker(stats['me1interp'],stats['me2interp'])
    mudiff, mvdiff = polar2whisker(stats['me1diff'],stats['me2diff'])



    # example size to plot
    psize=0.01

    if 'unbinned' in ptypes or 'compareunbinned' in ptypes:
        stdout.write("\t\tDoing plot type 'unbinned'\n")
        ax = fig.add_subplot(1,nplots,iplot)
        iplot += 1

        # plot individual stars
        scale=3.
        whiskers(ax, data['fx'], data['fy'], u, v, scale=scale,
                 linewidth=0.25)

        # a measure of scale
        xtext=-1.2
        ax.text(xtext, 0.9, str(psize), verticalalignment='center')
        whiskers(ax, xtext+0.18, 0.9, psize, 0.0, color='blue', scale=scale)

        if 'compareunbinned' in ptypes:
            stdout.write("\t\tOverplotting 'compareunbinned'\n")
            whiskers(ax, data['fx'], data['fy'], uinterp, vinterp, 
                     scale=scale, color='red', linewidth=0.25)
            
            # add a legend

            ypos = 1.1
            ystep = 0.07
            xtext = -1.1

            ax.text(xtext, ypos-ystep, "data", verticalalignment='center')
            whiskers(ax, xtext+0.23, ypos-ystep, psize, 0.0, 
                     color='black', scale=scale)
            ax.text(xtext, ypos-2*ystep, "interp", verticalalignment='center')
            whiskers(ax, xtext+0.23, ypos-2*ystep, psize, 0.0, 
                     color='red', scale=scale)


        ax.set_xlim(-1.3,1.3)
        ax.set_ylim(-1.3,1.3)
        set_minor_ticks(ax)

    if 'comparebinned' in ptypes:
        # comparison plot for the binned data
        ax = fig.add_subplot(1,nplots,iplot)
        iplot += 1

        scale=10.
        whiskers(ax, stats['mfx'], stats['mfy'], mu, mv, scale=scale)
        whiskers(ax, stats['mfx'], stats['mfy'], muinterp, mvinterp, 
                 scale=scale, color='red')

        # legend
        ypos = 1.1
        ystep = 0.07
        xtext = -1.1

        ax.text(xtext, ypos, str(psize), verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos, psize, 0.0, color='blue', scale=scale)

        ax.text(xtext, ypos-ystep, "data", verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos-ystep, psize, 0.0, 
                 color='black', scale=scale)
        ax.text(xtext, ypos-2*ystep, "interp", verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos-2*ystep, psize, 0.0, 
                 color='red', scale=scale)

        ax.set_xlim(-1.3,1.3)
        ax.set_ylim(-1.3,1.3)
        set_minor_ticks(ax)

    if 'diffbinned' in ptypes:
        # comparison plot for the binned data
        ax = fig.add_subplot(1,nplots,iplot)
        iplot += 1

        scale=50.
        psize=0.001
        whiskers(ax, stats['mfx'], stats['mfy'], mudiff, mvdiff, scale=scale)

        ax.text(xtext, ypos, str(psize), verticalalignment='center')
        whiskers(ax, xtext+0.23, ypos, psize, 0.0, color='blue', scale=scale)

        ax.set_xlim(-1.3,1.3)
        ax.set_ylim(-1.3,1.3)
        set_minor_ticks(ax)


    outdir='/home/users/esheldon/www/tmp/plots'
    outdir=os.path.join(outdir, serun)
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    ptypes_string = '-'.join(ptypes)
    outfile = "%s-checkpsf-%s.%s" % (exposurename,ptypes_string, imageformat)
    outfile=os.path.join(outdir,outfile)
    stdout.write("\tWriting plot file: %s\n" % outfile)
    plt.savefig(outfile, bbox_inches='tight', pad_inches=0.1)