Skip to content

Commit

Permalink
JP-1048: added unit test for dq_def roundtrip (spacetelescope#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro authored Aug 27, 2024
2 parents 7ed9425 + 8b27b48 commit d8a9ca2
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/stdatamodels/jwst/datamodels/tests/test_fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from stdatamodels.jwst import datamodels
from stdatamodels.jwst.datamodels import ImageModel, JwstDataModel, RampModel, SpecModel
from stdatamodels.jwst.datamodels import ImageModel, JwstDataModel, RampModel, SpecModel, FlatModel


@pytest.fixture
Expand Down Expand Up @@ -106,3 +106,25 @@ def test_units_roundtrip(tmp_path):

m = datamodels.open(fn)
assert m.spec_table.columns['WAVELENGTH'].unit == 'nm'


def test_flatmodel_dqdef_roundtrip(tmp_path):
'''Covers an old bug where this roundtrip would fail due to
a mix-up between signed and unsigned integer data types, leading to flag values
like 2147483649 instead of 0'''
flatdata = [(0,1,2),(3,4,5),(6,7,8)]
flatflags = [(0, 1, "DO_NOT_USE", "Bad pixel. Do not use."),
(1, 2, "NON_SCIENCE", "Pixel not on science portion of detector"),
(2, 4, "UNRELIABLE_FLAT", "Flat variance large")]
flatmodel = FlatModel( data=flatdata, dq_def=flatflags )

fn = tmp_path / "test_flat.fits"
flatmodel.save(fn)

with datamodels.open(fn) as flatmodel2:
assert np.allclose(flatmodel2.data, flatdata)
for i, flag in enumerate(flatmodel2.dq_def):
for j in range(2):
# tuples do not directly assert True because datamodels.open() returns np.int32
# which is not technically of type int. So must check their equality directly
assert flag[j] == flatflags[i][j]

0 comments on commit d8a9ca2

Please sign in to comment.