[AstroPy] FITS image data dtype

Erik Bray embray at stsci.edu
Wed Jul 17 12:14:16 EDT 2013


On 07/17/2013 11:56 AM, Miguel de Val-Borro wrote:
> Hi,
>
> I have some FITS images that are read with pyfits 3.0.8 and a dtype of
> '>f8'. However I am using an AMD processor and I find some problems when
> handling the data.  I have tried to swap the data byte order and the
> dtype using:
>
>>>> map = hdulist[1].data.byteswap().newbyteorder()
>>>> print map.dtype
> float64
>
> Then the resulting array seems to be fine. Is this what needs to be
> done, and why is pyfits not swapping to the little-endian type based on
> the system architecture?

FITS files store arrays in big-endian order natively.  Actually swapping the 
bytes to native order can be costly, especially when the data is being accessed 
by way of an mmap'd file (the default in PyFITS 3.1 and up).  And it's generally 
unnecessary when working within Numpy--it is only necessary if passing those 
bytes to other software that is expecting values in native byte order.

Erik




More information about the AstroPy mailing list