I am attempting to set a threshold for pixels in a FITS file using the code below. However, I get an error that says that:
IndexError: Index 2620 is out of bounds for axis 0 with size 2620
Any ideas on how to fix this?
This is the code:
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')