[AstroPy] Creating file-like object from HDUList?

Benjamin Alan Weaver baweaver at lbl.gov
Fri Sep 15 14:57:32 EDT 2017


Hello y'all,

I'd be interested in an answer to this question as well.

Kia ora koutou,
Benjamin Alan Weaver

On Thu, Sep 7, 2017 at 6:47 AM, Ole Streicher <astropy at liska.ath.cx> wrote:

> Hi,
>
> I have a rather large HDUList that was creating from a memory mapped
> fits file by using slices on its data array(s):
>
> from astropy.io import fits
>
> hdul0 = fits.open('datacube.fits', memmap = True) // >> 1GB
> hdul1 = fits.HDUList([ fits.PrimaryHDU(header = hdul0[0].header),
>                        fits.ImageHDU(data = hdul0[1].data[:100, :100,
> :100],
>                                      header = hdul0[1].header)])
>
> Is it now possible to create a file-like object opened in read mode without
> needing to read everything beforehand? Like here:
>
> res = io.BytesIO()
> hdul1.writeto(res)
> send_file(res, mime_type="application/fits")
>
> but without creating a large in-memory object with res, and without
> temporary storage on disk?
>
> Best regards
>
> Ole
>
> _______________________________________________
> AstroPy mailing list
> AstroPy at python.org
> https://mail.python.org/mailman/listinfo/astropy
>



-- 
With great responsibility seldom comes great power.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/astropy/attachments/20170915/96402046/attachment.html>


More information about the AstroPy mailing list