Skip to content

Commit

Permalink
Fix bug preventing NirspecQuadFlatModel instantiation from NirspecFla…
Browse files Browse the repository at this point in the history
…tModel (#401)
  • Loading branch information
emolter authored Feb 12, 2025
1 parent 8c2f588 commit dd86d11
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/401.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug preventing NirspecQuadFlatModel instantiation from NirspecFlatModel
2 changes: 1 addition & 1 deletion src/stdatamodels/jwst/datamodels/nirspec_flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, init=None, **kwargs):
self.quadrants[0].wavelength = init.wavelength
self.quadrants[0].flat_table = init.flat_table
self.quadrants[0].dq_def = init.dq_def
self.quadrants[0].dq = dynamic_mask(self.quadrants[0])
self.quadrants[0].dq = dynamic_mask(self.quadrants[0], pixel)
return

super(NirspecQuadFlatModel, self).__init__(init=init, **kwargs)
Expand Down
30 changes: 30 additions & 0 deletions src/stdatamodels/jwst/datamodels/tests/test_nirspec_flat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Tests for nirspec flat field models."""

import numpy as np
import pytest
from stdatamodels.jwst.datamodels import NirspecFlatModel, NirspecQuadFlatModel


@pytest.fixture(scope="module")
def flatmodel():
rng = np.random.default_rng()
data = rng.random((100, 100))
dq = rng.integers(0, 2, (100, 100))
model = NirspecFlatModel(data, dq=dq)
model.meta.instrument.name = "NIRSPEC"
model.meta.reftype = "FLAT"
model.meta.author = "STSCI"
model.meta.description = "Test flat field model"
model.meta.pedigree = "GROUND"
model.meta.useafter = "2025-02-12T00:00:00"
return model


def test_initialize_quad_from_flat(flatmodel):
"""
Cover a bug where attempting to initialize a quad flat model from a flat model would fail.
"""
quadmodel = NirspecQuadFlatModel(flatmodel)
assert isinstance(quadmodel, NirspecQuadFlatModel)
assert np.allclose(quadmodel.quadrants[0].data, flatmodel.data)
assert np.allclose(quadmodel.quadrants[0].dq, flatmodel.dq)

0 comments on commit dd86d11

Please sign in to comment.