Skip to content

Commit 8e13bfe

Browse files
authored
Merge pull request #388 from esheldon/gzip-finalize
work around cfitsio bug creating HDU for lossless gzip
2 parents 6f9590a + cbd9261 commit 8e13bfe

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Bug Fixes
1111

1212
- Bug not writing compression qlevel when it is set to None/0.0
1313
This was preventing lossless gzip compression
14+
- work around cfitsio bug when creating HDU for lossless gzip compression,
15+
reopen file instead of just an update hdu list
1416

1517
version 1.2.0
1618
--------------

fitsio/fitslib.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -1040,9 +1040,13 @@ def create_image_hdu(self,
10401040
extver=extver,
10411041
)
10421042

1043-
# don't rebuild the whole list unless this is the first hdu
1044-
# to be created
1045-
self.update_hdu_list(rebuild=False)
1043+
if compress is not None and qlevel is None or qlevel == 0.0:
1044+
# work around bug in cfitso
1045+
self.reopen()
1046+
else:
1047+
# don't rebuild the whole list unless this is the first hdu
1048+
# to be created
1049+
self.update_hdu_list(rebuild=False)
10461050

10471051
def _ensure_empty_image_ok(self):
10481052
"""

fitsio/tests/test_image_compression.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,11 @@ def test_compressed_write_read(compress):
9898
'gzip_2_lossless',
9999
]
100100
)
101-
def _test_compressed_write_read_fitsobj(compress):
101+
def test_compressed_write_read_fitsobj(compress):
102102
"""
103103
Test writing and reading a rice compressed image
104104
105-
This one fails because the compressed data do not seem to be
106-
finalized
105+
In this version, keep the fits object open
107106
"""
108107
nrows = 5
109108
ncols = 20
@@ -117,6 +116,7 @@ def _test_compressed_write_read_fitsobj(compress):
117116

118117
if 'lossless' in compress:
119118
qlevel = None
119+
# qlevel = 9999
120120
else:
121121
qlevel = 16
122122

@@ -160,14 +160,6 @@ def _test_compressed_write_read_fitsobj(compress):
160160
0.2,
161161
"%s compressed images ('%s')" % (compress, dtype),
162162
)
163-
# else:
164-
# # for integers we have chosen a wide range of values, so
165-
# # there will be no quantization and we expect no
166-
# # information loss
167-
# compare_array(
168-
# data, rdata,
169-
# "%s compressed images ('%s')" % (compress, dtype)
170-
# )
171163

172164
with FITS(fname) as fits:
173165
for ii in range(len(dtypes)):

0 commit comments

Comments
 (0)