[AstroPy] astropy Table to table in a multi-extension fits file

Knox Long knoxlong at gmail.com
Sun Mar 26 13:27:25 EDT 2017


Yes, Evert. Thank you. That did work.  Knox


On Sun, Mar 26, 2017 at 1:17 AM Evert Rol <evert.rol at gmail.com> wrote:

> >
> > I have several related astropy Tables (inside a python script) which I
> want to write to a multi-extension fits file.  Is there a simple way to do
> this using astropy.io.fits?
>
> Hi Knox,
>
> astropy.io.fits has a function `table_to_hdu` which may make things easier
> for you.
> Here's an example:
>
> from astropy.io.fits import table_to_hdu, HDUList, PrimaryHDU
> from astropy.table import Table
>
> HDUList([
>    PrimaryHDU(),
>    table_to_hdu( Table({'a': [1,2]})),
>    table_to_hdu( Table({'b': [1,2,3]}))
> ]).writeto('test.fits')
>
> (possibly appending to a HDU list inside a loop in your case.)
>
>
> Evert
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>
-- 
Knox S. Long
410-338-4862  (office)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170326/b0ac48bf/attachment.html>


More information about the AstroPy mailing list