ericmandel / pyds9

Python connection to SAOimage DS9 via XPA
76 stars 41 forks source link

3D arrays #59

Closed joeharr4 closed 5 years ago

joeharr4 commented 6 years ago

import numpy as np import pyds9

x = np.zeros((20,200,200)) x.shape

d=pyds9.DS9() d.set_np2arr(x)

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.5/dist-packages/pyds9/pyds9.py", line 760, in set_np2arr (w, h) = narr.shape ValueError: too many values to unpack (expected 2)

But, DS9 natively handles 3D arrays just fine. It gives you a slider to move among the images or play them as a movie. The RO.ds9 package does handle 3D arrays through XPA. Though RO.ds9 does not work in Python 3, this is a proof of concept that it can be done.

Any chance of handling 3D arrays in the future in pyds9 (and any other dimensionalities that DS9 takes)?

Thanks,

--jh--

(Response from Eric Mandel to my email...

Since set_np2arr uses the “array” public access point, and since the “array” public access point supports a zdim, it looks to me like we should be able to add support for 3 dimensions. )

montefra commented 6 years ago

@joeharr4 : it seems a simple enough fix. I'll try to look into is in the next few days.

Two questions:

1) Now the array is set using the following parameters:

    paramlist = 'array [xdim={0},ydim={1},bitpix={2}{3}]'

Would this be correct?

    paramlist = 'array [xdim={0},ydim={1},zdim={2},bitpix={3}{4}]'

2) does it make any sense to support arbitrary dimensions or should I a check that there are either 2 or 3 dimension?

ps: is seems that get_arr2np already supports 3D

ericmandel commented 6 years ago

@montefra DS9's array access point only supports 3 dimensions, so I don't think dim>3 arrays will work. Here is the calling sequence for the array access point:

array [new|mask] [[xdim=<x>,ydim=<y>|dim=<dim>],zdim=<z>,bitpix=<b>,skip=<s>,endian=[little|big]]

taken from: http://ds9.si.edu/doc/ref/xpa.html#array

montefra commented 6 years ago

@joeharr4 : #60 resolves the issue on @ericmandel, my computer and on Travis. If you still have issues, feel free to reopen the issue or open a new one

joeharr4 commented 5 years ago

I'm teaching my astro data analysis class again this semester, so I've tested this on the current astroconda pyds9. Sadly, it appears they don't have your fix:

Python 3.5.6 |Anaconda, Inc.| (default, Aug 26 2018, 21:41:56) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> import pyds9
>>> import astropy.io.fits as fits
>>> x=fits.getdata("SPITZER_I4_20674048_0690_0000_2_bcd.fits")
>>> d=pyds9.DS9()
>>> d.set_np2arr(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jh/miniconda3/envs/astroconda/lib/python3.5/site-packages/pyds9/pyds9.py", line 760, in set_np2arr
    (w, h) = narr.shape
ValueError: too many values to unpack (expected 2)
>>> help(d.set_np2arr)

When I called their ds9 on the FITS file from the shell, it worked perfectly, putting up the image cube slider dialog.

This is with current astroconda, which has version 7.5 of DS9 and pyds9 1.9.dev127, running on Ubuntu 18.04.1, if it matters. The FITS file is a Spitzer IRAC 32x32x64 subarray datacube. It's here:

https://physics.ucf.edu/~jh/fords9/SPITZER_I4_20674048_0690_0000_2_bcd.fits

I'm hoping this is just astroconda being one rev behind. Is it in ds9 7.6, or a later version of pyds9 than 1.9.dev127? It looks like the same pyds9 bug I reported and you fixed last December. The file in astroconda says internally 1.18.1, but is dated 2018-02-14, 2 months after your fix, above, and says 1.9.dev127 in the docs.

Thanks,

--jh--

ericmandel commented 5 years ago

@montefra Can you offer any help/advice here?

joeharr4 commented 5 years ago

Thanks!  Yes, I could have them do a manual install, but I'm trying to teach them to use package managers and to be organized and methodical about their software management, and not to break their managed installs.  Hopefully, this is a simple matter of someone pushing or pulling a single file into astroconda.  Of course, they could also go to the current release.

Thanks,

--jh--

On 09/28/2018 01:43 PM, Eric Mandel wrote:

Reopened #59 https://github.com/ericmandel/pyds9/issues/59.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericmandel/pyds9/issues/59#event-1874093754, or mute the thread https://github.com/notifications/unsubscribe-auth/AByT6TzOz21HCOJ4fOqn3z-pIYFYqRJ2ks5ufl_ZgaJpZM4Qr9Wm.

ericmandel commented 5 years ago

Ultimately I guess there's a work-around that might also be a teachable moment ... but still, sigh ...

joeharr4 commented 5 years ago

Well, it is a class in error analysis! ;-)

--jh--

On 09/28/2018 02:01 PM, Eric Mandel wrote:

Ultimately I guess there's a work-around that might also be a teachable moment ... but still, sigh ...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericmandel/pyds9/issues/59#issuecomment-425518462, or mute the thread https://github.com/notifications/unsubscribe-auth/AByT6cMxSekw981nA2vDqIgKJYWrlBxYks5ufmPzgaJpZM4Qr9Wm.

montefra commented 5 years ago

I don't know which release does Conda use.

Have you tried to install the current master and re-run the above commands? If it fails, then there is still a bug. If it works, conda is not using the latest versions.

joeharr4 commented 5 years ago

I am quite sure it's astroconda's fault.  You guys fixed this a year ago.  I just don't know how to get it into their release.  Do you maintain the DS9 in astroconda?  Do you push it to them?  Whom do I contact there, if not?  I put an issue in both githubs, but nobody responded until I emailed Eric.

Thanks,

--jh--

On 09/28/2018 02:45 PM, Francesco Montesano wrote:

I don't know which release does Conda use.

Have you tried to install the current master and re-run the above commands? If it fails, then there is still a bug. If it works, conda is not using the latest versions.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericmandel/pyds9/issues/59#issuecomment-425530445, or mute the thread https://github.com/notifications/unsubscribe-auth/AByT6fY5lsQ25MvVeZwb_9NmC6wMTwX4ks5ufm49gaJpZM4Qr9Wm.

ericmandel commented 5 years ago

Sorry, I have no idea about who to contact at Astroconda (I'm pretty sure we don't push to them.)

montefra commented 5 years ago

I am not involved with Astroconda. I haven't even ever used it (as far as I remember). I am sorry, but I don't know how to solve this.

joeharr4 commented 5 years ago

ok.  I've contacted Perry Greenfield at STScI.  Hopefully he can help from the astroconda side.  If you use Python much, astroconda seems to be the way a lot of the field is going to manage all the package updates.  It's like a homebrew or apt for personal python installs.

--jh--

On 09/30/2018 03:02 PM, Francesco Montesano wrote:

I am not involved with Astroconda. I haven't even ever used it (as far as I remember). I am sorry, but I don't know how to solve this.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ericmandel/pyds9/issues/59#issuecomment-425743288, or mute the thread https://github.com/notifications/unsubscribe-auth/AByT6WKxC5J7kSTfQIXQ4XoNXRvVt86gks5ugRU8gaJpZM4Qr9Wm.

ericmandel commented 5 years ago

OK, this was useful for me because we have documented the fact that @montefra does not push to external projects, so I can definitively answer a question like this without further help. I'll close this issue now ...