def read_fits_healpix(filename):
"""
Read the HEALPix map from a FITS file or a BinTableHDU to 1D array
in *RING* ordering.
Parameters
----------
filename : str or `~astropy.io.fits.BinTableHDU`
Filename of the HEALPix FITS file,
or an `~astropy.io.fits.BinTableHDU` instance.
Returns
-------
data : 1D `~numpy.ndarray`
HEALPix data in *RING* ordering with same dtype as input
header : `~astropy.io.fits.Header`
Header of the input FITS file
NOTE
----
This function wraps on `healpy.read_map()`, but set the data type of
data array to its original value as in FITS file, as well as return
the header of input FITS file.
"""
if isinstance(filename, fits.BinTableHDU):
hdu = filename
else:
# Read the first extended table
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)
评论列表
文章目录