aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-10-09 22:38:30 +0800
committerAaron LI <aaronly.me@outlook.com>2016-10-09 22:38:30 +0800
commitad0eb504996c977df190106229fbbe2b0f25caa6 (patch)
tree9c5927dfaf8b026ec0a7227819d483ffc9ce855d /fg21sim
parent4ce3c0b5ce2bd4b2d2bb89eaae669a4e3eba6662 (diff)
downloadfg21sim-ad0eb504996c977df190106229fbbe2b0f25caa6.tar.bz2
utils/fits.py: read_fits_healpix() also accept HDU
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/utils/fits.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/fg21sim/utils/fits.py b/fg21sim/utils/fits.py
index be5dc68..365ed7e 100644
--- a/fg21sim/utils/fits.py
+++ b/fg21sim/utils/fits.py
@@ -28,12 +28,14 @@ FITS_COLUMN_FORMATS = {
def read_fits_healpix(filename):
- """Read the HEALPix map from a FITS file to 1D array in *RING* ordering.
+ """Read the HEALPix map from a FITS file or a HDU to 1D array
+ in *RING* ordering.
Parameters
----------
- filename : str
- Filename of the HEALPix FITS file
+ filename : str or `~astropy.io.fits.BinTableHDU`
+ Filename of the HEALPix FITS file,
+ or an `~astropy.io.fits.BinTableHDU` instance.
Returns
-------
@@ -48,7 +50,10 @@ def read_fits_healpix(filename):
data array to its original value as in FITS file, as well as return
FITS header as `~astropy.io.fits.Header` instance.
"""
- hdu = fits.open(filename)[0]
+ if isinstance(filename, fits.BinTableHDU):
+ hdu = filename
+ else:
+ hdu = fits.open(filename)[0]
dtype = hdu.data.dtype
header = hdu.header
data = hp.read_map(hdu, nest=False, verbose=False)