Ejemplo n.º 1
0
def run_ptf(src, tag, opt):
    ps = PlotSequence('ptf-%s' % (tag))

    stari = src.srci
    fns = glob('ptf-%i/*.fits' % stari)
    print('Found files:', len(fns))
    stamps = []
    for fn in fns:
        print('  ', fn)
        wcs = Sip(fn, 0)
        x, y = wcs.radec2pixelxy(src.ra, src.dec)
        print('  source at', x, y)
        img = pyfits.open(fn)[0].data
        print('  image', img.shape)
        H, W = img.shape
        ix = int(np.round(x))
        iy = int(np.round(y))
        S = 20
        stamp = img[max(0, iy - S):min(H, iy + S),
                    max(0, ix - S):min(W, ix + S)]
        stamps.append(stamp)

    N = len(stamps)
    cols = int(np.ceil(np.sqrt(N)))
    rows = int(np.ceil(N / float(cols)))
    plt.clf()
    for i, stamp in enumerate(stamps):
        plt.subplot(rows, cols, i + 1)
        plt.imshow(stamp, interpolation='nearest', origin='lower')
    ps.savefig()
Ejemplo n.º 2
0
def run_ptf(src, tag, opt):
	ps = PlotSequence('ptf-%s' % (tag))

	stari = src.srci
	fns = glob('ptf-%i/*.fits' % stari)
	print 'Found files:', len(fns)
	stamps = []
	for fn in fns:
		print '  ', fn
		wcs = Sip(fn, 0)
		x,y = wcs.radec2pixelxy(src.ra, src.dec)
		print '  source at', x, y
		img = pyfits.open(fn)[0].data
		print '  image', img.shape
		H,W = img.shape
		ix = int(np.round(x))
		iy = int(np.round(y))
		S = 20
		stamp = img[max(0, iy - S) : min(H, iy+S),
					max(0, ix - S) : min(W, ix+S)]
		stamps.append(stamp)

	N = len(stamps)
	cols = int(np.ceil(np.sqrt(N)))
	rows = int(np.ceil(N / float(cols)))
	plt.clf()
	for i,stamp in enumerate(stamps):
		plt.subplot(rows, cols, i+1)
		plt.imshow(stamp, interpolation='nearest', origin='lower')
	ps.savefig()
Ejemplo n.º 3
0
    print('Reading WCS from', flt1)
    wcs1 = Sip(flt1, 0)
    wcs1.ensure_inverse_polynomials()
    # print('Reading WCS from', flt2)
    # wcs2 = Sip(flt2, 0)
    # wcs2.ensure_inverse_polynomials()

    print('T1 X,Y ranges', T1.x.min(), T1.x.max(), T1.y.min(), T1.y.max())
    print('T2 X,Y ranges', T2.x.min(), T2.x.max(), T2.y.min(), T2.y.max())

    # ~ 1e-6, 0.0006
    # ok,x,y = wcs2.radec2pixelxy(T2.ra, T2.dec)
    # print('Scatter wcs x vs catalog x:', np.mean(x - T2.x), np.std(x - T2.x))
    # print('Scatter wcs y vs catalog y:', np.mean(y - T2.y), np.std(y - T2.y))

    ok, x, y = wcs1.radec2pixelxy(T2.ra, T2.dec)
    print('Converted X,Y ranges:', x.min(), x.max(), y.min(), y.max())
    T2.x = x
    T2.y = y

    TT = merge_tables([T1, T2])
    TT.writeto(gstout)
    print('Wrote', gstout)

    hdr = pyfits.open(flt1)[0].header
    hdr['IMAGEW'] = 4096
    hdr['IMAGEH'] = 4096
    pyfits.writeto(fltout, None, header=hdr, clobber=True)
    print('Wrote', fltout)

    #cmd = 'cp "%s" "%s"' % (flt1, fltout)
