SmartHDUList¶
-
class
gammapy.utils.fits.SmartHDUList(hdu_list)[source]¶ Bases:
objectA FITS HDU list wrapper with some sugar.
This is a thin wrapper around
HDUList, with some conveniences built in.Parameters: - hdu_list :
HDUList HDU list (stored in
hdu_listattribute)
Examples
Opening a SmartHDUList calls
astropy.io.fits.opento get aHDUListobject, and then stores it away in thehdu_listattribute:>>> from gammapy.utils.fits import SmartHDUList >>> hdus = SmartHDUList.open('$GAMMAPY_DATA/catalogs/fermi/gll_psch_v08.fit.gz') >>> type(hdus.hdu_list) <class 'astropy.io.fits.hdu.hdulist.HDUList'>
So of course, you can do the usual things via
hdus.hdu_list:>>> hdus.hdu_list.filename() >>> hdus.hdu_list.info() >>> [hdu.name for hdu in hdus.hdu_list]
In addition, for a
SmartHDUList, it’s easier to get the HDUs you want:>>> hdus.get_hdu('Extended Sources') # by name >>> hdus.get_hdu(2) # by index >>> hdus.get_hdu(hdu_type='image') # first image (skip primary if empty) >>> hdus.get_hdu(hdu_type='table') # first table
Attributes Summary
namesList of HDU names (stripped, upper-case). Methods Summary
get_hdu(self[, hdu, hdu_type])Get HDU with given name, number or type. get_hdu_index(self[, hdu, hdu_type])Get index of HDU with given name, number or type. open(filename, \*\*kwargs)Create from FITS file ( SmartHDUList).write(self, filename, \*\*kwargs)Write HDU list to FITS file. Attributes Documentation
-
names¶ List of HDU names (stripped, upper-case).
Methods Documentation
-
get_hdu(self, hdu=None, hdu_type=None)[source]¶ Get HDU with given name, number or type.
This method simply calls
get_hdu_index(hdu, hdu_type), and if successful, returns the HDU for that given index.
-
get_hdu_index(self, hdu=None, hdu_type=None)[source]¶ Get index of HDU with given name, number or type.
If
hduis given, tries to find an HDU of that given name or number. Otherwise, ifhdu_typeis given, looks for the first suitable HDU.Raises
KeyErrorif no suitable HDU is found.Parameters: - hdu : int or str
HDU number or name, passed to
astropy.io.fits.HDUList.index_of.- hdu_type : {‘primary’, ‘image’ , ‘table’}
Type of HDU to load
Returns: - idx : int
HDU index
-
classmethod
open(filename, **kwargs)[source]¶ Create from FITS file (
SmartHDUList).This calls
astropy.io.fits.open, passing**kwargs. It reads the FITS headers, but not the data.The
filenameis passed throughmake_path, which accepts strings or Path objects and does environment variable expansion.Parameters: - filename : str
Filename
-
write(self, filename, **kwargs)[source]¶ Write HDU list to FITS file.
This calls
astropy.io.fits.HDUList.writeto, passing**kwargs.The
filenameis passed throughmake_path, which accepts strings or Path objects and does environment variable expansion.Parameters: - filename : str
Filename
- hdu_list :