Update SkyCube.read a bit
@@ -19,7 +19,7 @@ from astropy.wcs import WCS
from astropy.utils import lazyproperty
from ..utils.scripts import make_path
from ..utils.energy import EnergyBounds, Energy
-from ..utils.fits import table_to_fits_table
+from ..utils.fits import SmartHDUList, fits_header_to_meta_dict, table_to_fits_table
from ..image import SkyImage
from ..spectrum import LogEnergyAxis
from ..spectrum.utils import _trapz_loglog
@@ -148,12 +148,13 @@ class SkyCube(object):
Sky cube
"""
filename = str(make_path(filename))
+ hdu_list = SmartHDUList.open(filename)
+ hdu = hdu_list.get_hdu(hdu_type='image')
- data = fits.getdata(filename)
- header = fits.getheader(filename)
-
+ header = hdu.header
wcs = WCS(header).celestial
- meta = OrderedDict(header)
+ meta = fits_header_to_meta_dict(header)
+ data = hdu.data
# TODO: check and give reference for fermi data units
# TODO: choose format automatically
@@ -175,7 +176,9 @@ class SkyCube(object):
else:
raise ValueError('Not a valid cube fits format')
- return cls(name=name, data=data, wcs=wcs, energy_axis=energy_axis, meta=meta)
+ obj = cls(name=name, data=data, wcs=wcs, energy_axis=energy_axis, meta=meta)
+ obj._header = header
+ return obj
def fill_events(self, events, weights=None):
"""
