The writeto method of CompImageHDU raises an exception. It looks like the message comes from the interior of the cfitsio library.
The steps to reproduce shown below are based on astropy/0.2.
bw55@tardis[104]: ipython
Python 2.7.3 (default, Aug 1 2012, 05:14:39)
Type "copyright", "credits" or "license" for more information.
IPython 0.12.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy as np
In [2]: import astropy.io.fits as fits
In [3]: hdu = fits.CompImageHDU(np.array([-3, -2, -1, 0, 1, 2, 3]))
In [4]: hdu.writeto('tempfile.fits')
ERROR: RuntimeError: writing to compressed image is not supported [astropy.io.fits.hdu.compressed]
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/home/users/bw55/<ipython-input-4-c2b54d7eb58a> in <module>()
----> 1 hdu.writeto('tempfile.fits')
/home/users/bw55/local/products/astropy/0.2/lib/python2.7/site-packages/astropy/io/fits/hdu/base.pyc in writeto(self, name, output_verify, clobber, checksum)
1477 hdulist = HDUList([PrimaryHDU(), self])
1478 hdulist.writeto(name, output_verify, clobber=clobber,
-> 1479 checksum=checksum)
1480
1481 def _verify(self, option='warn'):
/home/users/bw55/local/products/astropy/0.2/lib/python2.7/site-packages/astropy/io/fits/hdu/hdulist.pyc in writeto(self, fileobj, output_verify, clobber, checksum)
669
670 for hdu in self:
--> 671 hdu._prewriteto(checksum=checksum)
672 try:
673 hdu._writeto(hdulist.__file)
/home/users/bw55/local/products/astropy/0.2/lib/python2.7/site-packages/astropy/io/fits/hdu/compressed.pyc in _prewriteto(self, checksum, inplace)
1483 self.scale(_ImageBaseHDU.NumCode[self._orig_bitpix])
1484 if self._data_loaded and self.data is not None:
-> 1485 self.updateCompressedData()
1486 # Doesn't call the super's _prewriteto, since it calls
1487 # self.data._scale_back(), which is meaningless here.
/home/users/bw55/local/products/astropy/0.2/lib/python2.7/site-packages/astropy/io/fits/hdu/compressed.pyc in updateCompressedData(self)
1282 # compress_hdu returns the size of the heap for the written
1283 # compressed image table
-> 1284 heapsize = compression.compress_hdu(self)
1285 finally:
1286 # if data was byteswapped return it to its original order
RuntimeError: writing to compressed image is not supported
In [5]:
If I scale the data to int32 (technically uint32), the write succeeds:
In [5]: bits=32
In [6]: hdu.scale('int{0:d}'.format(bits), '', bzero=2 ** (bits-1))
In [7]: hdu.writeto('tempfile.fits')
But if I scale the data to int64 (technically uint64), the write fails again:
In [5]: bits=64
In [6]: hdu.scale('int{0:d}'.format(bits), '', bzero=2 ** (bits-1))
In [7]: hdu.writeto('tempfile.fits')
(same failure as above)
The
writetomethod ofCompImageHDUraises an exception. It looks like the message comes from the interior of the cfitsio library.The steps to reproduce shown below are based on astropy/0.2.
If I scale the data to int32 (technically uint32), the write succeeds:
But if I scale the data to int64 (technically uint64), the write fails again: