예제 #1
0
def main():
    """Main program.
    """
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        '--force',
        action='store_true',
        help='Run calib processes even if files already exist?')
    parser.add_argument('--ccds', help='Set ccds.fits file to load')

    parser.add_argument(
        '--expnum',
        type=str,
        help='Cut to a single or set of exposures; comma-separated list')
    parser.add_argument('--extname',
                        '--ccdname',
                        help='Cut to a single extension/CCD name')

    parser.add_argument('--no-psf',
                        dest='psfex',
                        action='store_false',
                        help='Do not compute PsfEx calibs')
    parser.add_argument('--no-sky',
                        dest='sky',
                        action='store_false',
                        help='Do not compute sky models')
    parser.add_argument('--run-se',
                        action='store_true',
                        help='Run SourceExtractor')

    parser.add_argument('--splinesky',
                        action='store_true',
                        help='Spline sky, not constant')
    parser.add_argument('--threads',
                        type=int,
                        help='Run multi-threaded',
                        default=None)
    parser.add_argument('--continue',
                        dest='cont',
                        default=False,
                        action='store_true',
                        help='Continue even if one file fails?')

    parser.add_argument('args', nargs=argparse.REMAINDER)
    opt = parser.parse_args()

    survey = LegacySurveyData()
    if opt.ccds is not None:
        T = fits_table(opt.ccds)
        T = survey.cleanup_ccds_table(T)

        print('Read', len(T), 'from', opt.ccds)
    else:
        T = survey.get_ccds()
        #print len(T), 'CCDs'

    if len(opt.args) == 0:
        if opt.expnum is not None:
            expnums = set([int(e) for e in opt.expnum.split(',')])
            T.cut(np.array([e in expnums for e in T.expnum]))
            print('Cut to', len(T), 'with expnum in', expnums)
        if opt.extname is not None:
            T.cut(np.array([(t.strip() == opt.extname) for t in T.ccdname]))
            print('Cut to', len(T), 'with extname =', opt.extname)

        opt.args = range(len(T))

    args = []
    for a in opt.args:
        # Check for "expnum-ccdname" format.
        if '-' in str(a):
            words = a.split('-')
            assert (len(words) == 2)
            expnum = int(words[0])
            ccdname = words[1]
            I = np.flatnonzero((T.expnum == expnum) * (T.ccdname == ccdname))
            if len(I) != 1:
                print('Found', len(I), 'CCDs for expnum', expnum, 'CCDname',
                      ccdname, ':', I)
                print('WARNING: skipping this expnum,ccdname')
                continue
            assert (len(I) == 1)
            t = T[I[0]]
        else:
            i = int(a)
            print('Index', i)
            t = T[i]

        #print('CCDnmatch', t.ccdnmatch)
        #if t.ccdnmatch < 20 and not opt.force:
        #    print('Skipping ccdnmatch = %i' % t.ccdnmatch)
        #    continue

        im = survey.get_image_object(t)
        print('Running', im.name)

        kwargs = dict(psfex=opt.psfex, sky=opt.sky)
        if opt.force:
            kwargs.update(force=True)
        if opt.run_se:
            kwargs.update(se=True)
        if opt.splinesky:
            kwargs.update(splinesky=True)

        if opt.cont:
            kwargs.update(noraise=True)

        if opt.threads:
            args.append((im, kwargs))
        else:
            run_calibs((im, kwargs))

    if opt.threads:
        from astrometry.util.multiproc import multiproc
        mp = multiproc(opt.threads)
        mp.map(run_calibs, args)

    return 0
예제 #2
0
def main():
    import argparse
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--expnum',
        type=str,
        help='Run specified exposure numbers (can be comma-separated list')
    parser.add_argument(
        '--all-found',
        action='store_true',
        default=False,
        help='Only write output if all required input files are found')
    parser.add_argument('--ccds',
                        help='Set ccds.fits file to load, default is all')
    parser.add_argument('--continue',
                        dest='con',
                        help='Continue even if one exposure is bad',
                        action='store_true',
                        default=False)
    parser.add_argument('--outdir',
                        help='Output directory, default %(default)s',
                        default='calib')

    opt = parser.parse_args()

    survey = LegacySurveyData()
    if opt.ccds:
        ccds = fits_table(opt.ccds)
        ccds = survey.cleanup_ccds_table(ccds)
        survey.ccds = ccds

    if opt.expnum is not None:
        expnums = [(None, int(x, 10)) for x in opt.expnum.split(',')]
    else:
        ccds = survey.get_ccds()
        expnums = set(zip(ccds.camera, ccds.expnum))
        print(len(expnums), 'unique camera+expnums')

    for i, (camera, expnum) in enumerate(expnums):
        print()
        print('Exposure', i + 1, 'of', len(expnums), ':', camera, 'expnum',
              expnum)
        if camera is None:
            C = survey.find_ccds(expnum=expnum)
            print(len(C), 'CCDs with expnum', expnum)
            camera = C.camera[0]
            print('Set camera to', camera)

        C = survey.find_ccds(expnum=expnum, camera=camera)
        print(len(C), 'CCDs with expnum', expnum, 'and camera', camera)

        im0 = survey.get_image_object(C[0])

        skyoutfn = im0.merged_skyfn
        psfoutfn = im0.merged_psffn

        print('Checking for', skyoutfn)
        print('Checking for', psfoutfn)
        if os.path.exists(skyoutfn) and os.path.exists(psfoutfn):
            print('Exposure', expnum, 'is done already')
            continue

        if not os.path.exists(skyoutfn):
            try:
                merge_splinesky(survey, expnum, C, skyoutfn, opt)
            except:
                if not opt.con:
                    raise
                import traceback
                traceback.print_exc()
                print('Exposure failed:', expnum, '.  Continuing...')

        if not os.path.exists(psfoutfn):
            try:
                merge_psfex(survey, expnum, C, psfoutfn, opt)
            except:
                if not opt.con:
                    raise
                import traceback
                traceback.print_exc()
                print('Exposure failed:', expnum, '.  Continuing...')
예제 #3
0
        name = name.replace('survey-ccds-', '')
        name = name.replace('.fits', '')
        name = name.replace('.gz', '')
        print('Name', name)

        ## Quick check for existing output filename
        if opt.piece is not None and not opt.force:
            outfn = 'ccds-annotated/ccds-annotated-%s-%03i.fits' % (name, opt.piece)
            if os.path.exists(outfn):
                print('Already exists:', outfn)
                sys.exit(0)

        args = []
        i = 0
        ccds = fits_table(fn)
        ccds = survey.cleanup_ccds_table(ccds)

        if opt.piece is not None:
            c = ccds[opt.piece*N:]
            c = c[:N]
            _bounce_main((name, opt.piece, c, opt.force, opt.mzls, opt.normalizePsf))
            sys.exit(0)

        while len(ccds):
            c = ccds[:N]
            ccds = ccds[N:]
            args.append((name, i, c, opt.force, opt.mzls, opt.normalizePsf))
            i += 1
        print('Split CCDs file into', len(args), 'pieces')
        print('sizes:', [len(a[2]) for a in args])
        mp.map(_bounce_main, args)