diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-10-09 22:38:30 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-10-09 22:38:30 +0800 |
commit | ad0eb504996c977df190106229fbbe2b0f25caa6 (patch) | |
tree | 9c5927dfaf8b026ec0a7227819d483ffc9ce855d /fg21sim/utils | |
parent | 4ce3c0b5ce2bd4b2d2bb89eaae669a4e3eba6662 (diff) | |
download | fg21sim-ad0eb504996c977df190106229fbbe2b0f25caa6.tar.bz2 |
utils/fits.py: read_fits_healpix() also accept HDU
Diffstat (limited to 'fg21sim/utils')
-rw-r--r-- | fg21sim/utils/fits.py | 13 |
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) |