diff options
author | Aaron LI <aly@aaronly.me> | 2019-11-02 22:34:51 +0800 |
---|---|---|
committer | Aaron LI <aly@aaronly.me> | 2019-11-02 22:41:39 +0800 |
commit | 679641925217391a1e72304467ede32a57d0082e (patch) | |
tree | 88db504d279f836b2d7ac58c665b510e8f1adb45 /fg21sim/utils | |
parent | 20350055f7f1ad0b3fe8a2f27fc21d29ed3ac71e (diff) | |
download | fg21sim-679641925217391a1e72304467ede32a57d0082e.tar.bz2 |
utils/io: Support 'NESTED' ordering in read_fits_healpix()
Diffstat (limited to 'fg21sim/utils')
-rw-r--r-- | fg21sim/utils/io.py | 16 |
1 files changed, 11 insertions, 5 deletions
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, |