From ad0eb504996c977df190106229fbbe2b0f25caa6 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 9 Oct 2016 22:38:30 +0800 Subject: utils/fits.py: read_fits_healpix() also accept HDU --- fg21sim/utils/fits.py | 13 +++++++++---- 1 file 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) -- cgit v1.2.2