#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Make derived maps for a given set of basic maps.

TODO: describe
"""

# Parse command line arguments

from gammapy.utils.scripts import argparse, GammapyFormatter
parser = argparse.ArgumentParser(description=__doc__,
                                 formatter_class=GammapyFormatter)
parser.add_argument('infile', type=str,
                    help='Input FITS file name')
parser.add_argument('outfile', type=str,
                    help='Output FITS file name')
parser.add_argument('theta', type=float,
                    help='On-region correlation radius (deg)')
parser.add_argument('--is_off_correlated', action='store_false',
                    help='Are the basic OFF maps correlated?')
parser.add_argument('--clobber', action='store_true',
                    help='Clobber output files?')

args = parser.parse_args()
args = vars(args)

# Execute script

import logging
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s')
from astropy.io import fits
from gammapy.background import Maps

logging.info('Reading {0}'.format(args['infile']))
hdus = fits.open(args['infile'])
maps = Maps(hdus, theta=args['theta'],
            is_off_correlated=args['is_off_correlated'])
logging.info('Computing derived maps')
maps.make_derived_maps()
logging.info('Writing {0}'.format(args['outfile']))
maps.writeto(args['outfile'], clobber=True)