Ejemplo n.º 4
0
    print('Reading WCS from', flt1)
    wcs1 = Sip(flt1, 0)
    wcs1.ensure_inverse_polynomials()
    # print('Reading WCS from', flt2)
    # wcs2 = Sip(flt2, 0)
    # wcs2.ensure_inverse_polynomials()

    print('T1 X,Y ranges', T1.x.min(), T1.x.max(), T1.y.min(), T1.y.max())
    print('T2 X,Y ranges', T2.x.min(), T2.x.max(), T2.y.min(), T2.y.max())

    # ~ 1e-6, 0.0006
    # ok,x,y = wcs2.radec2pixelxy(T2.ra, T2.dec)
    # print('Scatter wcs x vs catalog x:', np.mean(x - T2.x), np.std(x - T2.x))
    # print('Scatter wcs y vs catalog y:', np.mean(y - T2.y), np.std(y - T2.y))
    
    ok,x,y = wcs1.radec2pixelxy(T2.ra, T2.dec)
    print('Converted X,Y ranges:', x.min(), x.max(), y.min(), y.max())
    T2.x = x
    T2.y = y
    
    TT = merge_tables([T1,T2])
    TT.writeto(gstout)
    print('Wrote', gstout)

    hdr = pyfits.open(flt1)[0].header
    hdr['IMAGEW'] = 4096
    hdr['IMAGEH'] = 4096
    pyfits.writeto(fltout, None, header=hdr, clobber=True)
    print('Wrote', fltout)

    #cmd = 'cp "%s" "%s"' % (flt1, fltout)
Ejemplo n.º 5
0
def main():
    decals = Decals()

    catpattern = 'pipebrick-cats/tractor-phot-b%06i.fits'
    ra, dec = 242, 7

    # Region-of-interest, in pixels: x0, x1, y0, y1
    #roi = None
    roi = [500, 1000, 500, 1000]

    if roi is not None:
        x0, x1, y0, y1 = roi

    #expnum = 346623
    #ccdname = 'N12'
    #chips = decals.find_ccds(expnum=expnum, extname=ccdname)
    #print 'Found', len(chips), 'chips for expnum', expnum, 'extname', ccdname
    #if len(chips) != 1:
    #return False

    chips = decals.get_ccds()
    D = np.argsort(np.hypot(chips.ra - ra, chips.dec - dec))
    print('Closest chip:', chips[D[0]])
    chips = [chips[D[0]]]

    im = DecamImage(decals, chips[0])
    print('Image:', im)

    targetwcs = Sip(im.wcsfn)
    if roi is not None:
        targetwcs = targetwcs.get_subimage(x0, y0, x1 - x0, y1 - y0)

    r0, r1, d0, d1 = targetwcs.radec_bounds()
    # ~ 30-pixel margin
    margin = 2e-3
    if r0 > r1:
        # RA wrap-around
        TT = [
            brick_catalog_for_radec_box(ra, rb, d0 - margin, d1 + margin,
                                        decals, catpattern)
            for (ra, rb) in [(0, r1 + margin), (r0 - margin, 360.)]
        ]
        T = merge_tables(TT)
        T._header = TT[0]._header
    else:
        T = brick_catalog_for_radec_box(r0 - margin, r1 + margin, d0 - margin,
                                        d1 + margin, decals, catpattern)

    print('Got', len(T), 'catalog entries within range')
    cat = read_fits_catalog(T, T._header)
    print('Got', len(cat), 'catalog objects')

    print('Switching ellipse parameterizations')
    switch_to_soft_ellipses(cat)
    keepcat = []
    for src in cat:
        if not np.all(np.isfinite(src.getParams())):
            print('Src has infinite params:', src)
            continue
        if isinstance(src, FixedCompositeGalaxy):
            f = src.fracDev.getClippedValue()
            if f == 0.:
                src = ExpGalaxy(src.pos, src.brightness, src.shapeExp)
            elif f == 1.:
                src = DevGalaxy(src.pos, src.brightness, src.shapeDev)
        keepcat.append(src)
    cat = keepcat

    slc = None
    if roi is not None:
        slc = slice(y0, y1), slice(x0, x1)
    tim = im.get_tractor_image(slc=slc)
    print('Got', tim)
    tim.psfex.fitSavedData(*tim.psfex.splinedata)
    tim.psfex.radius = 20
    tim.psf = CachingPsfEx.fromPsfEx(tim.psfex)

    tractor = Tractor([tim], cat)
    print('Created', tractor)

    mod = tractor.getModelImage(0)

    plt.clf()
    dimshow(tim.getImage(), **tim.ima)
    plt.title('Image')
    plt.savefig('1.png')

    plt.clf()
    dimshow(mod, **tim.ima)
    plt.title('Model')
    plt.savefig('2.png')

    ok, x, y = targetwcs.radec2pixelxy([src.getPosition().ra for src in cat],
                                       [src.getPosition().dec for src in cat])
    ax = plt.axis()
    plt.plot(x, y, 'rx')
    #plt.savefig('3.png')
    plt.axis(ax)
    plt.title('Sources')
    plt.savefig('3.png')

    bands = [im.band]
    import runbrick
    runbrick.photoobjdir = '.'
    scat, T = get_sdss_sources(bands, targetwcs, local=False)
    print('Got', len(scat), 'SDSS sources in bounds')

    stractor = Tractor([tim], scat)
    print('Created', stractor)
    smod = stractor.getModelImage(0)

    plt.clf()
    dimshow(smod, **tim.ima)
    plt.title('SDSS model')
    plt.savefig('4.png')
