[AstroPy] Re: [SciPy-user] pyfits question: handling gzipped fits files
Michael Fitzgerald
mpfitz at berkeley.edu
Fri Jul 15 07:41:33 EDT 2005
On Thursday 14 July 2005 07:56, Perry Greenfield wrote:
> On Jul 14, 2005, at 10:38 AM, Russell E. Owen wrote:
> > Is there some reasonable way to get pyfits to read a gzipped fits file
> > (in a way that works on Windows and unix)?
<snip>
> Not yet, but after version 1 is out, it's one of the first things we'd
> like to add (as well as support for the compression conventions that
> CFITSIO supports). We don't have time right now to do it (though it
> shouldn't be hard at all). If you or someone would like to add it, we
> would welcome such a patch.
Hello,
Here is a patch against pyfits 0.9 that does the trick for me on unix. It
simply uses the gzip.open() function to open the file instead of
__builtin__.open() if the filename ends in .gz.
Unfortunately, the patch is broken in the most recent version of pyfits
(0.9.8.2). I don't know in what version the break first occurs, but the
problem must've started when pyfits began using the two-argument form of File
objects' seek() method. The (optional) second argument is the 'whence'
direction flag. In short, the gzip.GzipFile class does not share the
interface of the File class, and can't be used as a drop-in replacement in
the most recent version of pyfits.
For the sake of consistency, it would be ideal if the File/GzipFile interfaces
were compatible, which means this should be fixed in Python's library. I
haven't poked around much for the best way to achieve this. I did notice,
however, the bz2 module's BZ2File class does implement the two-argument
seek() method. Perhaps the update to the gzip module can be modeled off the
bz2 module's implementation.
Finally, since I can't readily find pyfits 0.9 on the web, I've temporarily
put the patched 0.9 version here:
http://astron.berkeley.edu/~fitz/pyfits.py
Mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pyfits.py.diff
Type: text/x-diff
Size: 966 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20050715/0eaf9d12/attachment.diff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/astropy/attachments/20050715/0eaf9d12/attachment.sig>
More information about the AstroPy
mailing list