我正在尝试使用下面的代码为 FITS 文件中的像素设置阈值。但是,我收到一条错误消息:
IndexError: Index 2620 is out of bounds for axis 0 with size 2620
有想法该怎么解决这个吗?
这是代码:
from astropy.io import fits
import numpy as np
hdulist = fits.open("12ratio.fits")
origImData = hdulist[0].data
newImData = origImData*0
for x, y in np.nditer(origImData.shape):
curPixel = origImData[x, y]
if curPixel > 0.28 or curPixel < 3.11:
newImData[x, y] = curPixel
else:
newImData[x, y] = 0
newhdu = fits.PrimaryHDU(newImData)
newhdulist = fits.HDUList([newhdu])
newhdulist.writeto('modifiedratio12.fits')