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

Fix unsafe initialization of CubeModel from ImageModel #9192

Merged
merged 2 commits into from
Feb 17, 2025
Merged
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
28 changes: 15 additions & 13 deletions jwst/ami/ami_analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,21 @@
AMI cropped data, model, and residual data from LG algorithm fringe fitting
"""
# Create copy of input_model to avoid overwriting input
input_copy = copy.deepcopy(input_model)

# If the input image is 2D, expand all relevant extensions to be 3D
# Incl. those not currently used?
if len(input_model.data.shape) == 2:
if isinstance(input_copy, ImageModel):
input_copy = CubeModel(input_copy)
input_copy.data = np.expand_dims(input_copy.data, axis=0)
input_copy.dq = np.expand_dims(input_copy.dq, axis=0)
# input_copy.err = np.expand_dims(input_copy.err, axis=0)
# input_copy.var_poisson = np.expand_dims(input_copy.var_poisson, axis=0)
# input_copy.var_rnoise = np.expand_dims(input_copy.var_rnoise, axis=0)
# input_copy.var_flat = np.expand_dims(input_copy.var_flat, axis=0)
if isinstance(input_model, ImageModel):
# If the input image is 2D, expand all relevant extensions to be 3D
data = np.expand_dims(input_model.data, axis=0)
dq = np.expand_dims(input_model.dq, axis=0)
input_copy = CubeModel(data=data, dq=dq)
input_copy.update(input_model)

Check warning on line 76 in jwst/ami/ami_analyze.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze.py#L73-L76

Added lines #L73 - L76 were not covered by tests
# Incl. those not currently used?
# input_copy.err = np.expand_dims(input_model.err, axis=0)
# input_copy.var_poisson = np.expand_dims(input_model.var_poisson, axis=0)
# input_copy.var_rnoise = np.expand_dims(input_model.var_rnoise, axis=0)
# input_copy.var_flat = np.expand_dims(input_model.var_flat, axis=0)
elif isinstance(input_model, CubeModel):
input_copy = copy.deepcopy(input_model)
else:
raise TypeError("Input model must be a CubeModel or ImageModel.")

Check warning on line 85 in jwst/ami/ami_analyze.py

View check run for this annotation

Codecov / codecov/patch

jwst/ami/ami_analyze.py#L85

Added line #L85 was not covered by tests

# If the input data were taken in full-frame mode, extract a region
# equivalent to the SUB80 subarray mode to make execution time acceptable.
Expand Down