如何用Astropy转换(或缩放)FITS图像

2024-10-01 09:20:05 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Astropy库,我创建了一个FITS图像,该图像由2个实际FITS图像插值而成(它们被缩放为“int16”,这是我使用的软件的正确格式:Maxim DL)。在

但是此图像的比例是float64,而不是int16。任何天文处理软件都无法读取(除了适合解放者)

你知道该怎么做吗?我们可以通过改变标题中的“BITPIX”来转换FITS图像吗?在

我试过:(按照这个方法:appendix/faq.html#why-is-an-image-containing-integer-data-being-converted-unexpectedly-to-floats" rel="nofollow noreferrer">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()

但是,当我检查新修改的比例我的图片.fit“,它仍然显示-64! 没有保存和应用任何更改!在


Tags: 图像imageandataisinteger比例converted
1条回答
网友
1楼 · 发布于 2024-10-01 09:20:05

如果我没弄错你的问题,这应该行得通。在

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

相关问题 更多 >