# 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
    -----------
    filename : output file name
    data     : dictionary or recarray of data to write (must contain 'PIXEL')
    nside    : healpix nside of data
    coord    : 'G'alactic, 'C'elestial, 'E'cliptic
    ordering : 'RING' or 'NEST'
    kwargs   : Passed to fitsio.write

    Returns:
    --------
    None
    """

    # ADW: Do we want to make everything uppercase?

    if isinstance(data,dict):
        names = list(data.keys())
    else:
        names = data.dtype.names

    if 'PIXEL' not in names:
        msg = "'PIXEL' column not found."
        raise ValueError(msg)

    hdr = header_odict(nside=nside,coord=coord,nest=nest)
    fitshdr = fitsio.FITSHDR(list(hdr.values()))
    if header is not None:
        for k,v in header.items():
            fitshdr.add_record({'name':k,'value':v})
    # ADW: Should this be a debug?

# 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

    -----------
    filename : output file name
    data     : dictionary or recarray of data to write (must contain 'PIXEL')
    nside    : healpix nside of data
    coord    : 'G'alactic, 'C'elestial, 'E'cliptic
    ordering : 'RING' or 'NEST'
    kwargs   : Passed to fitsio.write

    Returns:
    --------
    None
    """

    # ADW: Do we want to make everything uppercase?

    if isinstance(data,dict):
        names = list(data.keys())
    else:
        names = data.dtype.names

    if 'PIXEL' not in names:
        msg = "'PIXEL' column not found."
        raise ValueError(msg)

    hdr = header_odict(nside=nside,coord=coord,nest=nest)
    fitshdr = fitsio.FITSHDR(list(hdr.values()))
    if header is not None:
        for k,v in header.items():
            fitshdr.add_record({'name':k,'value':v})
    # ADW: Should this be a debug?

    logger.info("Writing %s..."%filename)