-
Notifications
You must be signed in to change notification settings - Fork 35
JP-3967: SATURATION flag for partially saturated pixels should be propagated to the _rate DQ #421
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #421 +/- ##
==========================================
+ Coverage 89.89% 90.02% +0.13%
==========================================
Files 65 65
Lines 9983 10114 +131
==========================================
+ Hits 8974 9105 +131
Misses 1009 1009 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
daa928d to
e234a7c
Compare
0084443 to
e6d211c
Compare
b42c50d to
78bbefa
Compare
This comment was marked as resolved.
This comment was marked as resolved.
|
I don't mind. We probably should have worked to get this in first, then reformatted, but 🤷🏻♂️. |
c6b5ff5 to
1272f00
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmacdonald-stsci I could use some advice on whether the results for LIKELY added here make sense or I messed up something in utils.py. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pllim That appears correct. Further, many of the tests of the LIKELY algorithm are checked against the OLS algorithm as shown at the link below. These tests would fail if the flagging was different.
stcal/tests/test_ramp_fitting_likely_fit.py
Line 144 in 1272f00
| algo = "OLS" |
This comment was marked as resolved.
This comment was marked as resolved.
|
There is one failure on romancal that looks related ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to okify the romancal regtest after this is merged, but please tell me when that happens so I can be ready.
We should probably do the same for romancal / Casertano+22, but that's currently handled within romancal so I can tackle it separately.
(maybe just to say---yes, I agree that those romancal regtest failures look expected given this change)
211cba2 to
4ac7661
Compare
This comment was marked as resolved.
This comment was marked as resolved.
4ac7661 to
558a923
Compare
558a923 to
16edac2
Compare
…pagated to the _rate DQ C: Remove outdated comment Possible partially saturated ramp flagging. JP-3967 update for pllim (#1) * Undoing test changes in prep to change the C-extension, as well as analyze the test failures in the LIKELY CI tests. * Commenting out a part of a test that fails. The OLS SAT flagging needs to be updated before this test works. * Updated C-extension and tests. * Updating tests for ramp fitting cases. * Removing preprocessing switches and adding a comment, cleaning up the code. * Removing unnecessary comment. * Comments on how to update slope fitter for partial saturation flagging. * Updating the parital flagging for the rate product. Updating ramp fit tests for updating flagging. * Updating partial saturation flagging and tests. DOC: Reword second paragraph. Co-authored-by: Ken MacDonald <[email protected] m> TST: Extend test_ramp_fitting.py to LIKELY algo
16edac2 to
af54218
Compare
and fix tests. MNT: Add __all__ to ramp_fitting/utils.py DOC: Fix DQ propagation text. TST: Un-xfail test_read_pattern_saturation_flagging from spacetelescope#362
d7ca60b to
de35dc6
Compare
src/stcal/ramp_fitting/ramp_fit.py
Outdated
|
|
||
|
|
||
| # Suppress one group ramps, if desired. | ||
| if ramp_data.suppress_one_group_ramps: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went down the rabbit hole of trying to get flagging (more) consistent between OLS and LIKELY in test_ramp_fitting.py and found that I have to move this up to make it happen. Is there a reason why this is only done for OLS but not LIKELY before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be. @kmacdonald-stsci @t-brandt - do you know?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test_zeroframe was developed years ago, before the LIKELY algorithm was added. When the LIKELY algorithm was added, it did not use the ZEROFRAME. Usage of the ZEROFRAME wasn't added to the LIKELY algorithm till a few months ago.
Further, the test_ramp_fitting.py test module was designed to test the ramp fitting default algorithm, not the LIKELY algorithm, which is tested in the test_ramp_fitting_likely.py test module. There is an expectation these algorithms would give different results, so the same tests would yield different results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does that mean I have to undo this change here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have been using this module to test the LIKELY algorithm, then yes. Use test_ramp_fitting_likely.py to test that algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kmacdonald-stsci - the question here was whether it's appropriate to use suppress_one_group_ramps with the likelihood algorithm as well as OLS. The current behavior is to use it only for OLS.
I think this is a side question for this PR, though, so I suggest we leave it as is and file a ticket for follow up later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really understand the use cases for the LIKELY algorithm. I don't know the use cases, nor why someone would use it. For the OLS case, Mike Regan requested ramps with only one good group be suppressed. I don't know if the reason for that extends to the LIKELY algorithm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I opened https://jira.stsci.edu/browse/JP-4208 (spacetelescope/jwst#10089). We can discuss there. Thanks!
| # Assume total saturation if group 0 is SATURATED. | ||
| gdq0_sat = np.bitwise_and(gdq_sect[0], sat) | ||
| pixeldq_sect[gdq0_sat != 0] = np.bitwise_or(pixeldq_sect[gdq0_sat != 0], sat | dnu) | ||
| # If saturation occurs mark the appropriate flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@melanieclarke , do I have to also change dq_compress_sect here to go with your previous suggestion for dq_compress_final?
Also unsure if I have to touch L109 above to change it to set_if_total_ramp(pixeldq_sect, gdq_sect, dnu, dnu).
Given LIKELY can behave so differently from OLS, I am not sure what to expect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this one looks right as is.
At L109, it is setting DNU for the integration if the whole ramp is saturated, which is still correct behavior.
After that, it is now setting a SAT flag for the integration if there was saturation anywhere in the ramp, which is also correct.
and update tests again. Deferring this to JP-4208 or spacetelescope/jwst#10089
Resolves JP-3967
This PR addresses spacetelescope/jwst#8124 by reverting a bit of #125
xref
Target build: 12.3
Notes from Ken MacDonald
There are several past PRs related to your ticket:
In particular, the SAT flag for an integration was set only if the entire integration was set. This has a couple of consequences. When SAT is set, so is DNU. This invalidates the data, making their values NaN.
Unfortunately, due to the "LIKELY" algorithm being done in Python, this is done in two parts of the code:
utils.pyfor the “LIKELY” andslope_fitter.cfor the “OLS” algorithm.Below are links to the relevant parts of the C extension.
The initial set up for SAT flagging is done here (done on intial read):
stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 1891 in b326357
Notice there is a
cnt_satvariable that gets updated. This makes it easy to fine fully saturated ramps.The setting of the integration level SAT is done here (done during processing):
stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 1295 in b326357
Here is the seeting of pedestal data based on the integration level saturation:
stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 1989 in b326357
Invalid data is defined as
DNU | SAT:stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 2148 in b326357
If a ramp is flagged as SAT, set its slope to NaN:
stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 2807 in b326357
If all ramps are flagged as SAT, flag exposure level pixel as SAT:
stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 2820 in b326357
If the entire ramp is flagged as SAT, flag the integration as SAT (done during non-chargeloss processing):
stcal/src/stcal/ramp_fitting/src/slope_fitter.c
Line 3005 in b326357
(At this point, Melanie Clarke and Tyler Pauly stressed that this PR should only change DQ array, not SCI nor ERR.)
When you updated the
utils.pyfile for DQ flagging, the test file that should have been updated wastest_ramp_fitting_likely_fit.py. The changes you made inutils.pydo not affect the tests intest_ramp_fitting.py, which is where you made all the test updates.The tests for ramp fitting are like this:
test_ramp_fitting_cas22.pyis for Roman, so no updates we do should affect this file.test_ramp_fitting_likely_fit.py.test_ramp_fitting.pyandtest_ramp_fitting_cases.pyTODO
test_ramp_fitting_cases.pyalso needs updating. Why have the changes so far not affecting it? What is it actually testing?slope_fitter.cmore sotest_ramp_fitting.pyandtest_ramp_fitting_cases.pypass.test_ramp_fitting_likely_fit.pywith theoretical expected result for successful reversion, then fixutils.py.test_ramp_fitting.pyTasks
docs/pageno-changelog-entry-needed)changes/:echo "changed something" > changes/<PR#>.<changetype>.rst(see below for change types)"git+https://github.com/<fork>/stcal@<branch>")stcal@git+https://github.com/pllim/stcal.git@life-of-a-sat-gridjwstregression test https://github.com/spacetelescope/RegressionTests/actions/runs/19578858266 and https://github.com/spacetelescope/RegressionTests/actions/runs/19901284665 and https://github.com/spacetelescope/RegressionTests/actions/runs/20248199486 and https://github.com/spacetelescope/RegressionTests/actions/runs/20289156418romancalregression test https://github.com/spacetelescope/RegressionTests/actions/runs/19578882303 and https://github.com/spacetelescope/RegressionTests/actions/runs/20248238781 and https://github.com/spacetelescope/RegressionTests/actions/runs/20289178794