Skip to content

Conversation

penaguerrero
Copy link
Contributor

@penaguerrero penaguerrero commented Aug 25, 2025

Resolves JP-3673
and
Resolves JP-4062

This PR addresses saving the background mask in the corresponding datamodel extension, even if the step exists early. In such case, the scaling factor keyword will be saved with value "N/A", and the status of the step will be set to SKIPPED with value 1.0 and the status of the step will be set to FAILED.

Tasks

  • If you have a specific reviewer in mind, tag them.
  • add a build milestone, i.e. Build 12.0 (use the latest build if not sure)
  • Does this PR change user-facing code / API? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see changelog readme for instructions)
    • update or add relevant tests
    • update relevant docstrings and / or docs/ page
    • start a regression test and include a link to the running job (click here for instructions)
      • Do truth files need to be updated ("okified")?
        • after the reviewer has approved these changes, run okify_regtests to update the truth files
  • if a JIRA ticket exists, make sure it is resolved properly

Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 95.12195% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.51%. Comparing base (3bf3887) to head (48fbcab).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
jwst/background/background_step.py 95.00% 1 Missing ⚠️
jwst/background/background_sub_wfss.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9772      +/-   ##
==========================================
+ Coverage   82.49%   82.51%   +0.02%     
==========================================
  Files         366      366              
  Lines       37134    37140       +6     
==========================================
+ Hits        30633    30647      +14     
+ Misses       6501     6493       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@penaguerrero penaguerrero requested a review from a team as a code owner August 26, 2025 15:37
Copy link
Collaborator

@melanieclarke melanieclarke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing the cal_step status to be FAILED has some implications for the record_step_status function in jwst/stpipe/utilities. It currently assumes there are only two options: COMPLETE and SKIPPED. Since we are only allowing this value for this one step right now, which does not use record_step_status, I think we can address this later, but we should file a ticket for it.

It also looks like this step could use some more clean up on when it makes a copy of the input_model. In addition to the places I noted below, it also looks like subtract_soss_bkg is being called on input_model, when it should be called on the copy. The last three tests in test_background_soss.py should be modified to include this line to verify that the output is not a shallow copy of the input:
assert mock_model.meta.cal_step.bkg_subtract is None
If I add that line locally, those tests would currently be failing.

@melanieclarke
Copy link
Collaborator

Thanks for the clean up! Can you please also modify the tests to add the check for a shallow copy?

@melanieclarke
Copy link
Collaborator

Here's the follow up ticket to more broadly address possible FAILED status:
https://jira.stsci.edu/browse/JP-4103

@@ -179,6 +179,7 @@ def test_nirspec_gwa(tmp_cwd, background, science_image):
assert_allclose(result.data, test)
assert type(result) is type(science_image)
assert result.meta.cal_step.bkg_subtract == "COMPLETE"
assert result is not science_image
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is a good start, but it still won't catch a shallow copy, because the top-level object is not the same, but the underlying data is still shared. In all these cases, we should also add something like this to check that the meta was not updated in the input:
assert science_image.meta.cal_step.bkg_subtract is None


# Test image-based correction.
result = subtract_soss_bkg(generate_soss_image, template_model, 35.0, [25.0, 50.0])
assert result is not image
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test isn't helpful, since image is a copy already. You need to check that result is not generate_soss_image.

result.meta.cal_step.bkg_subtract = "SKIPPED"
self.log.warning("Skipping background subtraction")
self.log.warning(
"GWA_XTIL and GWA_YTIL source values are not the same as bkg values"
)

input_model.close()
model.close()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to close model here - it should be the same model as result, which we want to return open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants