[AstroPy] AstroPy Digest - HDU to Table

Derek Homeier derek at astro.physik.uni-goettingen.de
Wed Apr 17 18:41:40 EDT 2019


On 17 Apr 2019, at 8:52 pm, Derek Homeier <derek at astro.physik.uni-goettingen.de> wrote:
> 
> 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.
> 
I stand corrected here: Table.read() does store the header cards in the meta attribute,
after stripping the functional keywords defining the table itself and a couple of other blacklisted
cards - which just happened to be *all* of the cards in some of the test files in the distribution.
In contrast, this works as expected:

>>> chandra = Table.read('https://github.com/astropy/astropy/blob/master/astropy/io/fits/tests/data/chandra_time.fits?raw=true’)
>>> chandra.meta['TITLE']
Multiwavelength Characterization of Candidate Black Holes in Nearby Dwarf Galaxies

Cheers,
				Derek



More information about the AstroPy mailing list