# Path: ugali/utils/fileio.py
# def read(filename,**kwargs):
# def write(filename,data,**kwargs):
# def check_formula(formula):
# def parse_formula(formula):
# def add_column(filename,column,formula,force=False):
# def load_header(kwargs):
# def load_headers(filenames,multiproc=False,**kwargs):
# def load_file(kwargs):
# def load_files(filenames,multiproc=False,**kwargs):
# def load(args):
# def load_infiles(infiles,columns=None,multiproc=False):
# def insert_columns(filename,data,ext=1,force=False,colnum=None):
# def write_fits(filename,data,header=None,force=False):
# 
# 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):


from collections import OrderedDict as odict
from ugali.utils import fileio
from ugali.utils.logger import logger
import numpy
import numpy as np
import healpy as hp
import fitsio
import ugali.utils.projector
import ugali.utils.fileio
    import fitsio
    import fitsio
    import fitsio
    import fitsio
    import fitsio
    import argparse
    names = data_dict.dtype.names
    data_dict.dtype.names = ['PIXEL' if n=='LKDPIX' else n for n in names]
        
    write_partial_map(outfile, data_dict, nside)
    return data_dict

def merge_likelihood_headers2(filenames, outfile, **kwargs):
    """
    Merge header information from likelihood files.

    Parameters:
    -----------
    filenames : input filenames
    oufile    : the merged file to write
    
    Returns:
    --------
    data      : the data being written
    """
    filenames = np.atleast_1d(filenames)

    ext='PIX_DATA'
    nside = fitsio.read_header(filenames[0],ext=ext)['LKDNSIDE']
    
    keys=['STELLAR','NINSIDE','NANNULUS']
    data_dict = odict(PIXEL=[])
    for k in keys:
        data_dict[k] = []

    for i,filename in enumerate(filenames):

# Path: ugali/utils/fileio.py
# def read(filename,**kwargs):
# def write(filename,data,**kwargs):
# def check_formula(formula):
# def parse_formula(formula):
# def add_column(filename,column,formula,force=False):
# def load_header(kwargs):
# def load_headers(filenames,multiproc=False,**kwargs):
# def load_file(kwargs):
# def load_files(filenames,multiproc=False,**kwargs):
# def load(args):
# def load_infiles(infiles,columns=None,multiproc=False):
# def insert_columns(filename,data,ext=1,force=False,colnum=None):
# def write_fits(filename,data,header=None,force=False):
# 
# 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/utils/healpix.py
from collections import OrderedDict as odict
from ugali.utils import fileio
from ugali.utils.logger import logger
import numpy
import numpy as np
import healpy as hp
import fitsio
import ugali.utils.projector
import ugali.utils.fileio
    import fitsio
    import fitsio
    import fitsio
    import fitsio
    import fitsio
    import argparse

    names = data_dict.dtype.names
    data_dict.dtype.names = ['PIXEL' if n=='LKDPIX' else n for n in names]
        
    write_partial_map(outfile, data_dict, nside)
    return data_dict

def merge_likelihood_headers2(filenames, outfile, **kwargs):
    """
    Merge header information from likelihood files.

    Parameters:
    -----------
    filenames : input filenames
    oufile    : the merged file to write
    
    Returns:
    --------
    data      : the data being written
    """
    filenames = np.atleast_1d(filenames)

    ext='PIX_DATA'
    nside = fitsio.read_header(filenames[0],ext=ext)['LKDNSIDE']
    
    keys=['STELLAR','NINSIDE','NANNULUS']
    data_dict = odict(PIXEL=[])
    for k in keys:
        data_dict[k] = []

    for i,filename in enumerate(filenames):

        logger.debug('(%i/%i) %s'%(i+1, len(filenames), filename))