-
Notifications
You must be signed in to change notification settings - Fork 32
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-3576: Implement the Ramp Fitting Likelihood Algorithm #278
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #278 +/- ##
==========================================
+ Coverage 84.63% 84.69% +0.06%
==========================================
Files 41 44 +3
Lines 7628 8501 +873
==========================================
+ Hits 6456 7200 +744
- Misses 1172 1301 +129 ☔ View full report in Codecov by Sentry. |
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.
Comments are all minor docstring edits apart from one check to make sure that definitions of read noise are consistently referring to single read (=CDS/sqrt(2)) for all algorithms. I think the answer is yes, but I want to be completely certain.
@kmacdonald-stsci - in this comment from @t-brandt: It looks to me like the PR on JWST is skipping jump: I'm just starting to look at these code changes, but did the code here get updated to expect previously set jump flags? Or did we decide to skip jump in the detector1 pipeline when algorithm=LIKELY after all? |
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 think this needs quite a bit of clean up before it's ready to merge.
Most of it is code style related and documentation clarification, but I have a few significant structural concerns:
- Will jump be skipped in detector1 or no? See previous comment - we may need to run jump for 1/f purposes, and ignore the input flags here.
- We should add parameter passing structures for the detection threshold - currently
nsig
, but should berejection_threshold
, I think? And we need a test for that branch of the code. - There is code related to a pedestal calculation that looks unused and untested. If we don't plan to offer it, we should remove it.
Also - I'd like to test this on real data, but will wait for the issue with skipping jump to be settled.
Of course. As has been discussed many times, this is simply the initial implementation of the likelihood algorithm for ramp fitting. The implementation right now is to make the algorithm available for those interested in investigating it, which includes investigating the pedestal. The details for full integration into the existing pipeline have not been completely resolved, such as the separation of jump detection so it can be used as the preceding step for 1/f before running ramp fitting. |
dd8ba53
to
9469506
Compare
would this need a corresponding PR in |
This does have a corresponding JWST PR here: spacetelescope/jwst#8631 |
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.
Getting closer, thanks for all the updates!
A few lingering clean up issues still, noted below.
Testing this on some real data now to verify the various options are working as expected. I see significant differences between running with standard jump detection turned on in the pipeline and with it set to skip. With jump on and algorithm=LIKELY, the output is very similar to standard ramp fitting. With jump off and algorithm=LIKELY, the results from ramp fitting are @kmacdonald-stsci - I expected that the likelihood algorithm should be ignoring any previously set jump flags, so running with and without jump detection on should have identical results, but that's not the case. Can you please investigate?
Edit: reinstalling and testing again, I can't reproduce the very poor results I first saw with LIKELY + no jump - I assume something was off in my environment. However, I do still see differences between running with and without standard jump on, so that needs investigation. |
Please send me the data you are using and the specific pixels you are noticing as different. |
0ef30be
to
9c7e438
Compare
Finally had a chance to test this out a little. A few quick comments:
|
For @drlaw1558: this ramp fitting approach was never designed to outperform an efficient implementation of the Fixsen algorithm (which has a cost linear in the number of groups, with a small prefactor). This approach retains the linear scaling albeit with a larger prefactor. So if both the C implementation and this one are perfectly implemented, I would expect the C version to run faster by a factor of at least 5. This approach would offer significant performance gains if the Fixsen approach were implemented very inefficiently, as was previously the case. The appeal to the likelihood-based approach is the science gain (no bias, optimal SNR, optimal CR sensitivity), especially for long ramps, combined with perfect scaling with ramp size and a modest performance hit--a fixed factor--relative to the Fixsen algorithm. My expectation is that this approach should take 5-10 seconds for 10 groups full frame with CR flagging. |
Just wanted to check in, @kmacdonald-stsci : have you had a chance to investigate the files that David mentioned above? We're hoping to get this in soon, i.e. prior to CoB Thursday, so I want to make sure we address these issues found during testing. |
No. I am still investigating the files Melanie gave me. |
I fixed the jump detection differences and suppressed the warnings you were seeing. The integrations get combined here: @t-brandt is the behavior @drlaw1558 notes above expected with respect to NaN's? |
Based on the code link, I think the issue is the np.median and np.sum statements. np.median would probably replace easily with np.nanmedian, although the np.sum calls would be a little trickier. np.nansum returns 0 for all-NaN inputs which isn't desirable either, so we'd want something that ignores NaNs if present but return NaN if all inputs are NaN. |
^^^
|
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.
Reviewing again, I think all my comments on the code and docs clean up have been addressed, except for one more documentation clarification, below.
Thanks for fixing the jump flags and excessive warnings! I'm testing again on my data examples now.
I do think we should address the issue David pointed out with the NaNs in integration combination, but assuming local tests look good, we should be okay to get this in after that.
I am not sure if this comment is still relevant, but my suggestion for the NaNs when combining multiple integrations is to replace NaN values with zeros in the count rate and in the inverse variance. Then, they will receive zero weight when adding the to valid measurements, and if there are no valid measurements, you will wind up with 0/0. |
Hmm, okay, I'll install again in a clean environment and test again. Have you or @drlaw1558 checked that the NaN combination issues with jw01247667001_02101_00001_mirifulong_uncal.fits are now resolved? |
I still see the same differences after pulling and reinstalling, but even if it isn't just me, they are small, and there is a workaround -- just don't run the jump step, as is recommended. I think we can leave that for future work. I also tried reducing jw01247667001_02101_00001_mirifulong_rate.fits with your latest changes, and I don't see excessive NaNs, so I think that's fixed too. |
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.
All my comments have been addressed. Thanks for all the hard work on getting this ready!
Resolves JP-3576
This PR implements the likelihood algorithm for ramp fitting developed by Timothy Brandt in
Optimal Fitting and Debiasing for Detectors Read Out Up-the-Ramp
.Checklist
CHANGES.rst
(either inBug Fixes
orChanges to API
)