outfn = 'lsb/lsb-%s-%s.fits' % (exp, ext) f.write( 'python projects/desi/lsb.py --expnum %i --extname %s --out %s -F -n > lsb/lsb-%s-%s.log 2>&1\n' % (exp, ext, outfn, exp, ext)) f.close() log('Wrote', opt.out) sys.exit(0) log('Writing calibs to', opt.out) f = open(opt.out, 'w') log('Total of', len(allI), 'CCDs') for j, i in enumerate(allI): if opt.delete_sky or opt.delete_pvastrom: log(j + 1, 'of', len(allI)) im = DecamImage(decals, T[i]) if opt.delete_sky and os.path.exists(im.skyfn): log(' deleting:', im.skyfn) os.unlink(im.skyfn) if opt.delete_pvastrom and os.path.exists(im.pvwcsfn): log(' deleting:', im.pvwcsfn) os.unlink(im.pvwcsfn) if opt.check: log(j + 1, 'of', len(allI)) im = DecamImage(decals, T[i]) if not im.run_calibs(im, just_check=True): log('Calibs for', im.expnum, im.ccdname, im.calname, 'already done') continue
zoomslice = None if opt.zoom is not None: (x0,x1,y0,y1) = opt.zoom zoomslice = (slice(y0,y1), slice(x0,x1)) ps = None if opt.plots is not None: from astrometry.util.plotutils import PlotSequence ps = PlotSequence(opt.plots) T = exposure_metadata([filename], hdus=[hdu]) print 'Metadata:' T.about() decals = Decals() im = DecamImage(decals, T[0]) tim = im.get_tractor_image(slc=zoomslice, const2psf=True) print 'Got tim:', tim if catfn == 'DR1': margin = 20 TT = [] chipwcs = tim.subwcs bricks = bricks_touching_wcs(chipwcs, decals=decals) for b in bricks: # there is some overlap with this brick... read the catalog. fn = os.path.join(opt.catalog_path, 'tractor', b.brickname[:3], 'tractor-%s.fits' % b.brickname) if not os.path.exists(fn): print 'WARNING: catalog', fn, 'does not exist. Skipping!' continue
D = Decals() if opt.ccds is not None: T = fits_table(opt.ccds) print 'Read', len(T), 'from', opt.ccds else: T = D.get_ccds() print len(T), 'CCDs' print len(T), 'CCDs' if len(args) == 0: if opt.expnum is not None: T.cut(T.expnum == opt.expnum) print 'Cut to', len(T), 'with expnum =', opt.expnum if opt.extname is not None: T.cut(np.array([(t.strip() == opt.extname) for t in T.ccdname])) print 'Cut to', len(T), 'with extname =', opt.extname args = range(len(T)) for a in args: i = int(a) t = T[i] im = DecamImage(D, t) print 'Running', im.calname if opt.force: kwargs.update(force=True) run_calibs((im, kwargs))
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')
import os import numpy as np from astrometry.util.fits import fits_table from common import decals_dir, run_calibs, DecamImage if __name__ == '__main__': import optparse parser = optparse.OptionParser() opt, args = parser.parse_args() ccdsfn = os.path.join(decals_dir, 'decals-ccds.fits') T = fits_table(ccdsfn) for a in args: i = int(a) t = T[i] print 'Running', t.calname im = DecamImage(t) pixscale = np.sqrt(np.abs(t.cd1_1 * t.cd2_2 - t.cd1_2 * t.cd2_1)) pixscale *= 3600. print 'Pixscale', pixscale, 'arcsec/pix' mock_psf = False kwargs = dict() kwargs.update(psfex=False, psfexfit=False) run_calibs((im, kwargs, t.ra, t.dec, pixscale, mock_psf))
ext = T.ccdname[i].strip() outfn = 'lsb/lsb-%s-%s.fits' % (exp, ext) f.write('python projects/desi/lsb.py --expnum %i --extname %s --out %s -F -n > lsb/lsb-%s-%s.log 2>&1\n' % (exp, ext, outfn, exp, ext)) f.close() log('Wrote', opt.out) sys.exit(0) log('Writing calibs to', opt.out) f = open(opt.out,'w') log('Total of', len(allI), 'CCDs') for j,i in enumerate(allI): if opt.delete_sky or opt.delete_pvastrom: log(j+1, 'of', len(allI)) im = DecamImage(decals, T[i]) if opt.delete_sky and os.path.exists(im.skyfn): log(' deleting:', im.skyfn) os.unlink(im.skyfn) if opt.delete_pvastrom and os.path.exists(im.pvwcsfn): log(' deleting:', im.pvwcsfn) os.unlink(im.pvwcsfn) if opt.check: log(j+1, 'of', len(allI)) im = DecamImage(decals, T[i]) if not im.run_calibs(im, just_check=True): log('Calibs for', im.expnum, im.ccdname, im.calname, 'already done') continue if opt.command:
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')