Exemple #1
0
def red_green_image(req, job_id=None, size='full'):
    from astrometry.plot.plotstuff import (Plotstuff,
                                           PLOTSTUFF_FORMAT_PNG,
                                           PLOTSTUFF_FORMAT_PPM,
                                           #plotstuff_set_size_wcs,
    )

    job = get_object_or_404(Job, pk=job_id)
    ui = job.user_image
    sub = ui.submission
    img = ui.image
    if size == 'display':
        scale = float(img.get_display_image().width)/img.width
        img = img.get_display_image()
    else:
        scale = 1.0

    axyfn = job.get_axy_file()
    wcsfn = job.get_wcs_file()
    rdlsfn = job.get_rdls_file()
    pnmfn = img.get_pnm_path()
    exfn = get_temp_file()

    try:
        plot = Plotstuff()
        plot.wcs_file = wcsfn
        plot.outformat = PLOTSTUFF_FORMAT_PNG
        plot.outfn = exfn
        plot.scale_wcs(scale)
        plot.set_size_from_wcs()
        #plotstuff_set_size_wcs(plot.pargs)

        # plot image
        pimg = plot.image
        pimg.set_file(str(pnmfn))
        pimg.format = PLOTSTUFF_FORMAT_PPM
        plot.color = 'white'
        plot.alpha = 1.
        if sub.use_sextractor:
            xy = plot.xy
            xy.xcol = 'X_IMAGE'
            xy.ycol = 'Y_IMAGE'
        plot.plot('image')

        # plot red
        xy = plot.xy
        if hasattr(img, 'sourcelist'):
            # set xy offsets for source lists
            fits = img.sourcelist.get_fits_table()
            #xy.xoff = int(fits.x.min())
            #xy.yoff = int(fits.y.min())
            xy.xoff = 0.
            xy.yoff = 0.

        xy.set_filename(str(axyfn))
        xy.scale = scale
        plot.color = 'red'
        xy.nobjs = 200
        plot.lw = 2.
        plot.markersize = 6
        plot.plot('xy')

        # plot green
        rd = plot.radec
        rd.set_filename(str(rdlsfn))
        plot.color = 'green'
        plot.markersize = 4
        plot.plot('radec')

        plot.write()
    except:
        return HttpResponse("plot failed")

    f = open(exfn, 'rb')
    res = StreamingHttpResponse(f)
    res['Content-Type'] = 'image/png'
    return res
Exemple #2
0
def grid_image(req, jobid=None, size='full'):
    from astrometry.plot.plotstuff import (Plotstuff,
                                           PLOTSTUFF_FORMAT_JPG,
                                           PLOTSTUFF_FORMAT_PPM,
                                           plotstuff_set_size_wcs,
    )
    job = get_object_or_404(Job, pk=jobid)
    ui = job.user_image
    img = ui.image
    if size == 'display':
        scale = float(img.get_display_image().width)/img.width
        img = img.get_display_image()
    else:
        scale = 1.0

    wcsfn = job.get_wcs_file()
    pnmfn = img.get_pnm_path()
    outfn = get_temp_file()

    plot = Plotstuff()
    plot.wcs_file = wcsfn
    plot.outformat = PLOTSTUFF_FORMAT_JPG
    plot.outfn = outfn
    plot.scale_wcs(scale)
    plotstuff_set_size_wcs(plot.pargs)

    # plot image
    pimg = plot.image
    pimg.set_file(str(pnmfn))
    pimg.format = PLOTSTUFF_FORMAT_PPM
    plot.plot('image')

    grid = plot.grid
    ra,dec,radius = job.calibration.get_center_radecradius()
    steps = np.array([ 0.02, 0.05, 0.1, 0.2, 0.5,
                       1., 2., 5., 10., 15.,  30., 60. ])
    istep = np.argmin(np.abs(np.log(radius) - np.log(steps)))
    grid.declabelstep = steps[istep]
    nd = plot.count_dec_labels()
    if nd < 2:
        istep = max(istep-1, 0)
        grid.declabelstep = steps[istep]
    grid.decstep = grid.declabelstep
    plot.alpha = 1.
    plot.plot('grid')

    plot.alpha = 0.7
    grid.declabelstep = 0
    grid.decstep /= 2.
    plot.plot('grid')
    grid.decstep = 0

    # RA
    cosdec = np.cos(np.deg2rad(dec))
    istep = np.argmin(np.abs(np.log(radius/cosdec) - np.log(steps)))
    grid.ralabelstep = steps[istep] #min(istep+1, len(steps)-1)]
    nra = plot.count_ra_labels()
    if nra < 2:
        istep = max(istep-1, 0)
        grid.ralabelstep = steps[istep]
    grid.rastep = grid.ralabelstep
    plot.alpha = 1.
    plot.plot('grid')

    plot.alpha = 0.7
    grid.ralabelstep = 0
    grid.rastep /= 2.
    plot.plot('grid')

    plot.write()
    f = open(outfn, 'rb')
    res = HttpResponse(f)
    res['Content-Type'] = 'image/jpeg'
    return res