[AstroPy] question about fpack and astropy.io.fits
octavi at live.unc.edu
Thu Oct 9 20:01:45 EDT 2014
Thanks a lot Erik for your detailed reply.
Your answer allows me to focus my questions/concerns about astropy.io.fits
and fpack <http://heasarc.nasa.gov/fitsio/fpack/> in my initial message:
In other words, the convention states how compressed FITS files should be
> read and written, while fpack is simply a program that knows how to write
> files with that convention. There's no sense (I can think of) in which it
> makes sense for a general purpose FITS library (like astropy.io.fits) to
> support fpack itself. It does however support the same compression scheme
> and can read files compressed by fpack. And likewise can write compressed
> files that can be read by funpack.
1-by "it supports the same compression scheme" do you mean that
astropy.io.fits reads/writes tile compressed FITS images in the same
*exact* way (in terms of compression ratio and checksum file) as fpack does
from command line (of course using the same set of parameters)?
2-my other concern is speed when reading/writing tiled-compressed FITS
Is astropy.io.fits performance comparable to fpack command line one?
Our example is 6576x4384pix images, with tiles size of 100x100pix.
3-one of our pipeline most intensive I/O operations is to extract small
(500x500pix) subimages from the big ones (6576x4384pix) upon ~10^3 targets
(RA,DEC) x ~10^6 exposures = ~10^9 requests.
In the fpack website <http://heasarc.nasa.gov/fitsio/fpack/> I've seen
these two features:
-Each HDU of a multi-extension FITS file is compressed separately, so it is
> not necessary to uncompress the entire file to read a single image in a
> multi-extension file.
> -Dividing the image into tiles before compression enables faster access to
> small subsections of the image.
I know it's a basic question, but...: are the compressed tiles stored into
In other words, if my big (6576x4384pix) images are tile-compressed with
fpack (or with astropy.io.fits if possible) and properly multi-extension
HDU arranged, could astropy.io.fits (or pyfits) support the first of the
two fpack features mentioned above?
That would really improve the reading performance for subimage extraction
Thanks in advance,
On Thu, Oct 9, 2014 at 4:24 PM, Erik Bray <embray at stsci.edu> wrote:
> Hi Octavi,
> On 10/08/2014 11:06 PM, Octavi Fors wrote:
> > Hello everyone,
> > this might sounds like a newbie question, but do you know if fpack
> > package is supported by astropy.io.fits version 0.4.2?
> It depends on what you mean, exactly. It would help to add some
> about what *fpack* is--apologies if this isn't new to you but it's worth
> mentioning for anyone else reading.
> fpack itself (and its counterpart funpack (which I always enjoy reading
> pack")) are just command-line programs that write new FITS files with one
> more of the HDUs compressed according the FITS Tile Compression
> decompress them as the case may be.
> In other words, the convention states how compressed FITS files should be
> and written, while fpack is simply a program that knows how to write files
> that convention. There's no sense (I can think of) in which it makes
> sense for
> a general purpose FITS library (like astropy.io.fits) to support fpack
> It does however support the same compression scheme and can read files
> compressed by fpack. And likewise can write compressed files that can be
> by funpack.
> > In
> > the module "astropy.io.fits.compression" is mentioned to access
> compressed HDUs,
> > but it doesn't say if fpack is supported and how should this package be
> > specified in fits.open method.
> The docs you linked to at
> could probably be expanded on with more examples, but as they indicate
> containing compressed HDUs are handled transparently. The compressed HDUs
> accessed the same way as normal uncompressed IMAGE HDUs. The data is
> automatically decompressed when it is read. fpack has no role to play in
> > My images images are 16 and -32bit. and I would like to make use of
> > pattern (FZTILE='(n,m)', see fpack manual
> > <http://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/docs/fpackguide.pdf
> > For the -32bit images, any advise about noise-sensitive scaling
> > and subtractive dithering to achieve high compression ratios while
> > the scientific content of data, would be most than welcome.
> The FZTILE keyword, as well as the other "Fpack compression directive
> listed in section 3.3 of the fpack guide are not standard FITS keywords
> and are
> only understood by the fpack program itself.
> These can be used, for example, in a pipeline where raw data is written out
> uncompressed in a FITS file. The file is later processed through fpack
> will compress any HDUs marked with these keywords according to the
> settings. The end result of that is a new HDU compatible with the tile
> compression convention, and keywords like FZTILE become ZTILEn, or for
> FZALGOR becomes ZCMPTYPE.
> In other words, those FZ keywords indicate how the HDU *should* be
> when passed through fpack. The keywords on the actually compressed HDU
> (ZCMPTYPE, ZTILEn, etc.) indicate how the HDU *was* compressed.
> The FZ* keywords have no effect in astropy.io.fits (though it might not be
> a bad
> idea to create a facility that understands them, for creating compressed
> from existing uncompressed HDUs). Instead, to create a compressed HDU you
> create a CompImageHDU object as demonstrated here:
> This works the same as other HDU types in the library. Though it does take
> several optional keywords that are described in more detail in the API
> For example to specify a tiling use
> >>> hdu = fits.CompImageHDU(data=data, header=header, tile_size=(n, m))
> Subtractive dithering is used by default where applicable. It otherwise
> supports all the features of the convention except perhaps the ZMASKCMP
> (not for any particular technical reason--it's definitely something that
> can and
> should be done, though I haven't had any requests for it either...)
> As to how to find a balance between compression quality and data quality I
> others with more experience may wish to weigh in on that, though I will
> out that documentation for the tiled image convention has some useful tips
> on that:
> Hope that helps,
> AstroPy mailing list
> AstroPy at scipy.org
Postdoctoral Research Associate
Department of Physics and Astronomy
The University of North Carolina at Chapel Hill
CB #3255, #157 Phillips Hall
Chapel Hill, NC 27599
Office: (919) 962-3606
Fax: (919) 962-0480
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the AstroPy