#!/usr/bin/env python
# Licensed under a 3-clause BSD style license - see LICENSE.rst
"""Simulates IACT eventlist using an ARF file.

TODO: document
"""


# Parse command line arguments

from gammapy.utils.scripts import argparse, GammapyFormatter
parser = argparse.ArgumentParser(description=__doc__,
                                 formatter_class=GammapyFormatter)
parser.add_argument('arf', type=str,
                    help='Input ARF file.')
parser.add_argument('-t', '--exposure_time', type=float, default=.5,
                    help='Exposure time in hours')
parser.add_argument('-f', '--flux', type=float, default=.1,
                    help='Flux in units of Crab')
parser.add_argument('-r', '--rmf_file', type=str, default=None,
                    help='Response matrix file (RMF), optional')
parser.add_argument('-e', '--extra_file', type=str, default=None,
                    help='Extra file with auxiliary information e.g. bg-rate, psf, etc.')
parser.add_argument('-o', '--output_filename_base', type=str, default=None,
                    help='Output filename base. If set, output files will be written')
parser.add_argument('--write_pha', action='store_true', default=False,
                    help='Write photon PHA file')
parser.add_argument('--no_graphical_output', action='store_false', default=True,
                    help='Switch off graphical output')
parser.add_argument('-l', '--loglevel', type=str, default='INFO',
                    help='Amount of logging e.g. DEBUG, INFO, WARNING, ERROR.')

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

# Execute script

import logging
logging.basicConfig(level=logging.DEBUG, format='%(levelname)s - %(message)s')
from gammapy.utils.pyfact import sim_evlist

sim_evlist(flux=args['flux'],
           obstime=args['exposure_time'],
           arf=args['arf'],
           rmf=args['rmf'],
           extra=args['extra'],
           output_filename_base=args['output_filename_base'],
           write_pha=args['write_pha'],
           do_graphical_output=args['graphical_output'],
           loglevel=args['loglevel'])
