# 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
        for k,v in header.items():
            fitshdr.add_record({'name':k,'value':v})
    # ADW: Should this be a debug?
    logger.info("Writing %s..."%filename)
    fitsio.write(filename,data,extname='PIX_DATA',header=fitshdr,clobber=True)

def read_partial_map(filenames, column, fullsky=True, **kwargs):
    """
    Read a partial HEALPix file(s) and return pixels and values/map. Can
    handle 3D healpix maps (pix, value, zdim). Returned array has
    shape (dimz,npix).

    Parameters:
    -----------
    filenames     : list of input filenames
    column        : column of interest
    fullsky       : partial or fullsky map
    kwargs        : passed to fitsio.read

    Returns:
    --------
    (nside,pix,map) : pixel array and healpix map (partial or fullsky)
    """

    # Make sure that PIXEL is in columns
    #kwargs['columns'] = ['PIXEL',column]
    kwargs['columns'] = ['PIXEL'] + np.atleast_1d(column).tolist()

    filenames = np.atleast_1d(filenames)
    header = fitsio.read_header(filenames[0],ext=kwargs.get('ext',1))

# 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

        for k,v in header.items():
            fitshdr.add_record({'name':k,'value':v})
    # ADW: Should this be a debug?
    logger.info("Writing %s..."%filename)
    fitsio.write(filename,data,extname='PIX_DATA',header=fitshdr,clobber=True)

def read_partial_map(filenames, column, fullsky=True, **kwargs):
    """
    Read a partial HEALPix file(s) and return pixels and values/map. Can
    handle 3D healpix maps (pix, value, zdim). Returned array has
    shape (dimz,npix).

    Parameters:
    -----------
    filenames     : list of input filenames
    column        : column of interest
    fullsky       : partial or fullsky map
    kwargs        : passed to fitsio.read

    Returns:
    --------
    (nside,pix,map) : pixel array and healpix map (partial or fullsky)
    """

    # Make sure that PIXEL is in columns
    #kwargs['columns'] = ['PIXEL',column]
    kwargs['columns'] = ['PIXEL'] + np.atleast_1d(column).tolist()

    filenames = np.atleast_1d(filenames)
    header = fitsio.read_header(filenames[0],ext=kwargs.get('ext',1))

    data = fileio.load_files(filenames,**kwargs)