casacore / python-casacore

Python bindings for casacore, a library used in radio astronomy
http://casacore.github.io/python-casacore
GNU Lesser General Public License v3.0
35 stars 22 forks source link

Incorrect order of axes when accessing coordinates from image #129

Open astrofrog opened 6 years ago

astrofrog commented 6 years ago

I am trying to read in the following image with python-casacore:

https://www.dropbox.com/s/91lx6apur3xq2y0/example_cube.image.tgz?dl=0

The order of the axes should be [RA, Dec, Freq, Stokes] (or [Stokes, Freq, Dec, RA]), and this works in CASA itself:

CASA <19>: ia.open('example_cube.image')
2018-01-19 12:24:51 WARN    image::open (file /Volumes/EXT/bamboohome/xml-data/build-dir/CASA-R511P-POSIERRA/casa/gcwrap/tools/images/image_cmpt.cc, line 3572) Another image is already open, closing first
Out[19]: True

CASA <20>: ia.coordsys().names()
Out[20]: ['Right Ascension', 'Declination', 'Frequency', 'Stokes']

However python-casacore returns neither order, instead swapping Stokes and Frequency:

In [1]: from casacore.images import image

In [2]: im = image('example_cube.image')

In [3]: im.coordinates()
Out[3]: <casacore.images.coordinates.coordinatesystem at 0x10ec80550>

In [4]: im.coordinates().get_axes()
Out[4]: ['Frequency', ['Stokes'], ['Declination', 'Right Ascension']]

Is this a bug? If not, is there a way to get the axes in the same order as the actual data?

gervandiepen commented 5 years ago

This is a feature, not a bug. It is the question of C-order vs Fortran-order. Python is basically C-order, although it supports Fortran-order by defining the strides correctly. However, that lets Python do a transpose of the image cube when doing something with the data. It has been discussed with the CASA group. However, they preferred the Fortran order (as it is in the C++ layer), but python-casacore chose to swap the axes, so it becomes C-order.

So In python-casacore (and mostly also in TaQL) the first axis varies slowest.