Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for duplicate data when resaving model to fits #7358

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 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,25 @@ def test_casting():
total = dm.data.sum()
dm.data = dm.data + 2
assert dm.data.sum() > total


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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ python_requires = >=3.8
setup_requires =
setuptools_scm
install_requires =
asdf>=2.13.0
asdf>=2.14.1
asdf-transform-schemas>=0.3.0
astropy>=5.1
BayesicFitting>=3.0.1
Expand Down