예제 #1
0
def main():
    parser = OptionParser("usage: %prog [options] config_file.json "
                          "[config_file2.json, ...]"
                          "\n\nAtention:\ncalib, raw and product folder must"
                          "be set in the config files!"
                          "\n\nUse -vvv for DEBUG.")
    parser.add_option("-v", "--verbose", dest="verbose",
                      action="count",
                      help="Enable 'DEBUG' output in python log")
    parser.add_option("-e", "--skip-exist", dest="check_exist",
                      action="store_true",
                      default=False,
                      help="Skip if the product file already exists.")
    parser.add_option("-r", "--raise-error", dest="raise_error",
                      action="store_true",
                      default=False,
                      help="Raise errors instead of just log them.")
    parser.add_option("-i", "--include", dest="include_file",
                      default=None, metavar="FILE",
                      help="Preload FILE config before run the code.")
    parser.add_option("-p", "--product", dest="product",
                      default=None, metavar="NAME",
                      help="Product ID inside the configure files.")
    parser.add_option("-l", "--save-log", dest="save_log",
                      default=None, metavar="FILE",
                      help="Save log to FILE. If '%date' value, automatic name"
                           " based on date will be created.")

    (options, args) = parser.parse_args()

    if len(args) < 1:
        raise ValueError('No raw folder passed!')

    files = args

    if options.verbose is None:
        logger.setLevel('WARN')
    elif options.verbose == 1:
        logger.setLevel('INFO')
    else:
        logger.setLevel('DEBUG')

    pipe = MasterPipeline()
    if options.include_file is not None:
        pipe.load_default_file(options.include_file)

    def _process():
        for f in files:
            if options.product is not None:
                pipe.process_product(f, dataset=options.product,
                                     check_exist=options.check_exist,
                                     raise_error=options.raise_error)
            else:
                pipe.process_product(f, check_exist=options.check_exist,
                                     raise_error=options.raise_error)

    if options.save_log is not None:
        name = options.save_log
        if name == '%date':
            d = datetime.datetime.now()
            d = d.isoformat(timespec='seconds')
            name = "astropop_{}.log".format(d)
        with logger.log_to_file(name):
            _process()
    else:
        _process()
예제 #2
0
def main():
    parser = OptionParser("usage: %prog [options] raw_dir [raw_dir2, ...]")
    parser.add_option("-s",
                      "--stack",
                      action="store_true",
                      dest="stack_images",
                      default=False,
                      help="Stack all science images in one (sum)")
    parser.add_option("-i",
                      "--individual",
                      action="store_true",
                      dest="save_calibed",
                      default=True,
                      help="Save individual calibed science images "
                      "in 'calib_images' subfolder")
    parser.add_option("-v",
                      "--verbose",
                      dest="verbose",
                      action="store_true",
                      default=False,
                      help="Enable 'DEBUG' output in python log")
    parser.add_option("-a",
                      "--astrometry",
                      dest="astrometry",
                      action="store_true",
                      default=False,
                      help="Enable astrometry solving of stacked images "
                      "with astrometry.net")
    parser.add_option("-n",
                      "--science-catalog",
                      dest="science_catalog",
                      default=None,
                      metavar="FILE",
                      help="ASCII catalog to identify science stars. "
                      "Has to be astropy's table readable with columns "
                      "ID, RA, DEC")
    parser.add_option("-l",
                      "--save-log",
                      dest="save_log",
                      default=None,
                      metavar="FILE",
                      help="Save log to FILE. If '%date' value, automatic name"
                      " based on date will be created.")
    parser.add_option("-d",
                      "--dest",
                      dest="reduced_folder",
                      default='~/astropop_reduced',
                      metavar="FOLDER",
                      help="Reduced images (and created calib frames) will "
                      "be saved at inside FOLDER")
    parser.add_option("-c",
                      "--calib",
                      dest="calib_folder",
                      default=None,
                      metavar="FOLDER",
                      help="Load/save calibration frames from/in FOLDER. "
                      "If not set, reduced_folder/calib will be used"
                      " instead.")

    (options, args) = parser.parse_args()

    if len(args) < 1:
        raise ValueError('No raw folder passed!')

    raw_dirs = args

    if options.verbose:
        logger.setLevel('DEBUG')
    else:
        logger.setLevel('INFO')

    stack_images = options.stack_images
    individual = options.save_calibed
    astrometry = options.astrometry
    reduced_folder = os.path.expanduser(options.reduced_folder)
    reduced_folder = os.path.abspath(reduced_folder)
    mkdir_p(reduced_folder)

    if options.calib_folder is not None:
        calib_folder = os.path.expanduser(options.calib_folder)
        calib_folder = os.path.abspath(calib_folder)
    else:
        calib_folder = os.path.join(reduced_folder, 'calib')

    sci_cat = options.science_catalog
    if sci_cat is not None:
        sci_cat = ASCIICatalogClass(sci_cat,
                                    id_key='ID',
                                    ra_key='RA',
                                    dec_key='DEC',
                                    format='ascii')

    mkdir_p(reduced_folder)
    pipe = ImpactonCalib(product_dir=reduced_folder,
                         calib_dir=calib_folder,
                         ext=0,
                         fits_extensions=['.fit'],
                         compression=True)
    if stack_images:
        pipe_phot = ImpactonStackedPhotometry(product_dir=reduced_folder,
                                              image_ext=0)
    else:
        pipe_lc = ImpactonLightCurve(product_dir=reduced_folder, image_ext=0)

    def _process():
        for fold in raw_dirs:
            prods = pipe.run(fold,
                             stack_images=stack_images,
                             save_calibed=individual,
                             astrometry=astrometry)
            if stack_images:
                pipe_phot.process_products(prods, sci_cat)
            else:
                pipe_lc.process_products(prods)

    if options.save_log is not None:
        name = options.save_log
        if name == '%date':
            d = datetime.datetime.now()
            d = d.isoformat(timespec='seconds')
            name = "astropop_{}.log".format(d)
            name = os.path.join(reduced_folder, name)
        with logger.log_to_file(name):
            _process()
    else:
        _process()