Ejemplo n.º 6
0
def main():
    decals = Decals()

    catpattern = 'pipebrick-cats/tractor-phot-b%06i.fits'
    ra,dec = 242, 7

    # Region-of-interest, in pixels: x0, x1, y0, y1
    #roi = None
    roi = [500, 1000, 500, 1000]

    if roi is not None:
        x0,x1,y0,y1 = roi

    #expnum = 346623
    #ccdname = 'N12'
    #chips = decals.find_ccds(expnum=expnum, extname=ccdname)
    #print 'Found', len(chips), 'chips for expnum', expnum, 'extname', ccdname
    #if len(chips) != 1:
    #return False

    chips = decals.get_ccds()
    D = np.argsort(np.hypot(chips.ra - ra, chips.dec - dec))
    print('Closest chip:', chips[D[0]])
    chips = [chips[D[0]]]

    im = DecamImage(decals, chips[0])
    print('Image:', im)

    targetwcs = Sip(im.wcsfn)
    if roi is not None:
        targetwcs = targetwcs.get_subimage(x0, y0, x1-x0, y1-y0)

    r0,r1,d0,d1 = targetwcs.radec_bounds()
    # ~ 30-pixel margin
    margin = 2e-3
    if r0 > r1:
        # RA wrap-around
        TT = [brick_catalog_for_radec_box(ra,rb, d0-margin,d1+margin,
                                          decals, catpattern)
                for (ra,rb) in [(0, r1+margin), (r0-margin, 360.)]]
        T = merge_tables(TT)
        T._header = TT[0]._header
    else:
        T = brick_catalog_for_radec_box(r0-margin,r1+margin,d0-margin,
                                        d1+margin, decals, catpattern)

    print('Got', len(T), 'catalog entries within range')
    cat = read_fits_catalog(T, T._header)
    print('Got', len(cat), 'catalog objects')

    print('Switching ellipse parameterizations')
    switch_to_soft_ellipses(cat)
    keepcat = []
    for src in cat:
        if not np.all(np.isfinite(src.getParams())):
            print('Src has infinite params:', src)
            continue
        if isinstance(src, FixedCompositeGalaxy):
            f = src.fracDev.getClippedValue()
            if f == 0.:
                src = ExpGalaxy(src.pos, src.brightness, src.shapeExp)
            elif f == 1.:
                src = DevGalaxy(src.pos, src.brightness, src.shapeDev)
        keepcat.append(src)
    cat = keepcat

    slc = None
    if roi is not None:
        slc = slice(y0,y1), slice(x0,x1)
    tim = im.get_tractor_image(slc=slc)
    print('Got', tim)
    tim.psfex.fitSavedData(*tim.psfex.splinedata)
    tim.psfex.radius = 20
    tim.psf = CachingPsfEx.fromPsfEx(tim.psfex)
    
    tractor = Tractor([tim], cat)
    print('Created', tractor)

    mod = tractor.getModelImage(0)

    plt.clf()
    dimshow(tim.getImage(), **tim.ima)
    plt.title('Image')
    plt.savefig('1.png')

    plt.clf()
    dimshow(mod, **tim.ima)
    plt.title('Model')
    plt.savefig('2.png')

    
    ok,x,y = targetwcs.radec2pixelxy([src.getPosition().ra  for src in cat],
                                  [src.getPosition().dec for src in cat])
    ax = plt.axis()
    plt.plot(x, y, 'rx')
    #plt.savefig('3.png')
    plt.axis(ax)
    plt.title('Sources')
    plt.savefig('3.png')
    
    bands = [im.band]
    import runbrick
    runbrick.photoobjdir = '.'
    scat,T = get_sdss_sources(bands, targetwcs, local=False)
    print('Got', len(scat), 'SDSS sources in bounds')
    
    stractor = Tractor([tim], scat)
    print('Created', stractor)
    smod = stractor.getModelImage(0)

    plt.clf()
    dimshow(smod, **tim.ima)
    plt.title('SDSS model')
    plt.savefig('4.png')