# Path: ugali/utils/healpix.py
# def superpixel(subpix, nside_subpix, nside_superpix):
# def subpixel(superpix, nside_superpix, nside_subpix):
# def d_grade_ipix(ipix, nside_in, nside_out, nest=False):
# def u_grade_ipix(ipix, nside_in, nside_out, nest=False):
# def ud_grade_ipix(ipix, nside_in, nside_out, nest=False):
# def phi2lon(phi): return np.degrees(phi)
# def lon2phi(lon): return np.radians(lon)
# def theta2lat(theta): return 90. - np.degrees(theta)
# def lat2theta(lat): return np.radians(90. - lat)
# def pix2ang(nside, pix, nest=False):
# def ang2pix(nside, lon, lat, nest=False):
# def ang2vec(lon, lat):
# def get_nside(m):
# def healpixMap(nside, lon, lat, fill_value=0., nest=False):
# def in_pixels(lon,lat,pixels,nside):
# def index_pix_in_pixels(pix,pixels,sort=False,outside=-1):
# def index_lonlat_in_pixels(lon,lat,pixels,nside,sort=False,outside=-1):
# def query_disc(nside, vec, radius, inclusive=False, fact=4, nest=False):
# def ang2disc(nside, lon, lat, radius, inclusive=False, fact=4, nest=False):
# def get_interp_val(m, lon, lat, *args, **kwargs):
# def header_odict(nside,nest=False,coord=None, partial=True):
# def write_partial_map(filename, data, nside, coord=None, nest=False,
#                       header=None,dtype=None,**kwargs):
# def read_partial_map(filenames, column, fullsky=True, **kwargs):
# def merge_partial_maps(filenames,outfile,**kwargs):
# def merge_likelihood_headers(filenames, outfile, **kwargs):
# def merge_likelihood_headers2(filenames, outfile, **kwargs):
# def read_map(filename, nest=False, hdu=None, h=False, verbose=True):
# 
# 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 unittest
import numpy as np
import healpy as hp
import fitsio
from ugali.utils import healpix
from ugali.utils.logger import logger
                              [ 43361200,  43361201,  43361202,  43361203],
                              [142027176, 142027177, 142027178, 142027179]])
DU_GRADE_PIX_RING = np.array([[104582830, 104566446, 104566445, 104550062],
                              [ 43393971,  43377587,  43377586,  43361203],
                              [142059946, 142043562, 142043561, 142027178]])



class TestHealpix(unittest.TestCase):
    """Test healpix module"""

    def test_ud_grade_ipix(self):

        # Same NSIDE
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE),PIX)

        # Increase resolution (u_grade)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE*2,nest=True),
                                U_GRADE_PIX_NEST)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE*2),
                                U_GRADE_PIX_RING) 

        # Decrease resolution (d_grade)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE//2,nest=True),
                                D_GRADE_PIX_NEST)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE//2),
                                D_GRADE_PIX_RING)


        # u_grade then d_grade

# Path: ugali/utils/healpix.py
# def superpixel(subpix, nside_subpix, nside_superpix):
# def subpixel(superpix, nside_superpix, nside_subpix):
# def d_grade_ipix(ipix, nside_in, nside_out, nest=False):
# def u_grade_ipix(ipix, nside_in, nside_out, nest=False):
# def ud_grade_ipix(ipix, nside_in, nside_out, nest=False):
# def phi2lon(phi): return np.degrees(phi)
# def lon2phi(lon): return np.radians(lon)
# def theta2lat(theta): return 90. - np.degrees(theta)
# def lat2theta(lat): return np.radians(90. - lat)
# def pix2ang(nside, pix, nest=False):
# def ang2pix(nside, lon, lat, nest=False):
# def ang2vec(lon, lat):
# def get_nside(m):
# def healpixMap(nside, lon, lat, fill_value=0., nest=False):
# def in_pixels(lon,lat,pixels,nside):
# def index_pix_in_pixels(pix,pixels,sort=False,outside=-1):
# def index_lonlat_in_pixels(lon,lat,pixels,nside,sort=False,outside=-1):
# def query_disc(nside, vec, radius, inclusive=False, fact=4, nest=False):
# def ang2disc(nside, lon, lat, radius, inclusive=False, fact=4, nest=False):
# def get_interp_val(m, lon, lat, *args, **kwargs):
# def header_odict(nside,nest=False,coord=None, partial=True):
# def write_partial_map(filename, data, nside, coord=None, nest=False,
#                       header=None,dtype=None,**kwargs):
# def read_partial_map(filenames, column, fullsky=True, **kwargs):
# def merge_partial_maps(filenames,outfile,**kwargs):
# def merge_likelihood_headers(filenames, outfile, **kwargs):
# def merge_likelihood_headers2(filenames, outfile, **kwargs):
# def read_map(filename, nest=False, hdu=None, h=False, verbose=True):
# 
# 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: tests/test_healpix.py
import unittest
import numpy as np
import healpy as hp
import fitsio
from ugali.utils import healpix
from ugali.utils.logger import logger

                              [ 43361200,  43361201,  43361202,  43361203],
                              [142027176, 142027177, 142027178, 142027179]])
DU_GRADE_PIX_RING = np.array([[104582830, 104566446, 104566445, 104550062],
                              [ 43393971,  43377587,  43377586,  43361203],
                              [142059946, 142043562, 142043561, 142027178]])



class TestHealpix(unittest.TestCase):
    """Test healpix module"""

    def test_ud_grade_ipix(self):

        # Same NSIDE
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE),PIX)

        # Increase resolution (u_grade)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE*2,nest=True),
                                U_GRADE_PIX_NEST)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE*2),
                                U_GRADE_PIX_RING) 

        # Decrease resolution (d_grade)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE//2,nest=True),
                                D_GRADE_PIX_NEST)
        np.testing.assert_equal(healpix.ud_grade_ipix(PIX,NSIDE,NSIDE//2),
                                D_GRADE_PIX_RING)


        # u_grade then d_grade

        np.testing.assert_equal(healpix.ud_grade_ipix(