Adding a new column to a FITS file via python

2.8k Views Asked by At

I have created an array named distance that contains 1242 values. I want to add this array as the 11th column in an already existing FITS file that contains 10 columns.

I am using pyfits.

I tried pyfits.append(filename, distance) which showed no errors but did not add my column to the FITS file.

Any suggestions??

1

There are 1 best solutions below

0
On

Finally they released an updated library that allows the modification of a table extension in a human way!

Last release of FITSIO. You can easily add a column with a code looking like the following:

import fitsio
from fitsio import FITS,FITSHDR
...
fits = FITS('file.fits','rw')
fits[-1].insert_column(name = 'newcolumn', data = mydata)      # add the extra column
fits.close()