[AstroPy] issue with initialisation of a fits binary table

Erik Bray embray at stsci.edu
Mon Sep 8 09:59:54 EDT 2014


On 09/04/2014 09:24 PM, Paul Kuin wrote:
> Hi,
>
> I have a question about io.fits
>
> I wonder if I just miss something obvious, or it can only be done as a later
> fix. Let me explain my problem.
>
> When adding a card to the header, I can do that as
>
> header["NEW_KEY"]=("SOME_VALUE","this is an example")
> and in the header I get
> NEW_KEY = "SOME_VALUE"   \ this is an example
>
> So with a keyword.
>
> Now, when I define a new column like
>
> col = [fits.Column(name="Vmag",format="E",unit="mag",ascii=False)]
> I can create a binary table
> tab = fits.BinTableHDU.from_columns(columns=col)
>
> The header then is created with a TTYPE keyword with a value, but without a comment.
> Comments are sometimes very useful, and so I checked.
>
> I can define
> col = [fits.Column(name=("Vmag","some comment"),format="E",unit="mag",ascii=False)]
> which goes some way to being able to have a TTYPE keyword with value and comment,
> but then trying to create the binary table HDU as before, it fails.
>
> Am I missing something?
>
> I can probably go back in and modify the header to add comments once I have the
> bintable HDU defined, but it seems so inelegant I did not even try.

Just set

header.comments['TTYPE'] = 'Whatever'

after the fact.  Indeed, comments are nice to have, but they're mostly 
orthogonal to the actual structure of FITS files which we're trying to abstract 
away as much as possible.

If/when the FITS Schema infrastructure I've been working on is ready and 
integrated it will also be possible to define local schemas that provide 
standard comments to various header keywords, but that's a ways off.

As an aside, it's not necessary here to specify `ascii=False` in the Column() 
initialization.  That's already the default, and is only needed to create 
columns for ASCII tables when there's some ambiguity in the format code.

Erik




More information about the AstroPy mailing list