From 679641925217391a1e72304467ede32a57d0082e Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 2 Nov 2019 22:34:51 +0800 Subject: utils/io: Support 'NESTED' ordering in read_fits_healpix() --- fg21sim/utils/io.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'fg21sim') diff --git a/fg21sim/utils/io.py b/fg21sim/utils/io.py index b6719ec..4261f5f 100644 --- a/fg21sim/utils/io.py +++ b/fg21sim/utils/io.py @@ -253,8 +253,7 @@ def write_fits_image(outfile, image, header=None, float32=False, def read_fits_healpix(filename): """ - Read the HEALPix map from a FITS file or a BinTableHDU to 1D array - in *RING* ordering. + Read the HEALPix map from a FITS file or a BinTableHDU to 1D array. Parameters ---------- @@ -282,9 +281,16 @@ def read_fits_healpix(filename): hdu = fits.open(filename)[1] # Hack to ignore the dtype byteorder, use native endianness dtype = np.dtype(hdu.data.field(0).dtype.type) - header = hdu.header - data = hp.read_map(hdu, nest=False, verbose=False) - return (data.astype(dtype), header) + try: + ordering = hdu.header["ORDERING"] + except KeyError: + logger.warning("No 'ORDERING' keyword for file: %s" % filename) + logger.warning("Assume the 'NESTED' ordering") + ordering = "NESTED" + hdu.header["ORDERING"] = ordering + nest = ordering.upper() == "NESTED" + data = hp.read_map(hdu, nest=nest, verbose=False) + return (data.astype(dtype), hdu.header) def write_fits_healpix(outfile, hpmap, header=None, float32=False, -- cgit v1.2.2