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

JP-3782: Fix improper setting of AREA extension in coron3 pipeline #8907

Merged
merged 5 commits into from
Oct 25, 2024
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
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 @@
'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)

Check warning on line 40 in jwst/pipeline/calwebb_coron3.py

View check run for this annotation

Codecov / codecov/patch

jwst/pipeline/calwebb_coron3.py#L39-L40

Added lines #L39 - L40 were not covered by tests
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
Loading