# Path: ugali/utils/projector.py
# def celToGal(ra, dec):
#     """
#     Converts Celestial J2000 (deg) to Calactic (deg) coordinates
#     """
#     dec = np.radians(dec)
#     sin_dec = np.sin(dec)
#     cos_dec = np.cos(dec)
# 
#     ra = np.radians(ra)    
#     ra_gp = np.radians(192.85948)
#     de_gp = np.radians(27.12825)
# 
#     sin_ra_gp = np.sin(ra - ra_gp)
#     cos_ra_gp = np.cos(ra - ra_gp)
# 
#     lcp = np.radians(122.932)    
#     sin_b = (np.sin(de_gp) * sin_dec) \
#             + (np.cos(de_gp) * cos_dec * cos_ra_gp)
#     lcpml = np.arctan2(cos_dec * sin_ra_gp,
#                           (np.cos(de_gp) * sin_dec) \
#                           - (np.sin(de_gp) * cos_dec * cos_ra_gp))
#     bb = np.arcsin(sin_b)
#     ll = (lcp - lcpml + (2. * np.pi)) % (2. * np.pi)
#     return np.degrees(ll), np.degrees(bb)
# 
# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


import healpy
import pylab as plt
import numpy
import ugali.utils.skymap
from ugali.utils.projector import celToGal
from ugali.utils.logger import logger
    from optparse import OptionParser
leo_II            = ["Leo II"  ,dict(default_kwargs,xytext=(-4,0),ha='right'), ], 
leo_IV            = ["Leo IV"  ,dict(default_kwargs,xytext=(5,-1),ha='left'),  ], 
leo_T             = ["Leo T"   ,dict(default_kwargs,xytext=(4,5),ha='left'),   ], 
leo_V             = ["Leo V"   ,dict(default_kwargs,xytext=(4,5),ha='left'),   ], 
lmc               = ["LMC"     ,default_kwargs,                                ], 
pisces_II         = ["Psc II"  ,default_kwargs,                                ], 
sagittarius       = ["Sgr"     ,default_kwargs,                                ], 
sculptor          = ["Scl"     ,default_kwargs,                                ], 
segue_1           = ["Seg 1"   ,dict(default_kwargs,xytext=(4,2),ha='left'),   ], 
segue_2           = ["Seg 2"   ,default_kwargs,                                ], 
sextans           = ["Sex"     ,dict(default_kwargs,xytext=(-2,-5),ha='right'),], 
smc               = ["SMC"     ,default_kwargs,                                ], 
ursa_major_I      = ["UMa I"   ,dict(default_kwargs,xytext=(5,-5),ha='left'),  ], 
ursa_major_II     = ["UMa II"  ,dict(default_kwargs,xytext=(4,4)),             ], 
ursa_minor        = ["UMi"     ,default_kwargs,                                ], 
willman_1         = ["Wil 1"   ,dict(default_kwargs,xytext=(5,1),ha='left'),   ], 
)


if __name__ == "__main__":
    usage = "Usage: %prog  [options] input"
    description = "python script"
    parser = OptionParser(usage=usage,description=description)
    parser.add_option('-o','--outfile',default='allsky_maglims.png')
    parser.add_option('-t','--targets',default=None)
    parser.add_option('-c','--coord',default='GAL')
    parser.add_option('-p','--proj',default='MOL',choices=['MOL','CAR'])
    parser.add_option('-f','--field',default='MAGLIM')
    parser.add_option('-v','--verbose', action='store_true')
    (opts, args) = parser.parse_args()

# Path: ugali/utils/projector.py
# def celToGal(ra, dec):
#     """
#     Converts Celestial J2000 (deg) to Calactic (deg) coordinates
#     """
#     dec = np.radians(dec)
#     sin_dec = np.sin(dec)
#     cos_dec = np.cos(dec)
# 
#     ra = np.radians(ra)    
#     ra_gp = np.radians(192.85948)
#     de_gp = np.radians(27.12825)
# 
#     sin_ra_gp = np.sin(ra - ra_gp)
#     cos_ra_gp = np.cos(ra - ra_gp)
# 
#     lcp = np.radians(122.932)    
#     sin_b = (np.sin(de_gp) * sin_dec) \
#             + (np.cos(de_gp) * cos_dec * cos_ra_gp)
#     lcpml = np.arctan2(cos_dec * sin_ra_gp,
#                           (np.cos(de_gp) * sin_dec) \
#                           - (np.sin(de_gp) * cos_dec * cos_ra_gp))
#     bb = np.arcsin(sin_b)
#     ll = (lcp - lcpml + (2. * np.pi)) % (2. * np.pi)
#     return np.degrees(ll), np.degrees(bb)
# 
# Path: ugali/utils/logger.py
# class SpecialFormatter(logging.Formatter):
#     FORMATS = {'DEFAULT'       : "%(message)s",
#                logging.WARNING : "WARNING: %(message)s",
#                logging.ERROR   : "ERROR: %(message)s"}
#     def format(self, record):
# def file_found(filename,force):


# Path: ugali/scratch/PlotAllSkyHealpix.py
import healpy
import pylab as plt
import numpy
import ugali.utils.skymap
from ugali.utils.projector import celToGal
from ugali.utils.logger import logger
    from optparse import OptionParser

leo_II            = ["Leo II"  ,dict(default_kwargs,xytext=(-4,0),ha='right'), ], 
leo_IV            = ["Leo IV"  ,dict(default_kwargs,xytext=(5,-1),ha='left'),  ], 
leo_T             = ["Leo T"   ,dict(default_kwargs,xytext=(4,5),ha='left'),   ], 
leo_V             = ["Leo V"   ,dict(default_kwargs,xytext=(4,5),ha='left'),   ], 
lmc               = ["LMC"     ,default_kwargs,                                ], 
pisces_II         = ["Psc II"  ,default_kwargs,                                ], 
sagittarius       = ["Sgr"     ,default_kwargs,                                ], 
sculptor          = ["Scl"     ,default_kwargs,                                ], 
segue_1           = ["Seg 1"   ,dict(default_kwargs,xytext=(4,2),ha='left'),   ], 
segue_2           = ["Seg 2"   ,default_kwargs,                                ], 
sextans           = ["Sex"     ,dict(default_kwargs,xytext=(-2,-5),ha='right'),], 
smc               = ["SMC"     ,default_kwargs,                                ], 
ursa_major_I      = ["UMa I"   ,dict(default_kwargs,xytext=(5,-5),ha='left'),  ], 
ursa_major_II     = ["UMa II"  ,dict(default_kwargs,xytext=(4,4)),             ], 
ursa_minor        = ["UMi"     ,default_kwargs,                                ], 
willman_1         = ["Wil 1"   ,dict(default_kwargs,xytext=(5,1),ha='left'),   ], 
)


if __name__ == "__main__":
    usage = "Usage: %prog  [options] input"
    description = "python script"
    parser = OptionParser(usage=usage,description=description)
    parser.add_option('-o','--outfile',default='allsky_maglims.png')
    parser.add_option('-t','--targets',default=None)
    parser.add_option('-c','--coord',default='GAL')
    parser.add_option('-p','--proj',default='MOL',choices=['MOL','CAR'])
    parser.add_option('-f','--field',default='MAGLIM')
    parser.add_option('-v','--verbose', action='store_true')
    (opts, args) = parser.parse_args()

    if opts.verbose: logger.setLevel(logger.DEBUG)