# How to edit a FITS file import pyfits import os # Change to directory where script is located abspath = os.path.abspath(__file__) dname = os.path.dirname(abspath) os.chdir(dname) # Method 1 - alter the original FITS file FitsFile = pyfits.open('M33.fits',mode='update') #image = FitsFile[0].data #image[:,:,:] = 5.0 #FitsFile.flush() #FitsFile.close() # Method 2 - create a new FITS file #FitsFile = pyfits.open('M33.fits') # #image = FitsFile[0].data #header = FitsFile[0].header # #image[:,:,:] = 5.0 # #pyfits.writeto('testfile.fits',image, header) # Editing a header value - does NOT work on naxis keyword ! header= FitsFile[0].header header['CRPIX1'] = 13 image = FitsFile[0].data pyfits.writeto('testfile.fits',image, header)