I’m attempting to instantiate a simple ASCII HDU, but it doesn’t seem to work the same way as astropy.io.fits.BinTableHDU . For example, this works just fine:
In your example you might also instantiate it directly from the previously written table
with fits.open('binary_test.fits') as hdulist:
hdu = TableHDU(data=hdulist[1].data, name='MY_ASCII_HDU')
but that is probably not very helpful in the general case.
The docstring for that class is a bit confusing as there seems to be almost no other way to instantiate it through the data parameter, but the ASCII table format is rarely used.
TableHDU.from_columns as explained in the link above is probably the most useful way to create it; it should also directly handle numpy structured arrays, if that is more convenient.
Thanks, this is a huge help. I think this is exactly what I was looking for. It would be nice however if astropy used the same interface for both kinds of tables, that would help to encapsulate many of these details. Although… perhaps it’s better to use the fits Column method in both instances?
The Table to TableHDU interface doesn’t exist because ASCII table are not so common, binary table are much more used.
So on one side there is the API from astropy.io.fits, for ASCII and binary tables :