[AstroPy] AstroPy Digest - HDU to Table

Derek Homeier derek at astro.physik.uni-goettingen.de
Wed Apr 17 14:52:23 EDT 2019


On 17 Apr 2019, at 7:41 pm, Christoph Deil <deil.christoph at googlemail.com> wrote:
> 
> if you want a astropy.table.Table object, use Table.read.
> 
> You can pass it a filename, but you can also pass an astropy.io.fits.BinTableHDU object,
> If for some reason you already have it in memory.
> 
> I agree it’s weird that Table.read does this, adding a astropy.io.fits.hdu_to_table function would make this easier to discover.
> Maybe file an issue with Astropy with that suggestion?
> 
Two small clarifications: direct Table initialisation requires the `data` part, e.g.

astropy.table.Table(binhdu.data)

but it still preserves structure and column names of the FITS table. If in addition you want to keep
the complete header information, you need to explicitly pass it to the table.meta data, i.e.

astropy.table.Table(binhdu.data, meta=binhdu.header)

so you may say this still requires a wrapper, but it’s a pretty thin one.

For reading from file I have to add that my understanding of the documentation 
http://docs.astropy.org/en/stable/io/unified.html#keywords
"The FITS keywords associated with an HDU table are represented in the meta ordered dictionary attribute of a Table. “

is actually that Table.read(‘filename.fits’, [hdu=n]) should do this automatically, but in fact,
just like Table() without the meta keyword it ends up with an empty dictionary in table.meta.

This looks indeed like a real issue (either fix the documentation, or better, implement the
functionality it describes).

Cheers,
					Derek



More information about the AstroPy mailing list