def main(): ps = PlotSequence('cov') survey = LegacySurveyData() ra,dec = 242.0, 10.2 fn = 'coverage-ccds.fits' if not os.path.exists(fn): ccds = survey.get_ccds() ccds.cut(ccds.filter == 'r') ccds.cut(ccds.propid == '2014B-0404') ccds.cut(np.hypot(ccds.ra_bore - ra, ccds.dec_bore - dec) < 2.5) print(np.unique(ccds.expnum), 'unique exposures') print('propids', np.unique(ccds.propid)) ccds.writeto(fn) else: ccds = fits_table(fn) plt.clf() for e in np.unique(ccds.expnum): I = np.flatnonzero(ccds.expnum == e) plt.plot(ccds.ra[I], ccds.dec[I], '.') ps.savefig() degw = 3.0 pixscale = 10. W = degw * 3600 / 10. H = W hi = 6 cmap = cmap_discretize('jet', hi+1) wcs = Tan(ra, dec, W/2.+0.5, H/2.+0.5, -pixscale/3600., 0., 0., pixscale/3600., float(W), float(H)) r0,d0 = wcs.pixelxy2radec(1,1) r1,d1 = wcs.pixelxy2radec(W,H) extent = [min(r0,r1),max(r0,r1), min(d0,d1),max(d0,d1)] for expnums in [ [348666], [348666,348710, 348686], [348659, 348667, 348658, 348666, 348665, 348669, 348668], None, [348683, 348687, 347333, 348686, 348685, 348692, 348694, 348659, 348667, 348658, 348666, 348665, 348669, 348668, 348707, 348709, 348708, 348710, 348711, 348716, 348717], ]: nexp = np.zeros((H,W), np.uint8) for ccd in ccds: if expnums is not None and not ccd.expnum in expnums: continue ccdwcs = survey.get_approx_wcs(ccd) r,d = ccdwcs.pixelxy2radec(1, 1) ok,x0,y0 = wcs.radec2pixelxy(r, d) r,d = ccdwcs.pixelxy2radec(ccd.width, ccd.height) ok,x1,y1 = wcs.radec2pixelxy(r, d) xlo = np.clip(int(np.round(min(x0,x1))) - 1, 0, W-1) xhi = np.clip(int(np.round(max(x0,x1))) - 1, 0, W-1) ylo = np.clip(int(np.round(min(y0,y1))) - 1, 0, H-1) yhi = np.clip(int(np.round(max(y0,y1))) - 1, 0, H-1) nexp[ylo:yhi+1, xlo:xhi+1] += 1 plt.clf() plt.imshow(nexp, interpolation='nearest', origin='lower', vmin=-0.5, vmax=hi+0.5, cmap=cmap, extent=extent) plt.colorbar(ticks=np.arange(hi+1)) ps.savefig() O = fits_table('obstatus/decam-tiles_obstatus.fits') O.cut(np.hypot(O.ra - ra, O.dec - dec) < 2.5) for p in [1,2,3]: print('Pass', p, 'exposures:', O.r_expnum[O.get('pass') == p]) O.cut(O.get('pass') == 2) print(len(O), 'pass 2 nearby') d = np.hypot(O.ra - ra, O.dec - dec) print('Dists:', d) I = np.flatnonzero(d < 0.5) assert(len(I) == 1) ocenter = O[I[0]] print('Center expnum', ocenter.r_expnum) I = np.flatnonzero(d >= 0.5) O.cut(I) #center = ccds[ccds.expnum == ocenter.r_expnum] #p2 = ccds[ccds. ok,xc,yc = wcs.radec2pixelxy(ocenter.ra, ocenter.dec) xx,yy = np.meshgrid(np.arange(W)+1, np.arange(H)+1) c_d2 = (xc - xx)**2 + (yc - yy)**2 best = np.ones((H,W), bool) for o in O: ok,x,y = wcs.radec2pixelxy(o.ra, o.dec) d2 = (x - xx)**2 + (y - yy)**2 best[d2 < c_d2] = False del d2 del c_d2,xx,yy # plt.clf() # plt.imshow(best, interpolation='nearest', origin='lower', cmap='gray', # vmin=0, vmax=1) # ps.savefig() plt.clf() plt.imshow(nexp * best, interpolation='nearest', origin='lower', vmin=-0.5, vmax=hi+0.5, cmap=cmap, extent=extent) plt.colorbar(ticks=np.arange(hi+1)) ps.savefig() plt.clf() n,b,p = plt.hist(np.clip(nexp[best], 0, hi), range=(-0.5,hi+0.5), bins=hi+1) plt.xlim(-0.5, hi+0.5) ps.savefig() print('b', b) print('n', n) print('fracs', np.array(n) / np.sum(n)) print('pcts', ', '.join(['%.1f' % f for f in 100. * np.array(n)/np.sum(n)]))
def main(): ps = PlotSequence('cov') survey = LegacySurveyData() ra, dec = 242.0, 10.2 fn = 'coverage-ccds.fits' if not os.path.exists(fn): ccds = survey.get_ccds() ccds.cut(ccds.filter == 'r') ccds.cut(ccds.propid == '2014B-0404') ccds.cut(np.hypot(ccds.ra_bore - ra, ccds.dec_bore - dec) < 2.5) print(np.unique(ccds.expnum), 'unique exposures') print('propids', np.unique(ccds.propid)) ccds.writeto(fn) else: ccds = fits_table(fn) plt.clf() for e in np.unique(ccds.expnum): I = np.flatnonzero(ccds.expnum == e) plt.plot(ccds.ra[I], ccds.dec[I], '.') ps.savefig() degw = 3.0 pixscale = 10. W = degw * 3600 / 10. H = W hi = 6 cmap = cmap_discretize('jet', hi + 1) wcs = Tan(ra, dec, W / 2. + 0.5, H / 2. + 0.5, -pixscale / 3600., 0., 0., pixscale / 3600., float(W), float(H)) r0, d0 = wcs.pixelxy2radec(1, 1) r1, d1 = wcs.pixelxy2radec(W, H) extent = [min(r0, r1), max(r0, r1), min(d0, d1), max(d0, d1)] for expnums in [ [348666], [348666, 348710, 348686], [348659, 348667, 348658, 348666, 348665, 348669, 348668], None, [ 348683, 348687, 347333, 348686, 348685, 348692, 348694, 348659, 348667, 348658, 348666, 348665, 348669, 348668, 348707, 348709, 348708, 348710, 348711, 348716, 348717 ], ]: nexp = np.zeros((H, W), np.uint8) for ccd in ccds: if expnums is not None and not ccd.expnum in expnums: continue ccdwcs = survey.get_approx_wcs(ccd) r, d = ccdwcs.pixelxy2radec(1, 1) ok, x0, y0 = wcs.radec2pixelxy(r, d) r, d = ccdwcs.pixelxy2radec(ccd.width, ccd.height) ok, x1, y1 = wcs.radec2pixelxy(r, d) xlo = np.clip(int(np.round(min(x0, x1))) - 1, 0, W - 1) xhi = np.clip(int(np.round(max(x0, x1))) - 1, 0, W - 1) ylo = np.clip(int(np.round(min(y0, y1))) - 1, 0, H - 1) yhi = np.clip(int(np.round(max(y0, y1))) - 1, 0, H - 1) nexp[ylo:yhi + 1, xlo:xhi + 1] += 1 plt.clf() plt.imshow(nexp, interpolation='nearest', origin='lower', vmin=-0.5, vmax=hi + 0.5, cmap=cmap, extent=extent) plt.colorbar(ticks=np.arange(hi + 1)) ps.savefig() O = fits_table('obstatus/decam-tiles_obstatus.fits') O.cut(np.hypot(O.ra - ra, O.dec - dec) < 2.5) for p in [1, 2, 3]: print('Pass', p, 'exposures:', O.r_expnum[O.get('pass') == p]) O.cut(O.get('pass') == 2) print(len(O), 'pass 2 nearby') d = np.hypot(O.ra - ra, O.dec - dec) print('Dists:', d) I = np.flatnonzero(d < 0.5) assert (len(I) == 1) ocenter = O[I[0]] print('Center expnum', ocenter.r_expnum) I = np.flatnonzero(d >= 0.5) O.cut(I) #center = ccds[ccds.expnum == ocenter.r_expnum] #p2 = ccds[ccds. ok, xc, yc = wcs.radec2pixelxy(ocenter.ra, ocenter.dec) xx, yy = np.meshgrid(np.arange(W) + 1, np.arange(H) + 1) c_d2 = (xc - xx)**2 + (yc - yy)**2 best = np.ones((H, W), bool) for o in O: ok, x, y = wcs.radec2pixelxy(o.ra, o.dec) d2 = (x - xx)**2 + (y - yy)**2 best[d2 < c_d2] = False del d2 del c_d2, xx, yy # plt.clf() # plt.imshow(best, interpolation='nearest', origin='lower', cmap='gray', # vmin=0, vmax=1) # ps.savefig() plt.clf() plt.imshow(nexp * best, interpolation='nearest', origin='lower', vmin=-0.5, vmax=hi + 0.5, cmap=cmap, extent=extent) plt.colorbar(ticks=np.arange(hi + 1)) ps.savefig() plt.clf() n, b, p = plt.hist(np.clip(nexp[best], 0, hi), range=(-0.5, hi + 0.5), bins=hi + 1) plt.xlim(-0.5, hi + 0.5) ps.savefig() print('b', b) print('n', n) print('fracs', np.array(n) / np.sum(n)) print('pcts', ', '.join(['%.1f' % f for f in 100. * np.array(n) / np.sum(n)]))
def one_brick(X): (ibrick, brick) = X bands = ['g', 'r', 'z'] print('Brick', brick.brickname) wcs = wcs_for_brick(brick, W=94, H=94, pixscale=10.) BH, BW = wcs.shape targetrd = np.array([ wcs.pixelxy2radec(x, y) for x, y in [(1, 1), (BW, 1), (BW, BH), (1, BH), (1, 1)] ]) survey = LegacySurveyData() C = survey.ccds_touching_wcs(wcs) if C is None: print('No CCDs touching brick') return None I = np.flatnonzero(C.ccd_cuts == 0) if len(I) == 0: print('No good CCDs touching brick') return None C.cut(I) print(len(C), 'CCDs touching brick') depths = {} for band in bands: d = np.zeros((BH, BW), np.float32) depths[band] = d npix = dict([(band, 0) for band in bands]) nexps = dict([(band, 0) for band in bands]) # survey.get_approx_wcs(ccd) for ccd in C: #im = survey.get_image_object(ccd) awcs = survey.get_approx_wcs(ccd) imh, imw = ccd.height, ccd.width x0, y0 = 0, 0 x1 = x0 + imw y1 = y0 + imh imgpoly = [(1, 1), (1, imh), (imw, imh), (imw, 1)] ok, tx, ty = awcs.radec2pixelxy(targetrd[:-1, 0], targetrd[:-1, 1]) tpoly = list(zip(tx, ty)) clip = clip_polygon(imgpoly, tpoly) clip = np.array(clip) if len(clip) == 0: continue x0, y0 = np.floor(clip.min(axis=0)).astype(int) x1, y1 = np.ceil(clip.max(axis=0)).astype(int) #slc = slice(y0,y1+1), slice(x0,x1+1) awcs = awcs.get_subimage(x0, y0, x1 - x0, y1 - y0) ah, aw = awcs.shape #print('Image', ccd.expnum, ccd.ccdname, ccd.filter, 'overlap', x0,x1, y0,y1, '->', (1+x1-x0),'x',(1+y1-y0)) # Find bbox in brick space r, d = awcs.pixelxy2radec([1, 1, aw, aw], [1, ah, ah, 1]) ok, bx, by = wcs.radec2pixelxy(r, d) bx0 = np.clip(np.round(bx.min()).astype(int) - 1, 0, BW - 1) bx1 = np.clip(np.round(bx.max()).astype(int) - 1, 0, BW - 1) by0 = np.clip(np.round(by.min()).astype(int) - 1, 0, BH - 1) by1 = np.clip(np.round(by.max()).astype(int) - 1, 0, BH - 1) #print('Brick', bx0,bx1,by0,by1) band = ccd.filter[0] assert (band in bands) ccdzpt = ccd.ccdzpt + 2.5 * np.log10(ccd.exptime) psf_sigma = ccd.fwhm / 2.35 psfnorm = 1. / (2. * np.sqrt(np.pi) * psf_sigma) orig_zpscale = zpscale = NanoMaggies.zeropointToScale(ccdzpt) sig1 = ccd.sig1 / orig_zpscale detsig1 = sig1 / psfnorm # print('Image', ccd.expnum, ccd.ccdname, ccd.filter, # 'PSF depth', -2.5 * (np.log10(5.*detsig1) - 9), 'exptime', ccd.exptime, # 'sig1', ccd.sig1, 'zpt', ccd.ccdzpt, 'fwhm', ccd.fwhm, # 'filename', ccd.image_filename.strip()) depths[band][by0:by1 + 1, bx0:bx1 + 1] += (1. / detsig1**2) npix[band] += (y1 + 1 - y0) * (x1 + 1 - x0) nexps[band] += 1 for band in bands: det = np.median(depths[band]) # compute stats for 5-sigma detection with np.errstate(divide='ignore'): depth = 5. / np.sqrt(det) # that's flux in nanomaggies -- convert to mag depth = -2.5 * (np.log10(depth) - 9) if not np.isfinite(depth): depth = 0. depths[band] = depth #bricks.get('psfdepth_' + band)[ibrick] = depth print(brick.brickname, 'median PSF depth', band, ':', depth, 'npix', npix[band], 'nexp', nexps[band]) #'npix', bricks.get('npix_'+band)[ibrick], #'nexp', bricks.get('nexp_'+band)[ibrick]) return (npix, nexps, depths)