Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

3D arrays #59

Closed
joeharr4 opened this issue Nov 27, 2017 · 14 comments
Closed

3D arrays #59

joeharr4 opened this issue Nov 27, 2017 · 14 comments
Assignees
Labels
Milestone

Comments

@joeharr4
Copy link

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
Copy link
Contributor

@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}]'
  1. 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
Copy link
Owner

@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 montefra self-assigned this Nov 28, 2017
@montefra montefra added the bug label Nov 28, 2017
@montefra montefra added this to the 1.9 milestone Nov 28, 2017
montefra added a commit that referenced this issue Dec 13, 2017
Add support for 3D numpy arrays (issue #59)
@montefra
Copy link
Contributor

@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
Copy link
Author

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
Copy link
Owner

@montefra Can you offer any help/advice here?

@ericmandel ericmandel reopened this Sep 28, 2018
@joeharr4
Copy link
Author

joeharr4 commented Sep 28, 2018 via email

@ericmandel
Copy link
Owner

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

@joeharr4
Copy link
Author

joeharr4 commented Sep 28, 2018 via email

@montefra
Copy link
Contributor

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
Copy link
Author

joeharr4 commented Sep 28, 2018 via email

@ericmandel
Copy link
Owner

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

@montefra
Copy link
Contributor

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
Copy link
Author

joeharr4 commented Oct 1, 2018 via email

@ericmandel
Copy link
Owner

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 ...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants