# 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 time
import numpy
import scipy.signal
import astropy.io.fits as pyfits
import ugali.utils.config
import ugali.utils.binning
import ugali.isochrone
    if plot: import ugali.utils.plotting
    if plot: import ugali.utils.plotting
from ugali.utils.logger import logger
    columns_array = [pyfits.Column(name = 'BINS_MAG_2',
                                   format = 'E',
                                   array = bins_mag_2)]
    hdu = pyfits.new_table(columns_array)
    hdu.name = 'BINS_MAG_2'
    hdul.append(hdu)

    logger.info('Writing look-up table to %s'%(outfile))
    hdul.writeto(outfile, clobber = True)

############################################################

def mergeColorLUT(infiles):
    """
    Tool to merge color look-up tables.
    """
    pass

############################################################

def readColorLUT(infile, distance_modulus, mag_1, mag_2, mag_err_1, mag_err_2):
    """
    Take in a color look-up table and return the signal color evaluated for each object.
    Consider making the argument a Catalog object rather than magnitudes and uncertainties.
    """

    reader = pyfits.open(infile)

    distance_modulus_array = reader['DISTANCE_MODULUS'].data.field('DISTANCE_MODULUS')
    if not numpy.any(numpy.fabs(distance_modulus_array - distance_modulus) < 1.e-3):

# 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/color_lut.py
import time
import numpy
import scipy.signal
import astropy.io.fits as pyfits
import ugali.utils.config
import ugali.utils.binning
import ugali.isochrone
    if plot: import ugali.utils.plotting
    if plot: import ugali.utils.plotting
from ugali.utils.logger import logger

    columns_array = [pyfits.Column(name = 'BINS_MAG_2',
                                   format = 'E',
                                   array = bins_mag_2)]
    hdu = pyfits.new_table(columns_array)
    hdu.name = 'BINS_MAG_2'
    hdul.append(hdu)

    logger.info('Writing look-up table to %s'%(outfile))
    hdul.writeto(outfile, clobber = True)

############################################################

def mergeColorLUT(infiles):
    """
    Tool to merge color look-up tables.
    """
    pass

############################################################

def readColorLUT(infile, distance_modulus, mag_1, mag_2, mag_err_1, mag_err_2):
    """
    Take in a color look-up table and return the signal color evaluated for each object.
    Consider making the argument a Catalog object rather than magnitudes and uncertainties.
    """

    reader = pyfits.open(infile)

    distance_modulus_array = reader['DISTANCE_MODULUS'].data.field('DISTANCE_MODULUS')
    if not numpy.any(numpy.fabs(distance_modulus_array - distance_modulus) < 1.e-3):

        logger.warning("Distance modulus %.2f not available in file %s"%(distance_modulus, infile))