Skip to content

Conversation

@pllim
Copy link
Contributor

@pllim pllim commented Oct 24, 2025

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.py for the “LIKELY” and
  • slope_fitter.c for 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):

pr->stats[integ].cnt_sat++;

Notice there is a cnt_sat variable 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):

if ( (!chargeloss) && (groupdq[0] & rd->sat)) {

Here is the seeting of pedestal data based on the integration level saturation:

if (pr->rateints[integ].dq & rd->sat) {

Invalid data is defined as DNU | SAT:

rd->invalid = rd->dnu | rd->sat;

If a ramp is flagged as SAT, set its slope to NaN:

if (pr->rateints[integ].dq & rd->sat) {

If all ramps are flagged as SAT, flag exposure level pixel as SAT:

if (rd->nints == sat_cnt) {

If the entire ramp is flagged as SAT, flag the integration as SAT (done during non-chargeloss processing):

pr->rateints[integ].dq |= rd->sat;

(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.py file for DQ flagging, the test file that should have been updated was test_ramp_fitting_likely_fit.py. The changes you made in utils.py do not affect the tests in test_ramp_fitting.py, which is where you made all the test updates.

The tests for ramp fitting are like this:

  • test_ramp_fitting_cas22.py is for Roman, so no updates we do should affect this file.
  • The LIKELY algorithm affects tests in test_ramp_fitting_likely_fit.py.
  • The OLS algorithm (the C-extension) will affect the other two ramp fitting test modules: test_ramp_fitting.py and test_ramp_fitting_cases.py

TODO

  • Discuss with Ken on the state of this PR. Why did Ken's commit not fix the failing tests, given the tests have been updated to values expected on successful reversion? How to proceed?
  • See if test_ramp_fitting_cases.py also needs updating. Why have the changes so far not affecting it? What is it actually testing?
  • Change slope_fitter.c more so test_ramp_fitting.py and test_ramp_fitting_cases.py pass.
  • Change test_ramp_fitting_likely_fit.py with theoretical expected result for successful reversion, then fix utils.py.
  • Verify expected results for LIKELY algorithm added to test_ramp_fitting.py

Tasks

@github-actions github-actions bot added documentation Improvements or additions to documentation ramp_fitting testing labels Oct 24, 2025
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.02%. Comparing base (17e1705) to head (63391e8).
⚠️ Report is 1 commits behind head on main.

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.
📢 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.

@pllim pllim force-pushed the life-of-a-sat-grid branch from b42c50d to 78bbefa Compare November 17, 2025 22:48
@pllim

This comment was marked as resolved.

@kmacdonald-stsci
Copy link
Collaborator

I don't mind. We probably should have worked to get this in first, then reformatted, but 🤷🏻‍♂️.

@pllim pllim force-pushed the life-of-a-sat-grid branch from c6b5ff5 to 1272f00 Compare November 21, 2025 04:00
Copy link
Contributor Author

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!

Copy link
Collaborator

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.

@pllim

This comment was marked as resolved.

@pllim
Copy link
Contributor Author

pllim commented Nov 21, 2025

There is one failure on romancal that looks related (test_liklihood_rampfit: romancal.regtest.test_ramp_fit_likelihood) though the diff is hard for me to understand.

https://github.com/spacetelescope/RegressionTests/actions/runs/19578882303/attempts/1#summary-56071572672

FAILED romancal/regtest/test_ramp_fit_likelihood.py::test_liklihood_rampfit - AssertionError: 
  Diff report for:
      result file: r0000101001001001001_0001_wfi01_f158_like_rampfit.asdf
          model type: ImageModel
      truth file: truth/r0000101001001001001_0001_wfi01_f158_like_rampfit.asdf
          model type: ImageModel
  
  {'arrays_differ': {"root['roman']['dq']": {'abs_diff': np.uint64(2018634628180),
                                             'n_diffs': np.int64(313),
                                             'worst_abs_diff': {'index': (np.int64(401),
                                                                          np.int64(522)),
                                                                'value': np.uint32(4294967294)},
                                             'worst_fractional_diff': {'index': (np.int64(0),
                                                                                 np.int64(23)),
                                                                       'value': np.float64(1.0)}}}}

@pllim
Copy link
Contributor Author

pllim commented Nov 21, 2025

@pllim pllim marked this pull request as ready for review November 21, 2025 19:16
@pllim pllim requested a review from a team as a code owner November 21, 2025 19:16
Copy link
Collaborator

@schlafly schlafly left a 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)

pllim added a commit to pllim/jwst that referenced this pull request Nov 24, 2025
pllim added a commit to pllim/jwst that referenced this pull request Nov 25, 2025
pllim added a commit to pllim/jwst that referenced this pull request Nov 25, 2025
pllim added a commit to pllim/jwst that referenced this pull request Nov 26, 2025
pllim added a commit to pllim/jwst that referenced this pull request Dec 3, 2025
@pllim pllim force-pushed the life-of-a-sat-grid branch 2 times, most recently from 211cba2 to 4ac7661 Compare December 10, 2025 03:54
pllim added a commit to pllim/jwst that referenced this pull request Dec 10, 2025
@pllim

This comment was marked as resolved.

pllim added a commit to pllim/jwst that referenced this pull request Dec 10, 2025
@pllim pllim force-pushed the life-of-a-sat-grid branch from 4ac7661 to 558a923 Compare December 10, 2025 18:07
pllim added a commit to pllim/jwst that referenced this pull request Dec 11, 2025
@pllim pllim force-pushed the life-of-a-sat-grid branch from 558a923 to 16edac2 Compare December 11, 2025 20:37
…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
@pllim pllim force-pushed the life-of-a-sat-grid branch from 16edac2 to af54218 Compare December 12, 2025 22:32
pllim added a commit to pllim/jwst that referenced this pull request Dec 12, 2025
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
@pllim pllim force-pushed the life-of-a-sat-grid branch from d7ca60b to de35dc6 Compare December 15, 2025 21:14
@pllim pllim mentioned this pull request Dec 15, 2025
7 tasks


# Suppress one group ramps, if desired.
if ramp_data.suppress_one_group_ramps:
Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Collaborator

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.

Copy link
Contributor Author

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?

Copy link
Collaborator

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.

Copy link
Contributor

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.

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 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.

Copy link
Contributor Author

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.
Copy link
Contributor Author

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.

Copy link
Contributor

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
pllim added a commit to pllim/jwst that referenced this pull request Dec 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation ramp_fitting saturation testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants