Skip to content

Commit

Permalink
Merge branch 'main' into jp-2928-miri-dark
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke authored Oct 25, 2024
2 parents 0acda20 + b4c09b7 commit bd74206
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions changes/8907.pipeline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a bug leading to incorrect area extensions, and sometimes crashes, in the coron3 pipeline
9 changes: 8 additions & 1 deletion jwst/pipeline/calwebb_coron3.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ def to_container(model):
'var_poisson', 'var_rnoise', 'var_flat'
]:
try:
setattr(image, attribute, model.getarray_noinit(attribute)[plane])
arr = model.getarray_noinit(attribute)
if arr.ndim == 3:
setattr(image, attribute, arr[plane])
elif arr.ndim == 2:
setattr(image, attribute, arr)
else:
msg = f"Unexpected array shape for extension {attribute}: {arr.shape}"
raise ValueError(msg)
except AttributeError:
pass
image.update(model)
Expand Down
21 changes: 21 additions & 0 deletions jwst/pipeline/tests/test_calwebb_coron3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from stdatamodels.jwst.datamodels import CubeModel

from jwst.pipeline.calwebb_coron3 import to_container
import numpy as np


# Generate data
Expand All @@ -22,6 +23,26 @@ def make_container():
]


def test_to_container():
"""Cover bug where IndexError would be raised when area extension of CubeModel
has shape (x,y) instead of (nints,x,y). In this case area extension should
be copied to each ImageModel in the ModelContainer.
"""
shp = (10,5,5)
cube = CubeModel(shp)
extensions_3d = ['data', 'dq', 'err',]
for extension in extensions_3d:
setattr(cube, extension, np.random.rand(*shp))
cube.area = np.random.rand(5,5)

container = to_container(cube)
for i, model in enumerate(container):
for extension in extensions_3d:
assert np.all(getattr(model, extension) == getattr(cube, extension)[i])
assert hasattr(model, 'area')
assert np.all(model.area == cube.area)


@pytest.mark.parametrize('cube, container', [(cube, container)])
def test_container_shape(cube, container):
"""Test container shape"""
Expand Down

0 comments on commit bd74206

Please sign in to comment.