""" Code to derive atmospheric extinction
    
Context : SRP
Module  : SRPAtmExtinction
Author  : Stefano Covino
Date    : 22/08/2012
E-mail  : stefano.covino@brera.inaf.it
URL:    : http://www.merate.mi.astro.it/utenti/covino
Purpose : Compute atmospheric extinction

Usage   : SRPAtmExtinction [-h] -l wave [-s site] [-v] [--version]
            -l Wavelength for extinction coefficient (micron)
            -s Site for the extinction curve
    
History : (22/08/2012) First version.

"""

__version__ = '1.0.0'


import argparse, math, sys
import atpy, numpy
import SRP.SRPSpectroscopy as SS
from SRP.SRPSpectroscopy.AtmExtinction import AtmExtinction



parser = argparse.ArgumentParser()
parser.add_argument("-l", "--wave", action="store", type=float, help="Wavelength for extinction coefficient (micron)", required=True, metavar='wave')
parser.add_argument("-s", "--site", action="store", help="Site for the extinction curve", default='LaSilla', metavar='site')
parser.add_argument("-v", "--verbose", action="store_true", help="Fully describe operations")
parser.add_argument("--version", action="version", version=__version__)
options = parser.parse_args()


#
if options.wave < 0:
    parser.error("Wavelength must be positive.")
#
if options.site not in SS.AtmExtCurves.keys():
    print "Available sites:"
    for i in SS.AtmExtCurves.keys():
        print "\t", i
    parser.error("Site not available.")
#
k = AtmExtinction(options.wave,SS.AtmExtCurves[options.site])
if k <> None:
    if options.verbose:
        print "Extinction coefficient at %.3f micron is %.3f mag/airmass" % (options.wave, k)
    else:
        print "%.3f %.3f" % (options.wave, k)
else:
    if options.verbose:
        print "Wavelength not available."
    else:
        print "-1 -1"
#
        
