Пример #1
0
    def __init__(self, hdr, bandname=None, scale=1.):
        import numpy as np
        from tractor.brightness import NanoMaggies

        if hdr is not None:
            self.exptime = hdr['EXPTIME']
            self.phot_c = hdr['PHOT_C']
            self.phot_k = hdr['PHOT_K']
            self.airmass = hdr['AIRMASS']
            print('CFHT photometry:', self.exptime, self.phot_c, self.phot_k,
                  self.airmass)

            zpt = (2.5 * np.log10(self.exptime) + self.phot_c + self.phot_k *
                   (self.airmass - 1))
            print('-> zeropoint', zpt)
            scale = NanoMaggies.zeropointToScale(zpt)
            print('-> scale', scale)

        super(CfhtLinearPhotoCal, self).__init__(scale, band=bandname)
Пример #2
0
def main():
    global survey

    init()

    ps = PlotSequence('sky')
    # export LEGACY_SURVEY_DIR=/scratch1/scratchdirs/desiproc/DRs/dr4-bootes/legacypipe-dir/
    #survey = LegacySurveyData()
    survey = get_survey('dr4v2')
    ccds = survey.get_ccds_readonly()
    print(len(ccds), 'CCDs')
    ccds = ccds[ccds.camera == 'mosaic']
    print(len(ccds), 'Mosaic CCDs')
    # plt.clf()
    # plt.hist(ccds.mjd_obs % 1.0, bins=50)
    # plt.xlabel('MJD mod 1')
    # ps.savefig()

    ccds.imjd = np.floor(ccds.mjd_obs).astype(int)

    mjds = np.unique(ccds.imjd)
    print(len(mjds), 'unique MJDs')

    mp = multiproc(nthreads=8, init=init)

    allvals = []
    medmjds = []

    args = []

    for kk, mjd in enumerate(mjds):
        I = np.flatnonzero(ccds.imjd == mjd)
        print('MJD', mjd, ' (%i of %i):' % (kk + 1, len(mjds)), len(I), 'CCDs')
        if len(I) == 0:
            continue

        # pick one near the middle
        #i = I[len(I)/2]
        for i in [I[len(I) / 4], I[len(I) / 2], I[3 * len(I) / 4]]:

            ccd = ccds[i]

            key = dict(expnum=ccd.expnum, ccdname=ccd.ccdname)
            oldvals = key

            vals = cache.find(key)
            print('Got', vals.count(), 'cache hits for', key)
            gotone = False
            for val in vals:
                #if 'median_adu' in val:
                if 'mode_adu' in val:
                    print('cache hit:', val)
                    allvals.append(val)
                    medmjds.append(mjd)
                    gotone = True
                    break
                else:
                    print('partial cache hit:', val)
                    oldvals = val
                    ###!
                    cache.delete_one(val)
            if gotone:
                continue

            print('args: key', key, 'oldvals', oldvals)
            args.append((mjd, key, oldvals, ccd))

            # plt.clf()
            # plt.hist(tim.getImage().ravel(), range=(-0.1, 0.1), bins=50,
            #          histtype='step', color='b')
            # plt.axvline(med, color='b', alpha=0.3, lw=2)
            # plt.axvline(0., color='k', alpha=0.3, lw=2)
            # plt.xlabel('Sky-subtracted pixel values')
            # plt.title('Date ' + ccd.date_obs + ': ' + str(im))
            # ps.savefig()

    if len(args):
        meds = mp.map(read_sky_val, args)
        print('Medians:', meds)
        for (mjd, key, oldvals, ccd), val in zip(args, meds):
            if val is None:
                continue
            allvals.append(val)
            medmjds.append(mjd)

    medians = []
    median_adus = []
    mode_adus = []
    skyadus = []
    keepmjds = []

    for mjd, val in zip(medmjds, allvals):
        madu = val['median_adu']
        if madu is None:
            continue

        if 'median' in val:
            medians.append(val['median'])
        else:
            from tractor.brightness import NanoMaggies
            zpscale = NanoMaggies.zeropointToScale(val['ccdzpt'])
            med = (val['median_adu'] - val['skyadu']) / zpscale
            print('Computed median diff:', med, 'nmgy')
            medians.append(med)

        keepmjds.append(mjd)
        median_adus.append(val['median_adu'])
        mode_adus.append(val['mode_adu'])
        skyadus.append(val['skyadu'])

    medmjds = keepmjds

    median_adus = np.array(median_adus)
    mode_adus = np.array(mode_adus)
    skyadus = np.array(skyadus)
    medmjds = np.array(medmjds)
    medians = np.array(medians)

    plt.clf()
    plt.plot(medmjds, median_adus - skyadus, 'b.')
    plt.xlabel('MJD')
    #plt.ylabel('Image median after sky subtraction (nmgy)')
    plt.ylabel('Image median - SKYADU (ADU)')
    #plt.ylim(-0.03, 0.03)
    #plt.ylim(-10, 10)
    plt.ylim(-1, 1)

    plt.axhline(0, color='k', lw=2, alpha=0.5)
    ps.savefig()

    plt.clf()
    plt.plot(medmjds, mode_adus - skyadus, 'b.')
    plt.xlabel('MJD')
    plt.ylabel('Image mode - SKYADU (ADU)')
    plt.ylim(-1, 1)
    plt.axhline(0, color='k', lw=2, alpha=0.5)
    ps.savefig()

    print('Median pcts:', np.percentile(medians, [0, 2, 50, 98, 100]))
    mlo, mhi = np.percentile(medians, [2, 98])
    I = np.flatnonzero((medians > mlo) * (medians < mhi))

    d0 = np.mean(medmjds)
    dmjd = medmjds[I] - d0
    A = np.zeros((len(dmjd), 2))
    A[:, 0] = 1.
    A[:, 1] = dmjd
    b = np.linalg.lstsq(A, medians[I])[0]
    print('Lstsq:', b)
    offset = b[0]
    slope = b[1]
    xx = np.array([dmjd.min(), dmjd.max()])

    print('Offset', offset)
    print('Slope', slope)

    plt.clf()
    plt.plot(medmjds, medians, 'b.')
    ax = plt.axis()
    plt.plot(xx + d0, offset + slope * xx, 'b-')
    plt.axis(ax)
    plt.xlabel('MJD')
    plt.ylabel('Image median after sky subtraction (nmgy)')
    plt.ylim(-0.03, 0.03)
    plt.axhline(0, color='k', lw=2, alpha=0.5)
    ps.savefig()

    plt.clf()
    plt.plot(median_adus, skyadus, 'b.')
    ax = plt.axis()
    lo = min(ax[0], ax[2])
    hi = max(ax[1], ax[3])
    plt.plot([lo, hi], [lo, hi], 'k-', alpha=0.5)
    plt.xlabel('Median image ADU')
    plt.ylabel('SKYADU')
    plt.axis(ax)
    ps.savefig()

    plt.clf()
    plt.plot(medmjds, skyadus / median_adus, 'b.')
    plt.xlabel('MJD')
    plt.ylim(0.98, 1.02)
    plt.axhline(1.0, color='k', alpha=0.5)
    plt.ylabel('SKYADU / median image ADU')
    ps.savefig()
