#!python

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

parser = argparse.ArgumentParser(description='Create a SIMPUT photon list of a '
                                             'point-source background.')
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("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("--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.simput_prefix, args.phlist_prefix, args.exp_time,
                        args.fov, sky_center, absorb_model=args.absorb_model,
                        nH=args.nh, area=args.area, append=args.append, 
                        overwrite=args.overwrite, output_sources=args.output_sources,
                        input_sources=args.input_sources, prng=args.random_seed)