#!/usr/bin/env python

import argparse
from soxs import Spectrum, write_photon_list, AnnulusModel

parser = argparse.ArgumentParser(description='Create a SIMPUT photon list of an annulus source with '+
                                             'uniform surface brightness from a spectrum supplied in a file.')
parser.add_argument("simput_prefix", type=str, 
                    help='The prefix of the SIMPUT file to be used as the root of the '+
                         'catalog. If it does not exist, it will be created.')
parser.add_argument("phlist_prefix", type=str, 
                    help='The prefix of the photon list file to be written.')
parser.add_argument("ra0", type=float, help="The right ascension of the source center in degrees.")
parser.add_argument("dec0", type=float, help="The declination of the source center in degrees.")
parser.add_argument("r_in", type=float, help="The inner annulus of the source center in arcseconds.")
parser.add_argument("r_out", type=float, help="The outer annulus of the source center in arcseconds.")
parser.add_argument("specfile", type=str, help="The file containing the spectrum to be used.")
parser.add_argument("exp_time", type=float, help='The exposure time to use, in seconds.')
parser.add_argument("--area", type=float, default=30000.0, 
                    help='The collecting area to use, in cm^2. Default: 30000.0')
parser.add_argument("--append", action='store_true',
                    help='If set, append a new source an existing SIMPUT catalog. ')
parser.add_argument("--clobber", action='store_true',
                    help='Whether or not to clobber an existing file with the same name.')

args = parser.parse_args()

spec = Spectrum.from_file(args.specfile)
energy = spec.generate_energies(args.exp_time, args.area)
n_evt = energy.size
ann_src = AnnulusModel(args.ra0, args.dec0, args.r_in, args.r_out, n_evt)

write_photon_list(args.simput_prefix, args.phlist_prefix, args.exp_time, 
                  args.area, ann_src.ra, ann_src.dec, energy, append=args.append, 
                  clobber=args.clobber)