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

ds9.view cannot handle cubes #101

Closed stscieisenhamer closed 6 years ago

stscieisenhamer commented 7 years ago

If ds9.view is passed a cube, it fails. However, said cube can be loaded through reading a fits file.

>>> rancube = np.ones([50, 50, 50]) * np.random.rand(50)
>>> viewer.view(rancube)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/Users/eisenham/anaconda3/envs/jwstdevpy3/lib/python3.5/site-packages/imexam-0.7.2.dev307-py3.5-macosx-10.6-x86_64.egg/imexam/ds9_viewer.py in view(self, img)
   1706             try:
-> 1707                 img.shape = img.shape[-2:]
   1708             except:

ValueError: total size of new array must be unchanged

During handling of the above exception, another exception occurred:

UnsupportedImageShapeException            Traceback (most recent call last)
<ipython-input-25-97c9b56f0697> in <module>()
----> 1 viewer.view(rancube)

/Users/eisenham/anaconda3/envs/jwstdevpy3/lib/python3.5/site-packages/imexam-0.7.2.dev307-py3.5-macosx-10.6-x86_64.egg/imexam/connect.py in view(self, *args, **kwargs)
    487             self.window.view(args[0].data)  # when not specified
    488         else:
--> 489             self.window.view(*args, **kwargs)
    490
    491     def zoom(self, *args, **kwargs):

/Users/eisenham/anaconda3/envs/jwstdevpy3/lib/python3.5/site-packages/imexam-0.7.2.dev307-py3.5-macosx-10.6-x86_64.egg/imexam/ds9_viewer.py in view(self, img)
   1707                 img.shape = img.shape[-2:]
   1708             except:
-> 1709                 raise UnsupportedImageShapeException(repr(img.shape))
   1710
   1711             if img.dtype.byteorder in ["=", "|"]:

UnsupportedImageShapeException: (50, 50, 50)
>>> from astropy.io import fits
>>> fits.writeto('rancube.fits', rancube)
>>> viewer.load_fits('rancube.fits')
--------> OK
jemorrison commented 7 years ago

Is 'cube' here an IFUCube (output from cube_build) or a raw cube of data that is input for the sloper ?

Jane On 03/01/2017 10:28 AM, Jonathan Eisenhamer wrote:

If ds9.view is passed a cube, it fails. However, said cube can be loaded through reading a fits file.

>>> rancube = np.ones([50, 50, 50]) * np.random.rand(50) >>> viewer.view(rancube)

ValueError Traceback (most recent call last) /Users/eisenham/anaconda3/envs/jwstdevpy3/lib/python3.5/site-packages/imexam-0.7.2.dev307-py3.5-macosx-10.6-x86_64.egg/imexam/ds9_viewer.py in view(self, img) 1706 try: -> 1707 img.shape = img.shape[-2:] 1708 except: ValueError: total size of new array must be unchanged During handling of the above exception, another exception occurred: UnsupportedImageShapeException Traceback (most recent call last)

in () ----> 1 viewer.view(rancube) /Users/eisenham/anaconda3/envs/jwstdevpy3/lib/python3.5/site-packages/imexam-0.7.2.dev307-py3.5-macosx-10.6-x86_64.egg/imexam/connect.py in view(self, *args, **kwargs) 487 self.window.view(args[0].data) # when not specified 488 else: --> 489 self.window.view(*args, **kwargs) 490 491 def zoom(self, *args, **kwargs): /Users/eisenham/anaconda3/envs/jwstdevpy3/lib/python3.5/site-packages/imexam-0.7.2.dev307-py3.5-macosx-10.6-x86_64.egg/imexam/ds9_viewer.py in view(self, img) 1707 img.shape = img.shape[-2:] 1708 except: -> 1709 raise UnsupportedImageShapeException(repr(img.shape)) 1710 1711 if img.dtype.byteorder in ["=", "|"]: UnsupportedImageShapeException: (50, 50, 50) >>> from astropy.io import fits >>> fits.writeto('rancube.fits', rancube) >>> viewer.load_fits('rancube.fits') --------> OK | — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub , or mute the thread .
sosey commented 7 years ago

