ericmandel / pyds9

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

Test numpy<->ds9 with 3D arrays (issue #59) [skip appveyor] #60

Closed montefra closed 6 years ago

montefra commented 6 years ago

This PR addresses issue #59

I have added a test_3d.fits file replicating 3 times the test.fits in the z-direction. This should be enough to test the problem

montefra commented 6 years ago

@ericmandel : commit aa73eae28ccdeed20c8d2af150c7d17466194d7a should solve issue #59 .

However when creating a 3D array I came across the fact that python uses C ordering while fits uses Fortran ordering.

This means that:

numpy shape NAXIS1 NAXIS2 NAXIS 3
(10, 8) 8 10
(3, 10, 8) 8 10 3

So I:

  1. replaced the symmetric 15 x 15 test fist with asymmetric 8x10 fits images
  2. flipped xdim/ydim the set_np2arr function.

get_arr2np already does the correct thing.

If you want to double check the ordering open python/ipython and do:

In [1]: from astropy.io import fits
In [2]: hdus = fits.open('my/fits/file')
In [3]: hdus[0].data.shape
In [4]: hdus[0].header

Can you please check the changes?

ericmandel commented 6 years ago

I tested this on a real data cube and it looks like it does what you want:

screen shot 2017-12-13 at 3 21 44 pm

However, I can't comment on whether this is what numpy users expect, since I don't use Python/numpy. I think you should merge the PR but just keep in the back of your mind that there might be questions.

montefra commented 6 years ago

Thank you for checking. As I wrote, I think that this is the expected behaviour. Anyway I'll keep in mind

ericmandel commented 6 years ago

I'm confident you have it right. My comment is rooted in the fact that several years ago, I had it coded one way and then was told it needed to be the other way. So clearly I don't know which end is up with numpy!

montefra commented 6 years ago

So clearly I don't know which end is up with numpy!

I also never remember which way is numpy indexed. I always end up in a ipython session to do some test.