Beispiel #1
0
def read_data(imfn,
              ivarfn,
              dqfn,
              extname,
              badpixmask=badpixmaskfn,
              maskdiffuse=True,
              corrects7=True):
    import warnings
    with warnings.catch_warnings(record=True) as wlist:
        warnings.simplefilter('always')
        imh = fits.getheader(imfn)
        imdei = fits.getdata(imfn, extname=extname).copy()
        imdew = fits.getdata(ivarfn, extname=extname).copy()
        imded = fits.getdata(dqfn, extname=extname).copy()
    # suppress endless nonstandard keyword warnings on read
    for warning in wlist:
        if 'following header keyword' in str(warning.message):
            continue
        else:
            print(warning)
    # support old versions of CP with different DQ meanings
    from distutils.version import LooseVersion
    if LooseVersion(imh['PLVER']) < LooseVersion('V3.5'):
        imdedo = imded
        imded = numpy.zeros_like(imded)
        imded[(imdedo & 2**7) != 0] = 7
        imded[(imdedo & 2**4) != 0] = 5
        imded[(imdedo & 2**6) != 0] = 4
        imded[(imdedo & 2**1) != 0] = 3
        imded[(imdedo & 2**0) != 0] = 1
        # values 2, 8 don't seem to exist in early CP images;
        # likewise bits 2, 3, 5 don't really have meaning in recent CP images
        # (interpolated, unused, unused)
    imded = 2**imded
    # flag 7 does not seem to indicate problems with the pixels.
    mzerowt = (((imded & ~(2**0 | 2**7)) != 0) | (imdew < 0.)
               | ~numpy.isfinite(imdew))
    if badpixmask is not None:
        badmask = fits.getdata(badpixmask, extname=extname)
        imded |= ((badmask != 0) * extrabits['badpix'])
        mzerowt = mzerowt | (badmask != 0)
    imdew[mzerowt] = 0.
    imdew[:] = numpy.sqrt(imdew)
    if maskdiffuse:
        import nebulosity_mask
        nebmod = getattr(read_data, 'nebmod', None)
        if nebmod is None:
            modfn = os.path.join(os.environ['DECAM_DIR'], 'data', 'nebmaskmod',
                                 'weights', '27th_try')
            nebmod = nebulosity_mask.load_model(modfn)
            read_data.nebmod = nebmod
        nebmask = nebulosity_mask.gen_mask(nebmod, imdei) == 0
        if numpy.any(nebmask):
            imded |= (nebmask * extrabits['diffuse'])
            print(
                'Masking nebulosity, %5.2f' %
                (numpy.sum(nebmask) / 1. / numpy.sum(numpy.isfinite(nebmask))))
    if corrects7 and (extname == 'S7'):
        imdei = correct_sky_offset(imdei, weight=imdew)
        half = imded.shape[1] // 2
        imded[:, half:] |= extrabits['s7unstable']
    return imdei, imdew, imded
Beispiel #2
0
                                      uncompressed=args.uncompressed)
    if len(args.startsky) > 0:
        startsky = fits.getdata(args.startsky, 'SKY')
    flag_orig = fits.getdata(
        wise_filename(basedir,
                      coadd_id,
                      band,
                      'msk',
                      uncompressed=args.uncompressed))

    crowdsource.psfvalsharpcut.fac = 0.5
    if args.masknebulosity:
        import nebulosity_mask
        nebfn = os.path.join(os.environ['WISE_DIR'], 'dat', 'nebnet',
                             'weights1', '1st_try')
        nebmod = nebulosity_mask.load_model(nebfn)
        nebmask = nebulosity_mask.gen_mask_wise(nebmod, im) == 2
        if numpy.any(nebmask):
            flag |= nebmask * extrabits['nebulosity']
            flag |= nebmask * crowdsource.sharp_maskbit
            print(
                'Masking nebulosity, %5.2f' %
                (numpy.sum(nebmask) / 1. / numpy.sum(numpy.isfinite(nebmask))))

    psf = wise_psf_grid(band, coadd_id, basedir)
    if len(args.startpsf) > 0:
        startpsf = fits.getdata(args.startpsf, 'PSF').astype('f4')
        # there can be some endianness issues; astype('f4') converts to native
        modpsf = psf(1024, 1024, stampsz=psf.stamp.shape[-1])
        resid = startpsf - modpsf
        # need not sum to zero.
