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))
        logger.warning('         available distance moduli:'+str(distance_modulus_array))
        return False

    distance_modulus_key = '%.2f'%(distance_modulus_array[numpy.argmin(numpy.fabs(distance_modulus_array - distance_modulus))])

    bins_mag_err = reader['BINS_MAG_ERR'].data.field('BINS_MAG_ERR') 
    bins_mag_1 = reader['BINS_MAG_1'].data.field('BINS_MAG_1') 
    bins_mag_2 = reader['BINS_MAG_2'].data.field('BINS_MAG_2') 
    # Note that magnitude uncertainty is always assigned by rounding up, is this the right thing to do?
    index_mag_err_1 = numpy.clip(numpy.digitize(mag_err_1, bins_mag_err) - 1,
                                 0, len(bins_mag_err) - 2)
    index_mag_err_2 = numpy.clip(numpy.digitize(mag_err_2, bins_mag_err) - 1,
                                 0, len(bins_mag_err) - 2)

    u_color = numpy.zeros(len(mag_1))

    for index_mag_err_1_select in range(0, len(bins_mag_err) - 1):
        for index_mag_err_2_select in range(0, len(bins_mag_err) - 1):
            cut = numpy.logical_and(index_mag_err_1 == index_mag_err_1_select,
                                    index_mag_err_2 == index_mag_err_2_select)
            if numpy.sum(cut) < 1:
                continue
            histo = reader[distance_modulus_key].data.field('%i%i'%(index_mag_err_1_select, index_mag_err_2_select))
            u_color[cut] = ugali.utils.binning.take2D(histo,
                                                      mag_2[cut], mag_1[cut],
                                                      bins_mag_2, bins_mag_1)
    
    reader.close()
    return u_color
def readColorLUT ( infile , distance_modulus , mag_1 , mag_2 , mag_err_1 , mag_err_2 ) : 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 ) ) logger . warning ( '         available distance moduli:' + str ( distance_modulus_array ) ) return False distance_modulus_key = '%.2f' % ( distance_modulus_array [ numpy . argmin ( numpy . fabs ( distance_modulus_array - distance_modulus ) ) ] ) bins_mag_err = reader [ 'BINS_MAG_ERR' ] . data . field ( 'BINS_MAG_ERR' ) bins_mag_1 = reader [ 'BINS_MAG_1' ] . data . field ( 'BINS_MAG_1' ) bins_mag_2 = reader [ 'BINS_MAG_2' ] . data . field ( 'BINS_MAG_2' ) index_mag_err_1 = numpy . clip ( numpy . digitize ( mag_err_1 , bins_mag_err ) - 1 , 0 , len ( bins_mag_err ) - 2 ) index_mag_err_2 = numpy . clip ( numpy . digitize ( mag_err_2 , bins_mag_err ) - 1 , 0 , len ( bins_mag_err ) - 2 ) u_color = numpy . zeros ( len ( mag_1 ) ) for index_mag_err_1_select in range ( 0 , len ( bins_mag_err ) - 1 ) : for index_mag_err_2_select in range ( 0 , len ( bins_mag_err ) - 1 ) : cut = numpy . logical_and ( index_mag_err_1 == index_mag_err_1_select , index_mag_err_2 == index_mag_err_2_select ) if numpy . sum ( cut ) < 1 : continue histo = reader [ distance_modulus_key ] . data . field ( '%i%i' % ( index_mag_err_1_select , index_mag_err_2_select ) ) u_color [ cut ] = ugali . utils . binning . take2D ( histo , mag_2 [ cut ] , mag_1 [ cut ] , bins_mag_2 , bins_mag_1 ) reader . close ( ) return u_color
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.