[AstroPy] Adding a column to a FITS binary HDU

Alberto alberto.manfreda at pi.infn.it
Fri Jan 15 11:45:41 EST 2021


Hi,

despite I have been using astropy.io for a few years now, this is my 
first message to the list (which speaks highly of the quality of the 
module and of the documentation - great job, really!). Recently, 
however, I found myself stuck doing an apparently simple task. I have a 
FITS file containing a bunch of binary HDU tables, which I open with the:

hdu_list = open_event_file('/file_path/')

command. I need to add a new column to one of the HDU tables, then write 
the entire hdu_list to a different file location.

What is the simplest way to do this? The methods for adding columns that 
I found in the online FAQs work for Table objects, but what I can get 
from my hdu_list is a BinTableHDU object, which doesn't support 
dictionary-like assignment or the add_column() method. I know I can get 
a Table object from the hdu_list like this:

table = Table(hdu_list[1].data)

but this is a copy, so the changes to the table does not apply to the 
original hdu_list.

Any help is appreciated.

Kind Regards

Alberto

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/astropy/attachments/20210115/65adf915/attachment.html>


More information about the AstroPy mailing list