#!/usr/bin/env python

import argparse
import numpy as np
from soxs.background import make_point_sources_file

parser = argparse.ArgumentParser(description='Create a SIMPUT photon list catalog of a '
                                             'point-source background.')
parser.add_argument("filename", type=str,
                    help='The filename of the SIMPUT catalog to be used as the root of the ' +
                         'catalog. If it does not exist, it will be created.')
parser.add_argument("name", type=str,
                    help='The name of the source in the SIMPUT catalog.')
parser.add_argument("exp_time", help='The exposure time to use, in seconds.')
parser.add_argument("fov", help="The field of view on a side in arcminutes.")
parser.add_argument("sky_center", type=str, help='The center RA, Dec coordinates of the ' +
                                                 'observation, in degrees, comma-separated.')
parser.add_argument("--absorb_model", type=str, default="wabs",
                    help="The absorption model to use for foreground galactic absorption. Default: 'wabs'")
parser.add_argument("--nh", default=0.05,
                    help='The galactic hydrogen column in units of 10**22 atoms/cm**2. '
                         'Default: 0.05')
parser.add_argument("--area", default=30000.0,
                    help='The collecting area to use, in cm^2. Default: 30000.0')
parser.add_argument("--src_filename", type=str,
                    help='An optional filename to store the source instead of the SIMPUT '
                         'catalog file.')
parser.add_argument("--append", action='store_true',
                    help='If set, append a new source an existing SIMPUT catalog. ')
parser.add_argument("--overwrite", action='store_true',
                    help='Overwrite an existing file with the same name.')
parser.add_argument("--input_sources", type=str,
                    help="Use a previously written table of sources as input instead of generating them.")
parser.add_argument("--output_sources", type=str,
                    help="Output the source properties to the specified file.")
parser.add_argument("--random_seed", type=int,
                    help="A constant integer random seed to produce a consistent set of random numbers.")

args = parser.parse_args()

sky_center = np.array(args.sky_center.split(',')).astype("float64")

make_point_sources_file(args.filename, args.name, args.exp_time, args.fov, 
                        sky_center, absorb_model=args.absorb_model, nH=args.nh, 
                        area=args.area, append=args.append, 
                        src_filename=args.src_filename, 
                        overwrite=args.overwrite, 
                        output_sources=args.output_sources,
                        input_sources=args.input_sources, prng=args.random_seed)