[AstroPy] pyfits does not write to gzip ab+ objects
John K. Parejko
john.parejko at yale.edu
Fri Aug 23 01:49:35 EDT 2013
Hello,
On python2.7/pyfits3.1.2 , when I try to write to a gzip object in append mode, 'ab+', I receive an IOError: [Errno 9] read() on write-only GzipFile object. Whereas when I use mode 'ab', I receive no error.
The former worked in pyfits 2.4-ish (what we were previously using). We use NamedTemporaryFiles to prevent accidental filename collision, and pass that through a gzip object to select the compression level, before writing with hdu.writeto(tempFile,checksum=True).
I'm not sure whether pyfits or gzip is really the culprit here. I've attached an example.
Thanks in advance,
John
# Example:
import gzip
import pyfits
import numpy as np
hdu=pyfits.PrimaryHDU(np.random.random(10))
#IOError: [Errno 9] read() on write-only GzipFile object
f=gzip.GzipFile(filename='foo.fits.gz',mode='ab+',compresslevel=4)
hdu.writeto(f)
#works, resulting file is gzipped.
f=gzip.GzipFile(filename='foo.fits.gz',mode='ab',compresslevel=4)
hdu.writeto(f)
More information about the AstroPy
mailing list