Skip to content

Commit ab90d93

Browse files
authored
Merge pull request #16019 from neutrinoceros/io/fits/bug/remember_compression_options
TST: add regression tests for issue #12216
2 parents b447aed + 4d6a72f commit ab90d93

1 file changed

Lines changed: 81 additions & 0 deletions

File tree

‎astropy/io/fits/hdu/compressed/tests/test_compressed.py‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,3 +1349,84 @@ def test_hdu_lazy_loading(tmp_path):
13491349
assert_equal(hdulist[idx + 1].data, idx)
13501350
assert hdulist[idx + 1].data.shape == (2**idx, 2**idx)
13511351
fileobj.seek(0)
1352+
1353+
1354+
@pytest.mark.parametrize(
1355+
"init_kwargs, expected_zflags",
1356+
[
1357+
pytest.param(
1358+
dict(quantize_level=-32, data=np.array([0.0])),
1359+
{
1360+
"ZNAME1": "BLOCKSIZE",
1361+
"ZVAL1": 32,
1362+
"ZNAME2": "BYTEPIX",
1363+
"ZVAL2": 4,
1364+
"ZNAME3": "NOISEBIT",
1365+
"ZVAL3": -32,
1366+
"ZCMPTYPE": "RICE_1",
1367+
"ZQUANTIZ": "NO_DITHER",
1368+
},
1369+
id="quantize_level_w_data",
1370+
),
1371+
pytest.param(
1372+
dict(quantize_level=-32),
1373+
{
1374+
"ZNAME1": "BLOCKSIZE",
1375+
"ZVAL1": 32,
1376+
"ZNAME2": "BYTEPIX",
1377+
"ZVAL2": 4,
1378+
"ZNAME3": "NOISEBIT",
1379+
"ZVAL3": -32,
1380+
"ZCMPTYPE": "RICE_1",
1381+
"ZQUANTIZ": "NO_DITHER",
1382+
},
1383+
id="quantize_level_wo_data",
1384+
),
1385+
pytest.param(
1386+
dict(quantize_method=2, dither_seed=1, data=np.array([0.0])),
1387+
{
1388+
"ZNAME1": "BLOCKSIZE",
1389+
"ZVAL1": 32,
1390+
"ZNAME2": "BYTEPIX",
1391+
"ZVAL2": 4,
1392+
"ZNAME3": "NOISEBIT",
1393+
"ZVAL3": 16,
1394+
"ZCMPTYPE": "RICE_1",
1395+
"ZQUANTIZ": "SUBTRACTIVE_DITHER_2",
1396+
},
1397+
id="quantize_level_dither_seed_w_data",
1398+
),
1399+
pytest.param(
1400+
dict(quantize_method=2, dither_seed=1),
1401+
{
1402+
"ZNAME1": "BLOCKSIZE",
1403+
"ZVAL1": 32,
1404+
"ZNAME2": "BYTEPIX",
1405+
"ZVAL2": 4,
1406+
"ZNAME3": "NOISEBIT",
1407+
"ZVAL3": 16,
1408+
"ZCMPTYPE": "RICE_1",
1409+
"ZQUANTIZ": "SUBTRACTIVE_DITHER_2",
1410+
},
1411+
id="quantize_level_dither_seed_wo_data",
1412+
),
1413+
],
1414+
)
1415+
def test_compression_options_with_mutated_data(
1416+
init_kwargs,
1417+
expected_zflags,
1418+
tmp_path,
1419+
):
1420+
# see https://github.com/astropy/astropy/issues/12216
1421+
prng = np.random.default_rng(seed=0)
1422+
data = prng.random((50, 30)).astype("float32")
1423+
1424+
hdu = fits.CompImageHDU(**init_kwargs)
1425+
hdu.data = data
1426+
1427+
hdu.writeto(tmp_path / "t.fits")
1428+
1429+
hdr = fits.getheader(tmp_path / "t.fits", ext=1, disable_image_compression=True)
1430+
1431+
zflags = {k: hdr[k] for k in expected_zflags}
1432+
assert zflags == expected_zflags

0 commit comments

Comments
 (0)