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

    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()
    pnmfn = img.get_pnm_path()
    exfn = get_temp_file()

    try:
        plot = Plotstuff()
        plot.size = [img.width, img.height]
        plot.outformat = PLOTSTUFF_FORMAT_PNG
        plot.outfn = exfn

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

        # plot sources
        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 = xy.yoff = 1.

        if sub.use_sextractor:
            xy.xcol = 'X_IMAGE'
            xy.ycol = 'Y_IMAGE'

        xy.set_filename(str(axyfn))
        xy.scale = scale
        plot.color = 'red'
        # plot 50 brightest
        xy.firstobj = 0
        xy.nobjs = 50
        plot.lw = 2.
        plot.markersize = 6
        plot.plot('xy')
        # plot 200 other next brightest sources
        xy.firstobj = 50
        xy.nobjs = 250
        plot.alpha = 0.9
        plot.lw = 1.
        plot.markersize = 4
        plot.plot('xy')
        # plot 250 other next brightest sources
        xy.firstobj = 250
        xy.nobjs = 500
        plot.alpha = 0.5
        plot.lw = 1.
        plot.markersize = 3
        plot.plot('xy')
        plot.write()
    except:
        import traceback
        traceback.print_exc()
        return HttpResponse("plot failed")

    f = open(exfn, 'rb')
    res = HttpResponse(f)
    res['Content-Type'] = 'image/png'
    return res
Exemple #2
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