right...because there's a cube loader that works with ds9: viewer.load_mef_as_cube('cube.fits'), because ds9 has to know it's loading a cube fits image. load_fits() calls a different XPA function than load_mef_as_cube.

but the view() class hasn't been expanded to work with a cubed data array in 3D on disk, but it will display the 2D slice: viewer.view(rancube[0]) into ds9, and it keeps track of what's in that frame:

In [56]: a.get_frame_info()
Out[56]: 
{'extname': None,
 'extver': None,
 'filename': None,
 'iscube': False,
 'mef': False,
 'naxis': 0,
 'numaxis': 2,
 'user_array': array([[ 0.27419013,  0.79941412,  0.34257855, ...,  0.13473738,
          0.6688091 ,  0.89239826],
        [ 0.27419013,  0.79941412,  0.34257855, ...,  0.13473738,
          0.6688091 ,  0.89239826],
        [ 0.27419013,  0.79941412,  0.34257855, ...,  0.13473738,
          0.6688091 ,  0.89239826],
        ..., 
        [ 0.27419013,  0.79941412,  0.34257855, ...,  0.13473738,
          0.6688091 ,  0.89239826],
        [ 0.27419013,  0.79941412,  0.34257855, ...,  0.13473738,
          0.6688091 ,  0.89239826],
        [ 0.27419013,  0.79941412,  0.34257855, ...,  0.13473738,
          0.6688091 ,  0.89239826]])}
sosey commented 7 years ago

Example: http://imexam.readthedocs.io/en/v0.7.0/imexam/examples.html#load-and-examine-an-image-cube

what I said above about cube loading in ds9 wasn't entirely correct, you can load a cube with load_fits() in imexam, you can also load an MEF fits file as a cube and load a cube with load_mef_as_cube.... I don't have a cube fits image handy at the moment though...

sosey commented 7 years ago

found one! documentation on these should be expanded:

load_mef_as_cube() : nope, just use it to load MEF fits files, with 2d arrays, into one frame load_fits(): works with cubes and regular fits images load_mef_as_multi(): load an MEF fits file into multiple frames where each 2d array extension gets a different frame

I'm not sure the best way to take a local cube and display in DS9 as a cube, will have to look into that unless you'd like to :)

stscieisenhamer commented 7 years ago

Expanding ds9 isn't on the todo list :-)

What I was looking for was the equivalent behavior between load_fits and view. When load_fits gets a cube, it sets up the slice tool (maybe its doing multiple frames?). I would presume view would behave the same way. But maybe not.

Back to the ds9 issue: ya, it doesn't do cube, so not much expected, and from my (our) end, the work will be going into another viewer anyways.

stscieisenhamer commented 7 years ago

@jemorrison the one i happen to have is a CubeModel, but there is nothing specific. I'll run through the other ones to see if the behavior is the same; I didn't try because none of the documentation read what I was seeing ds9 do with load_fits.

sosey commented 7 years ago

yah, we don't want to touch the ds9 and xpa code ..... :fearful:

when load_fits() is sent a cube (really, ds9 is making the distinction here, it's the same call) then ds9 sets up the cube slider.

when view() gets a cube, the user needs to specify the slice by giving view the 2d array. view(rancube[0]) would show one slice in one frame. I haven't setup view() to know how to load into the cube dialog into ds9, it may not be hard, dunno

stscieisenhamer commented 7 years ago

oooooh, a bug and enhancement. 👍

sosey commented 7 years ago

yah, it's bug-ish, imexam returned the correct error that you gave it a 3d array and it wasn't expecting that, but it could be clearer, and could also be made to accept 3d cubes :smiley:

sosey commented 7 years ago

see https://github.com/spacetelescope/imexam/pull/102