-
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
RCAL-511 Implement Uneven ramp fitting #175
RCAL-511 Implement Uneven ramp fitting #175
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #175 +/- ##
==========================================
- Coverage 74.41% 74.11% -0.30%
==========================================
Files 29 33 +4
Lines 5944 6100 +156
==========================================
+ Hits 4423 4521 +98
- Misses 1521 1579 +58
☔ View full report in Codecov by Sentry. |
f38cdbc
to
f27f0b4
Compare
Developer note: None of the model and reference file handling has yet to be added. Currently planned on handling this in |
Just realized there was a commit that was neglected. Will be re-applying it shortly. |
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.
Many functions are too long and complicated.
If reasonable, attempts should be made to keep variable names across the code base the same. For example, nreads
and variations were often used interchangeably with group and frame time, making the code confusing to follow. Also, not sure why use the variable name resultant
, rather than group
, since they seem to be used for the same thing.
The code appears to properly implement the algorithm from Casertano's paper.
src/stcal/ramp_fitting/ols_cas21.pyx
Outdated
for j in range(resstart[i], resend[i] + 1): | ||
# Casertano+22 Eq. 37 | ||
# Note that we are replacing ww with kk to save memory; we don't | ||
# need ww again. |
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.
Should this say "we don't need kk again"?
src/stcal/ramp_fitting/ols_cas21.pyx
Outdated
The first resultant in this ramp | ||
resend : np.ndarray[nramp] | ||
The last resultant in this ramp. | ||
""" |
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.
This function is 100 lines long and does many things. In general functions should be able to completely fit on a screen, so roughly 35-45 lines, and shorter if possible. It would be easier to read and maintain if broken down into smaller functions.
""" | ||
firstreads = np.array([x[0] for x in ma_table]) | ||
nreads = np.array([x[1] for x in ma_table]) | ||
meantimes = read_time * firstreads + read_time * (nreads - 1) / 2 |
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.
Is read_time
frame time or group time? In other ramp fitting software, read_time
or something similar was used interchangeably with group and frame time, causing confusion in how the code works.
src/stcal/ramp_fitting/ols_cas21.pyx
Outdated
|
||
Parameters | ||
---------- | ||
resultants : np.ndarry[nresultants, npixel] |
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.
Is there a reason to use the term "resultant", rather than "group"? It would be good to try to keep nomenclature across files the same, when it makes sense.
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.
Roman and JWST are using different terminology for this. Roman terms this "resultant", so its not clear how to name this.
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 understand that, but this is STCAL. It's supposed to be telescope agnostic. Developing parallel code bases with different nomenclature for the same thing undermines being agnostic.
tests/test_ramp_fitting_cas21.py
Outdated
assert result == expected | ||
|
||
|
||
def test_ramp(test_table=None): |
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 is a lot of things being tested in this one test. It should be broken into smaller tests, with each test testing fewer things.
|
||
Returns | ||
------- | ||
par : np.ndarray[..., 2] (float) |
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.
Why use the variable name par
?
the read noise, Poisson source noise, and total noise. | ||
""" | ||
|
||
# Get the Multi-accum table, either as given or from the read pattern |
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.
This is a very long function, over 150 lines and should be broken down into smaller functions.
FWIW, some of the nomenclature answers:
|
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.
Modulo the given comments, LGTM.
Since I don't see JWST using this for their ramp analysis so the Roman specific nomenclature should not be too confusing.
014cbc7
to
44a7109
Compare
0832df9
to
553dd45
Compare
Finally addressing comments. @kmacdonald-stsci : Agree with most everything. Driver of not doing too much refactoring/naming conventions are primarily that this algorithm is still undergoing algorithmic/science discussion. Kept the implementation close to the original so that discussion would not be confused by refactor/rename issues. Also, the JWST use is still down-the-road so the terminology issue, though definitely needing to be addressed, will be so later on. Of course, this is all modulo what RCAL would like to see in the current PR. |
Hi Jonathan, This looks good. Thinking about next steps:
|
Some external feedback on the terminology issue: At the 20230720 TIPS, the terminology issue was brought up, of which Casertano defended the current uneven/Roman centric form. Unless there is strong reason to change in this PR, I propose to deal with it in a later PR. |
IMOP I think terminology should follow whatever the reference paper uses if possible as we may have to refer back to the paper in the future. It is unfortunate that the two telescopes could not agree on terminology. |
@schlafly The |
Oh no, you're right, I don't want to bring in l1.apportion_counts_to_resultants. That's more detailed than we need for this. Let me rig up a simulate_many_ramps replacement that would be appropriate here; it's not so bad. |
# For Roman, the read time of the detectors is a fixed value and is currently | ||
# backed into code. Will need to refactor to consider the more general case. | ||
# Used to deconstruct the MultiAccum tables into integration times. | ||
READ_TIME = 3.04 |
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.
Oops, this is Roman specific. We need to pull this out as an argument.
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.
Seems there was some recent discussion of this value, potentially coming from PPS. I am not seeing anything like this in the schema. What is the process to retrieve from PPS and add as a meta value to the Level 1 file?
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.
also note: this is already an argument. the above is the default. However, I will move this into romancal and make the argument required.
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.
This is the value to use: https://github.com/spacetelescope/rad/blob/main/src/rad/resources/schemas/exposure-1.0.0.yaml#L268
I don't know if we're populating it yet usually.
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.
Sorry I missed that you were just using FRAME_TIME as a default. I agree with you that it makes more sense to have that on the romancal side.
With the caveat that I haven't tested anything, so I'm sure it's full of bugs, here's a simpler version of simulate_many_ramps...
This is a good simulation of a ramp in the context of the assumptions inherent in the algorithm. That's better than trying to bring over stuff from l1.apportion_counts_to_resultants, sorry for the bad pointer. |
Changes: - fix circular import between `matable_fit` and `matable_fit_cas2022`. - Update tests from `romanisim` to work completely within `stcal`. - Allow test to use `romanisim` if present.
Initial implementation done. However, untested and tests need to be implemented.
This reverts commit a34fc59.
This reverts commit 1d310a2.
This reverts commit 63512ec.
ef8b39f
to
36a1136
Compare
Got the romanisim test dependency completed. However, I want to point out a C-ism that was causing issues. In
generates an error concerning not being able to coerce a complex number to double. This error appeared after taking in the memory enhancement changes Eddy made in the romanisim version. The condition when this occurs seems to be when The error does suggest setting of a cython parameter, |
Oops, I hit this one too. This happened when cython 3 came out a week or two ago. I tried pinging you here but should have followed up. spacetelescope/romanisim#67 (comment) |
Resolves RCAL-511
This PR implements the Casertino, et.al., 2021 algorithm for fitting unevenly spaced ramps. Initial implementation based primarily on code from
romanisim
.Checklist
CHANGES.rst
(either inBug Fixes
orChanges to API
)