Skip to content

Commit

Permalink
Add test for duplicate data when resaving model to fits
Browse files Browse the repository at this point in the history
When resaving a model to fits, asdf loses track of array-hdu
links and saves arrays in both hdu and as internal blocks in the
asdf tree. This can make an asdf tree that is larger than what
can be stored in a fits hdu.

See asdf issue: asdf-format/asdf#1232

This test is skipped as it fails with the current asdf version.

modify imports and use context manager for test_fits

Co-authored-by: James Davies <jdavies@mpia.de>

use context manager in test_fits

Co-authored-by: James Davies <jdavies@mpia.de>

improve test docstring in test_fits
  • Loading branch information
braingram committed Nov 18, 2022
1 parent f6b3973 commit 082423a
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion jwst/datamodels/tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import numpy as np
import pytest

from jwst.datamodels import JwstDataModel, RampModel
from jwst import datamodels
from jwst.datamodels import ImageModel, JwstDataModel, RampModel


@pytest.fixture
Expand Down Expand Up @@ -68,3 +69,26 @@ def test_casting():
total = dm.data.sum()
dm.data = dm.data + 2
assert dm.data.sum() > total


@pytest.mark.skip(reason='fix required for asdf')
def test_resave_duplication_bug(tmp_path):
"""
An issue in asdf (https://github.com/asdf-format/asdf/issues/1232)
resulted in duplication of data when a model was read from and then
written to a fits file. A resave results in array data being written to
both hdus and as internal blocks within the asdf tree (which is then
stored in the asdf hdu).
"""
fn1 = tmp_path / "test1.fits"
fn2 = tmp_path / "test2.fits"

arr = np.zeros((1000, 100), dtype='f4')
m = ImageModel(arr)
m.save(fn1)

with datamodels.open(fn1) as m2:
m2.save(fn2)

with fits.open(fn1) as ff1, fits.open(fn2) as ff2:
assert ff1['ASDF'].size == ff2['ASDF'].size

0 comments on commit 082423a

Please sign in to comment.