Ejemplo n.º 1
0
def stage2(cat=None,
           variances=None,
           T=None,
           bands=None,
           ps=None,
           targetwcs=None,
           **kwargs):
    print('kwargs:', kwargs.keys())
    #print 'variances:', variances

    from desi_common import prepare_fits_catalog
    TT = T.copy()
    hdr = None
    fs = None
    T2, hdr = prepare_fits_catalog(cat, 1. / np.array(variances), TT, hdr,
                                   bands, fs)
    T2.about()
    T2.writeto('cfht.fits')

    ccmap = dict(g='g', r='r', i='m')

    bandlist = [b for b in bands]
    scat, S = get_sdss_sources(bandlist, targetwcs)
    S.about()
    I, J, d = match_radec(T2.ra, T2.dec, S.ra, S.dec, 1. / 3600.)
    M = fits_table()
    M.ra = S.ra[J]
    M.dec = S.dec[J]
    M.cfhtI = I
    for band in bands:
        mag = T2.get('decam_%s_mag' % band)[I]
        sflux = np.array([s.getBrightness().getBand(band) for s in scat])[J]
        smag = NanoMaggies.nanomaggiesToMag(sflux)
        M.set('mag_%s' % band, mag)
        M.set('smag_%s' % band, smag)
        cc = ccmap[band]
        plt.clf()
        plt.subplot(2, 1, 1)
        plt.plot(smag, mag, '.', color=cc, alpha=0.5)
        lo, hi = 16, 24
        plt.plot([lo, hi], [lo, hi], 'k-')
        plt.xlabel('SDSS mag')
        plt.ylabel('CFHT mag')
        plt.axis([lo, hi, lo, hi])

        plt.subplot(2, 1, 2)
        plt.plot(smag, mag - smag, '.', color=cc, alpha=0.5)
        lo, hi = 16, 24
        plt.plot([lo, hi], [0, 0], 'k-')
        plt.xlabel('SDSS mag')
        plt.ylabel('CFHT - SDSS mag')
        plt.axis([lo, hi, -1, 1])

        plt.suptitle('%s band' % band)
        ps.savefig()
    M.writeto('cfht-matched.fits')

    plt.clf()
    lp, lt = [], []
    for band in bands:
        sn = T2.get('decam_%s_nanomaggies' % band) * np.sqrt(
            T2.get('decam_%s_nanomaggies_invvar' % band))
        #mag = T2.get('decam_%s_mag_corr' % band)
        mag = T2.get('decam_%s_mag' % band)
        print('band', band)
        print('Mags:', mag)
        print('SN:', sn)
        cc = ccmap[band]
        p = plt.semilogy(mag, sn, '.', color=cc, alpha=0.5)
        lp.append(p[0])
        lt.append('%s band' % band)
    plt.xlabel('mag')
    plt.ylabel('Flux Signal-to-Noise')
    tt = [1, 2, 3, 4, 5, 10, 20, 30, 40, 50]
    plt.yticks(tt, ['%i' % t for t in tt])
    plt.axhline(5., color='k')
    #plt.axis([21, 26, 1, 20])
    plt.legend(lp, lt, loc='upper right')
    plt.title('CFHT depth')
    ps.savefig()

    # ['tims', 'cons', 'pixscale', 'H', 'coimgs', 'detmaps', 'W', 'brick', 'detivs', 'targetrd']

    return dict(T2=T2,
                M=M,
                tims=None,
                detmaps=None,
                detivs=None,
                cons=None,
                coimgs=None)
Ejemplo n.º 2
0
    TT = T.copy()
    for k in ['itx', 'ity', 'index']:
        TT.delete_column(k)
    for col in TT.get_columns():
        if not col in ['tx', 'ty', 'blob']:
            TT.rename(col, 'sdss_%s' % col)

    TT.brickid = np.zeros(len(TT), np.int32) + brickid
    TT.objid = np.arange(len(TT)).astype(np.int32)

    invvars = None
    hdr = None
    fs = None

    cat.thawAllRecursive()
    T2, hdr = prepare_fits_catalog(cat, invvars, TT, hdr, bands, fs)
    # Unpack shape columns
    T2.shapeExp_r = T2.shapeExp[:, 0]
    T2.shapeExp_e1 = T2.shapeExp[:, 1]
    T2.shapeExp_e2 = T2.shapeExp[:, 2]
    T2.shapeDev_r = T2.shapeExp[:, 0]
    T2.shapeDev_e1 = T2.shapeExp[:, 1]
    T2.shapeDev_e2 = T2.shapeExp[:, 2]
    T2.shapeExp_r_ivar = T2.shapeExp_ivar[:, 0]
    T2.shapeExp_e1_ivar = T2.shapeExp_ivar[:, 1]
    T2.shapeExp_e2_ivar = T2.shapeExp_ivar[:, 2]
    T2.shapeDev_r_ivar = T2.shapeExp_ivar[:, 0]
    T2.shapeDev_e1_ivar = T2.shapeExp_ivar[:, 1]
    T2.shapeDev_e2_ivar = T2.shapeExp_ivar[:, 2]

    T2.writeto(opt.output)
