[AstroPy] Add an astropy.table.Table to a multi-extension FITS file?

Joseph Booker joe at neoturbine.net
Thu Dec 18 10:36:36 EST 2014


Just so you know, any file I/O can be done completely in memory with
BytesIO:


>>> from astropy.io import fits
>>> from astropy.table import Table
>>> import io
>>> t = Table(names=('a', 'b', 'c'), dtype=('f4', 'i4', 'S2'));
t.add_row((1, 2.0, 'x')); t.add_row((4, 5.0, 'y'))
>>> buf = io.BytesIO()
>>> t.write(buf, format='fits')
>>> buf.seek(0)
0
>>> print(fits.open(buf))
[<astropy.io.fits.hdu.image.PrimaryHDU object at 0x7fb97ee77da0>,
<astropy.io.fits.hdu.table.BinTableHDU object at 0x7fb974a409e8>]


Note that older versions of python use StringIO.StringIO instead of
io.BytesIO

On Wed, Dec 17, 2014 at 8:55 PM, David Kirkby <dkirkby at uci.edu> wrote:
>
> Is it possible to create a table as an astropy.table.Table and then
> convert it to an astropy.fits.io.BinTableHDU suitable for adding to the
> astropy.io.fits.HDUList of a multi-extension file?
>
> I guess that astropy.table.Table.write already implements this but I
> didn't see how to only generate a new HDU in memory with this API.
>
> thanks,
> David
>
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at scipy.org
> http://mail.scipy.org/mailman/listinfo/astropy
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20141218/944645d2/attachment.html>


More information about the AstroPy mailing list