Astro-GuiGeek Astro-GuiGeek - 3 years ago 101
Python Question

How to convert (or scale) a FIT image with Astropy

Using the Astropy library, I created a FIT image which is made by interpolation from 2 actual FIT images (they are scaled as "int16", the right format for the software I use : Maxim DL).

But the scale of this image is float64 and not int16. And any astronomical processing software can't read it (except FITS Liberator)

Do you have an idea how to proceed ? Can we convert a FIT image just by changing the "BITPIX" in the header ?

I tried: (following this method : Why is an image containing integer data being converted unexpectedly to floats?

from import fits'')
print(image.header['BITPIX']) # it gives : -64

print(image.header['BITPIX']) # it gives : 16

However, when I check the newly-modified scale of "", it still displays -64 !
No change was saved and applied!

Answer Source

If I understand your problem correctly, this should work.

from import fits
import numpy as np

# create dummy fits file
a = np.array([[1,2,3],

hdu = fits.PrimaryHDU() = a

# looking at the header object confirms BITPIX = -64

# change data type = np.int16(

# look again to confirm BITPIX = 16
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download