Ejemplo n.º 3
0
def main():
    """Main program.
    """
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-b',
                        '--brick',
                        type=int,
                        metavar='BRICK',
                        help='Brick ID to run: default %(default)s',
                        default=377306)
    parser.add_argument('-s',
                        '--sed-matched',
                        action='store_true',
                        help='Run SED-matched filter?')
    parser.add_argument('-B',
                        '--bands',
                        default='grz',
                        help='Bands to retrieve')
    parser.add_argument('-o',
                        '--output',
                        metavar='FILE',
                        help='Output filename for catalog',
                        default='initial-cat.fits')
    parser.add_argument('-t', '--threads', type=int, help='Run multi-threaded')
    parser.add_argument('-W',
                        '--width',
                        type=int,
                        dest='W',
                        default=3600,
                        metavar='PIXELS',
                        help='Target image width (default %(default)s)')
    parser.add_argument('-H',
                        '--height',
                        type=int,
                        dest='H',
                        default=3600,
                        metavar='PIXELS',
                        help='Target image height (default %(default)s)')

    if not (('BOSS_PHOTOOBJ' in os.environ) and
            ('PHOTO_RESOLVE' in os.environ)):
        print(
            '''$BOSS_PHOTOOBJ and $PHOTO_RESOLVE not set -- on NERSC, you can do:
export BOSS_PHOTOOBJ=/project/projectdirs/cosmo/data/sdss/pre13/eboss/photoObj.v5b
export PHOTO_RESOLVE=/project/projectdirs/cosmo/data/sdss/pre13/eboss/resolve/2013-07-29
To read SDSS files from the local filesystem rather than downloading them.
''')

    opt = parser.parse_args()
    brickid = opt.brick
    bands = opt.bands
    if opt.threads and opt.threads > 1:
        from astrometry.util.multiproc import multiproc
        mp = multiproc(opt.threads)
    else:
        mp = multiproc()

    ps = None
    plots = False

    decals = Decals()
    brick = decals.get_brick(brickid)
    print('Chosen brick:')
    brick.about()
    targetwcs = wcs_for_brick(brick, W=opt.W, H=opt.H)
    W, H = targetwcs.get_width(), targetwcs.get_height()

    # Read SDSS sources
    cat, T = get_sdss_sources(bands, targetwcs)

    if opt.sed_matched:
        # Read images
        tims = decals.tims_touching_wcs(targetwcs,
                                        mp,
                                        mock_psf=True,
                                        bands=bands)
        print('Rendering detection maps...')
        detmaps, detivs = detection_maps(tims, targetwcs, bands, mp)

        SEDs = sed_matched_filters(bands)
        Tnew, newcat, nil = run_sed_matched_filters(SEDs, bands, detmaps,
                                                    detivs, (T.itx, T.ity),
                                                    targetwcs)
        T = merge_tables([T, Tnew], columns='fillzero')
        cat.extend(newcat)

    from desi_common import prepare_fits_catalog
    TT = T.copy()
    for k in ['itx', 'ity', 'index']:
        TT.delete_column(k)
    for col in TT.get_columns():
        if not col in ['tx', 'ty', 'blob']:
            TT.rename(col, 'sdss_%s' % col)

    TT.brickid = np.zeros(len(TT), np.int32) + brickid
    TT.objid = np.arange(len(TT)).astype(np.int32)

    invvars = None
    hdr = None
    fs = None

    cat.thawAllRecursive()
    T2, hdr = prepare_fits_catalog(cat, invvars, TT, hdr, bands, fs)
    # Unpack shape columns
    T2.shapeExp_r = T2.shapeExp[:, 0]
    T2.shapeExp_e1 = T2.shapeExp[:, 1]
    T2.shapeExp_e2 = T2.shapeExp[:, 2]
    T2.shapeDev_r = T2.shapeExp[:, 0]
    T2.shapeDev_e1 = T2.shapeExp[:, 1]
    T2.shapeDev_e2 = T2.shapeExp[:, 2]
    T2.shapeExp_r_ivar = T2.shapeExp_ivar[:, 0]
    T2.shapeExp_e1_ivar = T2.shapeExp_ivar[:, 1]
    T2.shapeExp_e2_ivar = T2.shapeExp_ivar[:, 2]
    T2.shapeDev_r_ivar = T2.shapeExp_ivar[:, 0]
    T2.shapeDev_e1_ivar = T2.shapeExp_ivar[:, 1]
    T2.shapeDev_e2_ivar = T2.shapeExp_ivar[:, 2]

    T2.writeto(opt.output)
    print('Wrote', opt.output)
    return 0