예제 #3
0
def main():
    parser = OptionParser("usage: %prog [options] raw_dir [raw_dir2, ...]")
    parser.add_option("-v", "--verbose", dest="verbose",
                      action="store_true",
                      default=False,
                      help="Enable 'DEBUG' output in python log")
    parser.add_option("-a", "--astrometry", dest="astrometry",
                      action="store_true",
                      default=False,
                      help="Enable astrometry solving of stacked images "
                           "with astrometry.net")
    parser.add_option("-n", "--science-catalog", dest="science_catalog",
                      default=None, metavar="FILE",
                      help="ASCII catalog to identify science stars. "
                           "Has to be astropy's table readable with columns "
                           "ID, RA, DEC")
    parser.add_option("-l", "--save-log", dest="save_log",
                      default=None, metavar="FILE",
                      help="Save log to FILE. If '%date' value, automatic name"
                           " based on date will be created.")
    parser.add_option("-d", "--dest", dest="reduced_folder",
                      default='~/astropop_reduced', metavar="FOLDER",
                      help="Reduced images (and created calib frames) will "
                           "be saved at inside FOLDER")

    (options, args) = parser.parse_args()

    if len(args) < 1:
        raise ValueError('No raw folder passed!')

    raw_dirs = args

    if options.verbose:
        logger.setLevel('DEBUG')
    else:
        logger.setLevel('INFO')

    reduced_folder = os.path.expanduser(options.reduced_folder)
    reduced_folder = os.path.abspath(reduced_folder)
    mkdir_p(reduced_folder)

    sci_cat = options.science_catalog
    if sci_cat is not None:
        sci_cat = ASCIICatalogClass(sci_cat, id_key='ID', ra_key='RA',
                                    dec_key='DEC', format='ascii')

    mkdir_p(reduced_folder)
    pipe_phot = BSMStackedPhotometry(product_dir=reduced_folder, image_ext=0)

    def _process():
        for fold in raw_dirs:
            pipe_phot.run(fold, sci_cat, options.astrometry)

    if options.save_log is not None:
        name = options.save_log
        if name == '%date':
            d = datetime.datetime.now()
            d = d.isoformat(timespec='seconds')
            name = "astropop_{}.log".format(d)
            name = os.path.join(reduced_folder, name)
        with logger.log_to_file(name):
            _process()
    else:
        _process()