-1

I am having a problem, with python, pyfits and numpy. I am opening a fits file with the usual

file = pyfits.open('file.fits', memap = True)

when calling

file.info()

It shows me, that the dataset contained has the shape (2,1024,1024,546):

No.    Name         Type      Cards   Dimensions   Format
0    PRIMARY     PrimaryHDU      12   (2, 1024, 1024, 546)   float32

then, I go ahead and import this array into a numpy array via

data = file[0].data

when I then want to show the shape of this array, using

print (data.shape)

it shows the shape

(546,1024,1024,2)

I have no Idea, why it is doing so. It is important to know which dimension belongs to which axis.

Any help is appreciated! Thank you very much.

HenrikWolf
  • 21
  • 4

1 Answers1

1

See http://docs.astropy.org/en/stable/io/fits/appendix/faq.html#what-convention-does-astropy-use-for-indexing-such-as-of-image-coordinates

FITS axes (as shown in the .info()) method, as ordered in the NAXISn keywords, are in FORTRAN order. Numpy, which is based on Python, which in turn is based on C uses C ordered axes.

(As an aside, please be aware that the stand-alone pyfits module is deprecate, and astropy.io.fits should be used instead).

Iguananaut
  • 15,675
  • 4
  • 43
  • 50