Пример #3
0
    import argparse
    parser = argparse.ArgumentParser(description='Produce annotated CCDs file by reading CCDs file + calibration products')
    parser.add_argument('--part', action='append', help='CCDs file to read, survey-ccds-X.fits.gz, default: ["decals","nondecals","extra"].  Can be repeated.', default=[])
    parser.add_argument('--threads', type=int, help='Run multi-threaded', default=4)
    opt = parser.parse_args()


    if False:
        #### FIX mistake in DR3 annotated CCDs: sig1
        for part in ['decals', 'nondecals', 'extra']:
            from tractor.brightness import NanoMaggies
            fn = '/global/cscratch1/sd/desiproc/dr3/ccds-annotated-%s.fits.gz' % part
            T = fits_table(fn)
            zpt = T.ccdzpt + 2.5 * np.log10(T.exptime)
            print('Median zpt:', np.median(zpt))
            zpscale = NanoMaggies.zeropointToScale(zpt)
            print('Median zpscale:', np.median(zpscale))
    
            print('Zpscale limits:', zpscale.min(), zpscale.max())
            print('Non-finite:', np.sum(np.logical_not(np.isfinite(zpscale))))
    
            T.sig1 /= zpscale
            T.sig1[np.logical_not(np.isfinite(T.sig1))] = 0.
            print('Median sig1:', np.median(T.sig1))
    
            print('Before:')
            for col in ['psfdepth', 'galdepth', 'gausspsfdepth', 'gaussgaldepth']:
                c = T.get(col)
                for band in 'grz':
                    I = np.flatnonzero((T.filter == band) * (T.sig1 > 0))
                    print(col, band, 'median', np.median(c[I]))