You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Pyfits: Failure to write compressed np.int64 compressed images. #2153
Using astropy: 0.3.dev4315, the following code crashes (note that other types np.uint8, np.int16, np.int32, np.float32 and np.float64 are fine):
orig = np.arange(100, dtype=int)
primary = fits.PrimaryHDU()
hdu = fits.CompImageHDU(orig)
hdulist = fits.HDUList([primary, hdu])
hdulist.writeto('test.fits', clobber=True)
ERROR: RuntimeError: writing to compressed image is not supported [astropy.io.fits.hdu.compressed]
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-32-ac346fc5abe9> in <module>()
----> 1 hdulist.writeto('test.fits', clobber=True)
/home/chanial/.local/lib/python2.7/site-packages/astropy-0.3.dev4315-py2.7-linux-x86_64.egg/astropy/io/fits/hdu/hdulist.pyc in writeto(self, fileobj, output_verify, clobber, checksum)
671
672 for hdu in self:
--> 673 hdu._prewriteto(checksum=checksum)
674 try:
675 hdu._writeto(hdulist.__file)
/home/chanial/.local/lib/python2.7/site-packages/astropy-0.3.dev4315-py2.7-linux-x86_64.egg/astropy/io/fits/hdu/compressed.pyc in _prewriteto(self, checksum, inplace)
1500 self.scale(_ImageBaseHDU.NumCode[self._orig_bitpix])
1501 if self._data_loaded and self.data is not None:
-> 1502 self._update_compressed_data()
1503 # Doesn't call the super's _prewriteto, since it calls
1504 # self.data._scale_back(), which is meaningless here.
/home/chanial/.local/lib/python2.7/site-packages/astropy-0.3.dev4315-py2.7-linux-x86_64.egg/astropy/io/fits/hdu/compressed.pyc in _update_compressed_data(self)
1289 # compress_hdu returns the size of the heap for the written
1290 # compressed image table
-> 1291 heapsize, self.compressed_data = compression.compress_hdu(self)
1292 finally:
1293 # if data was byteswapped return it to its original order
RuntimeError: writing to compressed image is not supported
Although, it seems that according to the current tile compression spec, specifically section 6.1, RICE_1 compression should support 64-bit ints if I read correctly (even though other parts of the spec are a little vague about that).
More importantly though, the current version of CFITSIO that is bundled in Astropy does not support this. I haven't checked CFITSIO updates in a while though so let me see if this has been improved...
From the CFITSIO changelog it's not clear that this has been fixed yet. Might be worth trying out though. I don't remember the details of why this didn't work before (though I know it definitely didn't).
Probably this should either give an error, or cast the data to 32-bit (where possible, with warnings and overflow errors).
It would probably be good to update the convention and update CFITSIO to support this. Though if any effort were put into this I'd rather it be in the form of #3895.
Activity
embray commentedon Feb 28, 2014
For whatever reason the FITS Tile Compression convention still does not allow compression of 64-bit integer data #931.
This could still use a better error message or warning though.
eteq commentedon May 27, 2014
@embray - should this be pushed to 0.4.1?
embray commentedon Oct 20, 2015
Although, it seems that according to the current tile compression spec, specifically section 6.1, RICE_1 compression should support 64-bit ints if I read correctly (even though other parts of the spec are a little vague about that).
More importantly though, the current version of CFITSIO that is bundled in Astropy does not support this. I haven't checked CFITSIO updates in a while though so let me see if this has been improved...
embray commentedon Oct 20, 2015
From the CFITSIO changelog it's not clear that this has been fixed yet. Might be worth trying out though. I don't remember the details of why this didn't work before (though I know it definitely didn't).
Probably this should either give an error, or cast the data to 32-bit (where possible, with warnings and overflow errors).
It would probably be good to update the convention and update CFITSIO to support this. Though if any effort were put into this I'd rather it be in the form of #3895.
embray commentedon Jul 6, 2021
AFAICT CFITS (or at least the version vendored in Astropy) still does not support this, though it does give a slightly better error message:
astrofrog commentedon Jan 21, 2023
This seems to have been fixed by #14252:
prevent creating compressed files with (u)int64 data
prevent creating compressed files with (u)int64 data