[AstroPy] issue with initialisation of a fits binary table

Thomas Robitaille thomas.robitaille at gmail.com
Mon Sep 8 11:18:20 EDT 2014


Hi Paul,

To add a row, you could consider using the Table interface:

from astropy.table import Table
t = Table.read('thefile.fits')
t.add_row(...)
t.write('newfile.fits', overwrite=True)

and similarly to add a column. Generally speaking if you want to
manipulate the table you are much better off reading it in via the Table
interface.

Cheers,
Tom

Paul Kuin wrote:
> Hi Erik, 
> 
> The problem I see with that is that I won't know in advance which
> keyword is TTYPE1, TTYPE2, etc. although it probably is in sequence. At
> the moment I just will let it be. Good to know you are working on
> improving that for the new version. 
> 
> One other item that really bugged me later was trying to add a row to a
> binTable.There's no good way to do that. I wrote a work-around. I
> suppose that will also be fixed in the next release. 
> 
> Cheers, 
> 
>    Paul
> 
> On Mon, Sep 8, 2014 at 2:59 PM, Erik Bray <embray at stsci.edu
> <mailto:embray at stsci.edu>> wrote:
> 
>     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
> 
>     _______________________________________________
>     AstroPy mailing list
>     AstroPy at scipy.org <mailto:AstroPy at scipy.org>
>     http://mail.scipy.org/mailman/listinfo/astropy
> 
> 
> 
> 
> -- 
> 
> * * * * * * * * http://www.mssl.ucl.ac.uk/~npmk/ * * * *
> Dr. N.P.M. Kuin      (n.kuin at ucl.ac.uk <mailto:n.kuin at ucl.ac.uk>)      
> phone +44-(0)1483 (prefix) -204927 (work)
> mobile +44(0)7806985366  skype ID: npkuin
> Mullard Space Science Laboratory  – University College London  –
> Holmbury St Mary – Dorking – Surrey RH5 6NT–  U.K.
> 
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy



More information about the AstroPy mailing list