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
74 stars 45 forks source link

load_fits() XPA error, and subsequent imexam() error #247

Closed vrijmoet closed 2 years ago

vrijmoet commented 2 years ago

I'm having two issues, but maybe they are related.

(1) When I use load_fits() to open an image in ds9, it gives me an XpaException:

>>> import imexam
Ginga not installed, use other viewer, or no viewer
photutils not installed, photometry functionality in imexam() not available
>>> viewer = imexam.connect('testy')
>>> viewer.load_fits('20201204.09.056.o.fits')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/imexam/connect.py", line 393, in load_fits
    self.window.load_fits(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/imexam/ds9_viewer.py", line 1180, in load_fits
    self.set(cstring)
  File "/usr/local/lib/python3.6/site-packages/imexam/ds9_viewer.py", line 667, in set
    self.xpa.set(param, buf)
  File "/usr/local/lib/python3.6/site-packages/imexam/xpa_wrap.py", line 18, in set
    super(XPA, self).set(param.encode('utf-8', 'strict'), buf)
  File "wrappers/xpa.pyx", line 177, in imexam.imexamxpa.xpa.set
  File "wrappers/xpa.pyx", line 147, in imexam.imexamxpa._set
imexam.imexamxpa.XpaException: b'XPA$ERROR Unable to load fits  image /nfs/morgan/users/vrijmoet/pypline.atgsu/20201204.09.056.o.fits[0] (DS9:testy a33c518:39455)\n'

(my image is '20201204.09.056.o.fits' and my ds9 window is titled 'testy'. The path in the last line is where I am running my session) I can get around this issue if I first load the image with astropy.io.fits:

>>> from astropy.io import fits
>>> hdul = fits.open('20201204.09.056.o.fits')
>>> viewer.load_fits(hdul)

Then the image shows up in ds9 and looks good. So, no big deal.

(2) But then when I use imexam() on it, there is a more major error:

>>> viewer.imexam()

Press 'q' to quit

2 Make the next plot in a new window
a Aperture sum, with radius region_size 
b Return the 2D gauss fit center of the object
c Return column plot
d Return the Center of Mass fit center of the object
e Return a contour plot in a region around the cursor
g Return curve of growth plot
h Return a histogram in the region around the cursor
j 1D [Gaussian1D default] line fit 
k 1D [Gaussian1D default] column fit
l Return line plot
m Square region stats, in [region_size],default is median
r Return the radial profile plot
s Save current figure to disk as [plot_name]
t Make a fits image cutout using pointer location
w Display a surface plot around the cursor location
x Return x,y,value of pixel
y Return x,y,value of pixel
Current image None
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/imexam/connect.py", line 150, in imexam
    self._run_imexam()
  File "/usr/local/lib/python3.6/site-packages/imexam/connect.py", line 242, in _run_imexam
    x, y, current_key = self.readcursor()
  File "/usr/local/lib/python3.6/site-packages/imexam/connect.py", line 303, in readcursor
    return self.window.readcursor()
  File "/usr/local/lib/python3.6/site-packages/imexam/ds9_viewer.py", line 701, in readcursor
    k, x, y = xpa_string.split()
ValueError: not enough values to unpack (expected 3, got 0)

Is there any chance I'm getting the second error because of how I'm avoiding the first error?

And is there something else I could try to narrow down what's going wrong? I have tried the suggestions on the "Common Problems" page, and I have tried the above sequence in a script as well as an interactive session.

vrijmoet commented 2 years ago

After some extensive testing, I'm pretty sure this issue is just our ds9 being very out of date.

The most recent version of ds9 is 8.3, but our installed version is 3.3 (from ~2003?). I installed ds9 8.3, XPA, and imexam on another machine, and everything works flawlessly.