spacetelescope / imexam

imexam is a python tool for simple image examination, and plotting, with similar functionality to IRAF's imexamine
http://imexam.readthedocs.io
BSD 3-Clause "New" or "Revised" License
75 stars 45 forks source link

make the ginga viewer work with HDUList objects #170

Closed bsipocz closed 5 years ago

bsipocz commented 5 years ago

As a workaround for #169, I opened the file and fixed it. But then run into the issue that HDULists doesn't have header:

In [30]: a = fits.open('flat.0038.fits')
In [31]: a.verify('fix')

In [32]: viewer.load_fits(a)
2019-05-08 18:45:31,004 | E | ginga_viewer.py:633 (load_fits) | Exception loading image: AttributeError("'HDUList' object has no attribute 'header'")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python3.7/site-packages/imexam/ginga_viewer.py in load_fits(self, fname, extver)
    628                     hdu = shortname
--> 629                 image.load_hdu(hdu)
    630             self._set_frameinfo(fname=shortname, hdu=hdu, image=image)

/usr/local/lib/python3.7/site-packages/ginga/AstroImage.py in load_hdu(self, hdu, fobj, naxispath, inherit_primary_header)
    125         ahdr = self.get_header()
--> 126         self.io.fromHDU(hdu, ahdr)
    127 

/usr/local/lib/python3.7/site-packages/ginga/util/io_fits.py in fromHDU(self, hdu, ahdr)
    101     def fromHDU(self, hdu, ahdr):
--> 102         header = hdu.header
    103         if hasattr(header, 'cards'):

AttributeError: 'HDUList' object has no attribute 'header'

During handling of the above exception, another exception occurred:

Exception                                 Traceback (most recent call last)
<ipython-input-32-8e4edaac4687> in <module>()
----> 1 viewer.load_fits(a)

/usr/local/lib/python3.7/site-packages/imexam/connect.py in load_fits(self, *args, **kwargs)
    400         else:
    401             self.exam._datafile = args[0]
--> 402         self.window.load_fits(*args, **kwargs)
    403 
    404     def load_region(self, *args, **kwargs):

/usr/local/lib/python3.7/site-packages/imexam/ginga_viewer.py in load_fits(self, fname, extver)
    632         except Exception as e:
    633             self.logger.error("Exception loading image: {0}".format(repr(e)))
--> 634             raise Exception(repr(e))
    635 
    636     def panto_image(self, x, y):

Exception: AttributeError("'HDUList' object has no attribute 'header'")

The file itself has a single HDUWorking with just one image HDU: [<astropy.io.fits.hdu.image.PrimaryHDU object at 0x1330a4eb8>] so doing

In [33]: viewer.load_fits(a[0])

works.

I'm not sure how practical it is, but naively I would think opening up all the image HDUs from a HDUList would be a nice feature (or having a default to open the first image hdu but opt in to open all).

sosey commented 5 years ago

ginga wants to use it's own AstroImage() ... but wait, I think I see where I missed a chance to feed it the HDUList.....

sosey commented 5 years ago

fixed in #171