[英]How to convert (or scale) a FITS image with Astropy
Using the Astropy library, I created a FITS image which is made by interpolation from 2 actual FITS images (they are scaled as " int16 ", the right format for the software I use : Maxim DL). 使用Astropy库,我创建了一个FITS图像,该图像是通过从2个实际FITS图像进行插值得到的(它们缩放为“ int16 ”,这是我使用的软件的正确格式:Maxim DL)。
But the scale of this image is float64 and not int16 . 但是此图像的比例是float64而不是int16 。 And any astronomical processing software can't read it (except FITS Liberator)
而且任何天文处理软件都无法读取(FITS Liberator除外)
Do you have an idea how to proceed ? 你有一个想法如何进行? Can we convert a FITS image just by changing the "BITPIX" in the header ?
我们可以仅通过更改标题中的“ BITPIX”来转换FITS图像吗?
I tried: (following this method : Why is an image containing integer data being converted unexpectedly to floats? 我尝试过:(遵循此方法: 为什么包含整数数据的图像意外地转换为浮点数?
from astropy.io import fits
hdu1=fits.open('mypicture.fit')
image=hdu1[0]
print(image.header['BITPIX']) # it gives : -64
image.scale('int16')
data=image.data
data.dtype
print(image.header['BITPIX']) # it gives : 16
hdu1.close()
However, when I check the newly-modified scale of "mypicture.fit", it still displays -64 ! 但是,当我检查新修改的“ mypicture.fit”比例时, 它仍显示-64 ! No change was saved and applied!
没有更改已保存并应用!
If I understand your problem correctly, this should work. 如果我正确理解您的问题,则应该可以。
from astropy.io import fits
import numpy as np
# create dummy fits file
a = np.array([[1,2,3],
[4,5,6],
[7,8,9]],dtype=np.float64)
hdu = fits.PrimaryHDU()
hdu.data = a
# looking at the header object confirms BITPIX = -64
hdu.header
# change data type
hdu.data = np.int16(hdu.data)
# look again to confirm BITPIX = 16
hdu.header
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.