|
34 | 34 | DEFAULT_BLOCK_SIZE = 32 |
35 | 35 | DEFAULT_BYTE_PIX = 4 |
36 | 36 |
|
| 37 | +# CFITSIO version-specific features |
| 38 | +if COMPRESSION_SUPPORTED: |
| 39 | + CFITSIO_SUPPORTS_GZIPDATA = compression.CFITSIO_VERSION >= 3.28 |
| 40 | + |
37 | 41 |
|
38 | 42 | class CompImageHeader(Header): |
39 | 43 | """ |
@@ -462,7 +466,7 @@ def updateHeaderData(self, image_header, |
462 | 466 | # this behavior so the only way to determine which behavior will |
463 | 467 | # be employed is via the CFITSIO version |
464 | 468 |
|
465 | | - if compression.cfitsio_version >= 3.28: |
| 469 | + if CFITSIO_SUPPORTS_GZIPDATA: |
466 | 470 | ttype2 = 'GZIP_COMPRESSED_DATA' |
467 | 471 | # The required format for the GZIP_COMPRESSED_DATA is actually |
468 | 472 | # missing from the standard docs, but CFITSIO suggests it |
@@ -770,7 +774,8 @@ def updateHeaderData(self, image_header, |
770 | 774 | bytepix = DEFAULT_BYTE_PIX |
771 | 775 |
|
772 | 776 | self._header.set('ZVAL2', bytepix, |
773 | | - 'bytes per pixel (1, 2, 4, or 8)', after='ZNAME2') |
| 777 | + 'bytes per pixel (1, 2, 4, or 8)', |
| 778 | + after='ZNAME2') |
774 | 779 | afterCard = 'ZVAL2' |
775 | 780 | idx = 3 |
776 | 781 | elif compressionType == 'HCOMPRESS_1': |
@@ -942,6 +947,7 @@ def compData(self): |
942 | 947 | # data) from the file, if there is any. |
943 | 948 | compData = super(BinTableHDU, self).data |
944 | 949 | if isinstance(compData, np.rec.recarray): |
| 950 | + del self.data |
945 | 951 | return compData |
946 | 952 | else: |
947 | 953 | # This will actually set self.compData with the pre-allocated space |
@@ -1255,6 +1261,11 @@ def updateCompressedData(self): |
1255 | 1261 | if dataspan < BLOCK_SIZE: |
1256 | 1262 | # We must a full FITS block at a minimum |
1257 | 1263 | dataspan = BLOCK_SIZE |
| 1264 | + else: |
| 1265 | + # Still make sure to pad out to a multiple of 2880 byte blocks |
| 1266 | + # otherwise CFITSIO can get read errors when it tries to read |
| 1267 | + # a partial block that goes past the end of the file |
| 1268 | + dataspan += _pad_length(dataspan) |
1258 | 1269 | self.compData = np.empty((dataspan,), dtype=np.byte) |
1259 | 1270 | self.compData[:tbsize] = 0 |
1260 | 1271 |
|
@@ -1353,7 +1364,8 @@ def updateHeader(self): |
1353 | 1364 | bytepix = DEFAULT_BYTE_PIX |
1354 | 1365 |
|
1355 | 1366 | self._header.set('ZVAL2', bytepix, |
1356 | | - 'bytes per pixel (1, 2, 4, or 8)', after='ZNAME2') |
| 1367 | + 'bytes per pixel (1, 2, 4, or 8)', |
| 1368 | + after='ZNAME2') |
1357 | 1369 |
|
1358 | 1370 | def scale(self, type=None, option='old', bscale=1, bzero=0): |
1359 | 1371 | """ |
|
0 commit comments