Ejemplo n.º 4
0
    TT = T.copy()
    for k in ["itx", "ity", "index"]:
        TT.delete_column(k)
    for col in TT.get_columns():
        if not col in ["tx", "ty", "blob"]:
            TT.rename(col, "sdss_%s" % col)

    TT.brickid = np.zeros(len(TT), np.int32) + brickid
    TT.objid = np.arange(len(TT)).astype(np.int32)

    invvars = None
    hdr = None
    fs = None

    cat.thawAllRecursive()
    T2, hdr = prepare_fits_catalog(cat, invvars, TT, hdr, bands, fs)
    # Unpack shape columns
    T2.shapeExp_r = T2.shapeExp[:, 0]
    T2.shapeExp_e1 = T2.shapeExp[:, 1]
    T2.shapeExp_e2 = T2.shapeExp[:, 2]
    T2.shapeDev_r = T2.shapeExp[:, 0]
    T2.shapeDev_e1 = T2.shapeExp[:, 1]
    T2.shapeDev_e2 = T2.shapeExp[:, 2]
    T2.shapeExp_r_ivar = T2.shapeExp_ivar[:, 0]
    T2.shapeExp_e1_ivar = T2.shapeExp_ivar[:, 1]
    T2.shapeExp_e2_ivar = T2.shapeExp_ivar[:, 2]
    T2.shapeDev_r_ivar = T2.shapeExp_ivar[:, 0]
    T2.shapeDev_e1_ivar = T2.shapeExp_ivar[:, 1]
    T2.shapeDev_e2_ivar = T2.shapeExp_ivar[:, 2]

    T2.writeto(opt.output)
Ejemplo n.º 5
0
def stage2(cat=None, variances=None, T=None, bands=None, ps=None,
           targetwcs=None, **kwargs):
    print 'kwargs:', kwargs.keys()
    #print 'variances:', variances

    from desi_common import prepare_fits_catalog
    TT = T.copy()
    hdr = None
    fs = None
    T2,hdr = prepare_fits_catalog(cat, 1./np.array(variances), TT, hdr, bands, fs)
    T2.about()
    T2.writeto('cfht.fits')
    
    ccmap = dict(g='g', r='r', i='m')

    bandlist = [b for b in bands]
    scat,S = get_sdss_sources(bandlist, targetwcs)
    S.about()
    I,J,d = match_radec(T2.ra, T2.dec, S.ra, S.dec, 1./3600.)
    M = fits_table()
    M.ra = S.ra[J]
    M.dec = S.dec[J]
    M.cfhtI = I
    for band in bands:
        mag = T2.get('decam_%s_mag' % band)[I]
        sflux = np.array([s.getBrightness().getBand(band) for s in scat])[J]
        smag = NanoMaggies.nanomaggiesToMag(sflux)
        M.set('mag_%s' % band, mag)
        M.set('smag_%s' % band, smag)
        cc = ccmap[band]
        plt.clf()
        plt.subplot(2,1,1)
        plt.plot(smag, mag, '.', color=cc, alpha=0.5)
        lo,hi = 16,24
        plt.plot([lo,hi],[lo,hi], 'k-')
        plt.xlabel('SDSS mag')
        plt.ylabel('CFHT mag')
        plt.axis([lo,hi,lo,hi])

        plt.subplot(2,1,2)
        plt.plot(smag, mag - smag, '.', color=cc, alpha=0.5)
        lo,hi = 16,24
        plt.plot([lo,hi],[0, 0], 'k-')
        plt.xlabel('SDSS mag')
        plt.ylabel('CFHT - SDSS mag')
        plt.axis([lo,hi,-1,1])

        plt.suptitle('%s band' % band)
        ps.savefig()
    M.writeto('cfht-matched.fits')
        
    plt.clf()
    lp,lt = [],[]
    for band in bands:
        sn = T2.get('decam_%s_nanomaggies' % band) * np.sqrt(T2.get('decam_%s_nanomaggies_invvar' % band))
        #mag = T2.get('decam_%s_mag_corr' % band)
        mag = T2.get('decam_%s_mag' % band)
        print 'band', band
        print 'Mags:', mag
        print 'SN:', sn
        cc = ccmap[band]
        p = plt.semilogy(mag, sn, '.', color=cc, alpha=0.5)
        lp.append(p[0])
        lt.append('%s band' % band)
    plt.xlabel('mag')
    plt.ylabel('Flux Signal-to-Noise')
    tt = [1,2,3,4,5,10,20,30,40,50]
    plt.yticks(tt, ['%i' % t for t in tt])
    plt.axhline(5., color='k')
    #plt.axis([21, 26, 1, 20])
    plt.legend(lp, lt, loc='upper right')
    plt.title('CFHT depth')
    ps.savefig()

    # ['tims', 'cons', 'pixscale', 'H', 'coimgs', 'detmaps', 'W', 'brick', 'detivs', 'targetrd']

    return dict(T2=T2, M=M, tims=None, detmaps=None, detivs=None,
                cons=None, coimgs=None)