Beispiel #3
0
def read_data(imfn,
              ivarfn,
              dqfn,
              extname,
              badpixmask=None,
              maskdiffuse=True,
              corrects7=True,
              wcutoff=0.0,
              contmask=False,
              maskgal=False,
              verbose=False):
    import warnings
    with warnings.catch_warnings(record=True) as wlist:
        warnings.simplefilter('always')
        imh = fits.getheader(imfn)
        hdr = fits.getheader(imfn, extname=extname)
        imdei = fits.getdata(imfn, extname=extname).copy()
        imdew = fits.getdata(ivarfn, extname=extname).copy()
        imded = fits.getdata(dqfn, extname=extname).copy()
    # suppress endless nonstandard keyword warnings on read
    for warning in wlist:
        if 'following header keyword' in str(warning.message):
            continue
        else:
            print(warning)
    # support old versions of CP with different DQ meanings
    from distutils.version import LooseVersion
    if LooseVersion(imh['PLVER']) < LooseVersion('V3.5'):
        imdedo = imded
        imded = numpy.zeros_like(imded)
        imded[(imdedo & 2**7) != 0] = 7
        imded[(imdedo & 2**4) != 0] = 5
        imded[(imdedo & 2**6) != 0] = 4
        imded[(imdedo & 2**1) != 0] = 3
        imded[(imdedo & 2**0) != 0] = 1
        # values 2, 8 don't seem to exist in early CP images;
        # likewise bits 2, 3, 5 don't really have meaning in recent CP images
        # (interpolated, unused, unused)
    imded = 2**imded
    # flag 7 does not seem to indicate problems with the pixels.
    mzerowt = (((imded & ~(2**0 | 2**7)) != 0) | (imdew < wcutoff)
               | ~numpy.isfinite(imdew))
    if badpixmask is None:
        badpixmask = os.path.join(os.environ['DECAM_DIR'], 'data',
                                  'badpixmasksefs_comp.fits')
    if "I" in extname:
        extidx = extname.index("I")
        bextname = extname[:extidx]
    else:
        bextname = extname
    badmask = fits.getdata(badpixmask, extname=bextname)
    imded |= ((badmask != 0) * extrabits['badpix'])
    mzerowt = mzerowt | (badmask != 0)
    imdew[mzerowt] = 0.
    imdew[:] = numpy.sqrt(imdew)
    if corrects7 and (extname[:2] == 'S7'):
        imdei = correct_sky_offset(imdei, weight=imdew)
        half = imded.shape[1] // 2
        imded[:, half:] |= extrabits['s7unstable']
    if maskgal:
        if imh["WCSCAL"] == "Successful":
            import galaxy_mask
            leda = getattr(read_data, 'leda', None)
            if leda is None:
                leda = galaxy_mask.read_leda_decaps()
                read_data.leda = leda
            gmsk = galaxy_mask.galaxy_mask(hdr, leda)
            if numpy.any(gmsk):
                imded |= (gmsk * extrabits['galaxy'])
                imded |= (gmsk * crowdsource_base.nodeblend_maskbit)
        else:
            if verbose:
                print("WCSCAL Unsucessful, Skipping galaxy masking...")

    if maskdiffuse:
        import nebulosity_mask
        nebmod = getattr(read_data, 'nebmod', None)
        if nebmod is None:
            modfn = os.path.join(os.environ['DECAM_DIR'], 'data', 'nebmaskmod',
                                 'weights', '27th_try')
            nebmod = nebulosity_mask.load_model(modfn)
            read_data.nebmod = nebmod
        if not contmask:
            nebmask = nebulosity_mask.gen_mask(nebmod, imdei) == 0
            nebprob = None
        else:
            nebmask, nebprob = nebulosity_mask.gen_prob(nebmod,
                                                        imdei,
                                                        return_prob=True)

        if numpy.any(nebmask):
            imded |= (nebmask * extrabits['diffuse'])
            imded |= (nebmask * (crowdsource_base.nodeblend_maskbit
                                 | crowdsource_base.sharp_maskbit))
            if verbose:
                print('Masking nebulosity fraction, %5.2f' %
                      (numpy.sum(nebmask) / 1. /
                       numpy.sum(numpy.isfinite(nebmask))))
    else:
        nebprob = None

    return imdei, imdew, imded, nebprob