Example #1
0
    wcs = Tan(*[
        float(x) for x in [
            194.954, 27.980, (W + 1) / 2., (H + 1) /
            2., -pixscale, 0, 0, pixscale, W, H
        ]
    ])
    gri = map_sdss(None,
                   1,
                   1,
                   1,
                   1,
                   get_images=True,
                   wcs=wcs,
                   forcescale=0,
                   bestOnly=True)
    #print 'Got', gri
    g, r, i = gri
    print('g', g.shape)

    hdr = fitsio.FITSHDR()
    wcs.add_to_header(hdr)

    fitsio.write('coma-g.fits', g, header=hdr, clobber=True)
    fitsio.write('coma-r.fits', r, header=hdr, clobber=True)
    fitsio.write('coma-i.fits', i, header=hdr, clobber=True)

    bands = 'gri'
    rgb = sdss_rgb(gri, bands)
    save_jpeg('coma.jpg', rgb)
Example #2
0
def run_one(X):
    k, sb, bricks, version = X
    print(k, sb.brickname)
    outfn = 'skybricks/sky-%s.fits.fz' % sb.brickname
    if os.path.exists(outfn):
        return True

    I = np.flatnonzero((bricks.ra2 > sb.ra1) * (bricks.ra1 < sb.ra2) *
                       (bricks.dec2 > sb.dec1) * (bricks.dec1 < sb.dec2))
    if len(I) == 0:
        print('No bricks overlap')
        return False

    # 3600 + 1% margin on each side
    w, h = 3672, 3672

    if sb.dec >= 78.:
        # In order to have fully-overlapping tiles at high Decs, we
        # need larger maps.  DR9 reaches a max skytile of Dec=+85,
        # where the required size is 3724.  Add a little margin.
        w, h = 3744, 3744
    binning = 4
    # pixscale
    cd = 1. / 3600.

    fullw, fullh = w * binning, h * binning
    fullcd = cd / binning

    # There are really three states: no coverage, blob, no blob.
    # Since blobs outside each brick's unique area do not appear in
    # the files, we start skyblobs as zero, but also track the
    # coverage so we can set !coverage to blob at the end.

    skyblobs = np.zeros((fullh, fullw), bool)
    covered = np.zeros((fullh, fullw), bool)

    skywcs = Tan(sb.ra, sb.dec, (fullw + 1) / 2., (fullh + 1) / 2., -fullcd,
                 0., 0., fullcd, float(fullw), float(fullh))

    for i in I:
        brick = bricks[i]
        #print('Blob', brickname)
        #fn = 'cosmo/data/legacysurvey/dr9/%s/metrics/%s/blobs-%s.fits.gz' % (brick.hemi, brick.brickname[:3], brick.brickname)
        #fn = 'dr9-south-blobs/blobs-%s.fits.gz' % (brick.brickname)
        fn = '/global/cfs/cdirs/cosmo/data/legacysurvey/dr9/%s/metrics/%s/blobs-%s.fits.gz' % (
            brick.hemi, brick.brickname[:3], brick.brickname)

        blobs, hdr = fitsio.read(fn, header=True)
        wcs = Tan(hdr)
        blobs = (blobs > -1)
        try:
            Yo, Xo, Yi, Xi, _ = resample_with_wcs(skywcs, wcs)
        except NoOverlapError:
            continue

        skyblobs[Yo, Xo] |= blobs[Yi, Xi]

        # coverage: nexp > 0 in any band
        for band in ['g', 'r', 'z']:
            fn = (
                '/global/cfs/cdirs/cosmo/data/legacysurvey/dr9/%s/coadd/%s/%s/legacysurvey-%s-nexp-%s.fits.fz'
                % (brick.hemi, brick.brickname[:3], brick.brickname,
                   brick.brickname, band))
            if not os.path.exists(fn):
                continue
            nexp = fitsio.read(fn)
            covered[Yo, Xo] |= (nexp[Yi, Xi] > 0)

    if not np.any(covered):
        print('No coverage')
        return False
    # No coverage = equivalent to there being a blob there (ie,
    # conservative for placing sky fibers)
    skyblobs[covered == False] = True

    # bin down, counting how many times 'skyblobs' is set
    subcount = np.zeros((h, w), np.uint8)
    for i in range(binning):
        for j in range(binning):
            subcount += skyblobs[i::binning, j::binning]
    subwcs = Tan(sb.ra, sb.dec, (w + 1) / 2., (h + 1) / 2., -cd, 0., 0., cd,
                 float(w), float(h))
    hdr = fitsio.FITSHDR()
    hdr.add_record(
        dict(name='SB_VER',
             value=version,
             comment='desi-sky-locations git version'))
    subwcs.add_to_header(hdr)
    fitsio.write(outfn,
                 subcount,
                 header=hdr,
                 clobber=True,
                 compress='GZIP',
                 tile_dims=(256, 256))
    print('Wrote', outfn)
    return True