Ejemplo n.º 6
0
def main():
    """Main program.
    """
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('-b', '--brick', type=int, metavar='BRICK',
        help='Brick ID to run: default %(default)s', default=377306)
    parser.add_argument('-s', '--sed-matched', action='store_true',
                      help='Run SED-matched filter?')
    parser.add_argument('-B', '--bands', default='grz', help='Bands to retrieve')
    parser.add_argument('-o', '--output', metavar='FILE', help='Output filename for catalog',
                      default='initial-cat.fits')
    parser.add_argument('-t', '--threads', type=int, help='Run multi-threaded')
    parser.add_argument('-W', '--width', type=int, dest='W', default=3600,
        metavar='PIXELS', help='Target image width (default %(default)s)')
    parser.add_argument('-H', '--height', type=int, dest='H', default=3600,
        metavar='PIXELS', help='Target image height (default %(default)s)')

    if not (('BOSS_PHOTOOBJ' in os.environ) and ('PHOTO_RESOLVE' in os.environ)):
        print('''$BOSS_PHOTOOBJ and $PHOTO_RESOLVE not set -- on NERSC, you can do:
export BOSS_PHOTOOBJ=/project/projectdirs/cosmo/data/sdss/pre13/eboss/photoObj.v5b
export PHOTO_RESOLVE=/project/projectdirs/cosmo/data/sdss/pre13/eboss/resolve/2013-07-29
To read SDSS files from the local filesystem rather than downloading them.
''')


    opt = parser.parse_args()
    brickid = opt.brick
    bands = opt.bands
    if opt.threads and opt.threads > 1:
        from astrometry.util.multiproc import multiproc
        mp = multiproc(opt.threads)
    else:
        mp = multiproc()

    ps = None
    plots = False

    decals = Decals()
    brick = decals.get_brick(brickid)
    print('Chosen brick:')
    brick.about()
    targetwcs = wcs_for_brick(brick, W=opt.W, H=opt.H)
    W,H = targetwcs.get_width(), targetwcs.get_height()

    # Read SDSS sources
    cat,T = get_sdss_sources(bands, targetwcs)

    if opt.sed_matched:
        # Read images
        tims = decals.tims_touching_wcs(targetwcs, mp, mock_psf=True, bands=bands)
        print('Rendering detection maps...')
        detmaps, detivs = detection_maps(tims, targetwcs, bands, mp)

        SEDs = sed_matched_filters(bands)
        Tnew,newcat,nil = run_sed_matched_filters(SEDs, bands, detmaps, detivs,
                                                  (T.itx,T.ity), targetwcs)
        T = merge_tables([T,Tnew], columns='fillzero')
        cat.extend(newcat)


    from desi_common import prepare_fits_catalog
    TT = T.copy()
    for k in ['itx','ity','index']:
        TT.delete_column(k)
    for col in TT.get_columns():
        if not col in ['tx', 'ty', 'blob']:
            TT.rename(col, 'sdss_%s' % col)

    TT.brickid = np.zeros(len(TT), np.int32) + brickid
    TT.objid   = np.arange(len(TT)).astype(np.int32)

    invvars = None
    hdr = None
    fs = None

    cat.thawAllRecursive()
    T2,hdr = prepare_fits_catalog(cat, invvars, TT, hdr, bands, fs)
    # Unpack shape columns
    T2.shapeExp_r = T2.shapeExp[:,0]
    T2.shapeExp_e1 = T2.shapeExp[:,1]
    T2.shapeExp_e2 = T2.shapeExp[:,2]
    T2.shapeDev_r = T2.shapeExp[:,0]
    T2.shapeDev_e1 = T2.shapeExp[:,1]
    T2.shapeDev_e2 = T2.shapeExp[:,2]
    T2.shapeExp_r_ivar  = T2.shapeExp_ivar[:,0]
    T2.shapeExp_e1_ivar = T2.shapeExp_ivar[:,1]
    T2.shapeExp_e2_ivar = T2.shapeExp_ivar[:,2]
    T2.shapeDev_r_ivar  = T2.shapeExp_ivar[:,0]
    T2.shapeDev_e1_ivar = T2.shapeExp_ivar[:,1]
    T2.shapeDev_e2_ivar = T2.shapeExp_ivar[:,2]

    T2.writeto(opt.output)
    print('Wrote', opt.output)
    return 0