-
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-3677: Add maximum_shower_amplitude parameter to jump step #306
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #306 +/- ##
===========================================
- Coverage 86.68% 29.56% -57.13%
===========================================
Files 49 37 -12
Lines 8937 8332 -605
===========================================
- Hits 7747 2463 -5284
- Misses 1190 5869 +4679 ☔ View full report in Codecov by Sentry. |
Not sure why I can't request a review, but tagging @kmacdonald-stsci |
The romancal regression tests pass |
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 are portions of the code that are invoked unconditionally, but included in conditionals, which results in two parts of the code that need to be maintained, when there could be a single unconditional call to be maintained.
Also, there are some formatting issues.
src/stcal/jump/jump.py
Outdated
@@ -317,6 +320,7 @@ def detect_jumps( | |||
) | |||
log.info("Total snowballs = %i", total_snowballs) | |||
number_extended_events = total_snowballs | |||
|
|||
if find_showers: |
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.
As noted in another PR, the find_showers
portion of the code is always invoked in both the if
and else
portion of the conditional. Since it is always executed unconditionally, it should be moved outside the conditional. This applies to the expand_large_events
portion of the code, 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.
Done
src/stcal/jump/jump.py
Outdated
# Approximate pre-shower rates | ||
tempdata = indata[intg,:,:,:].copy() | ||
# Ignore any groups flagged in the original gdq array | ||
tempdata[ingdq[intg,:,:,:] & donotuse_flag != 0] = np.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.
This could be combined into a single computation by setting invalid_flags = donotuse_flag | sat_flag | jump_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.
Done
src/stcal/jump/jump.py
Outdated
# Ensure that flagging showers didn't change final fluxes by more than the allowed amount | ||
for intg in range(nints): | ||
# Approximate pre-shower rates | ||
tempdata = indata[intg,:,:,:].copy() |
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.
Add spaces after ,
.
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.
Done
src/stcal/jump/jump.py
Outdated
# Approximate pre-shower rates | ||
tempdata = indata[intg,:,:,:].copy() | ||
# Ignore any groups flagged in the original gdq array | ||
tempdata[ingdq[intg,:,:,:] & donotuse_flag != 0] = np.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.
Add spaces after ,
.
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.
Done
src/stcal/jump/jump.py
Outdated
# Approximate post-shower rates | ||
tempdata = indata[intg,:,:,:].copy() | ||
# Ignore any groups flagged in the shower gdq array | ||
tempdata[gdq[intg,:,:,:] & donotuse_flag != 0] = np.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.
Add spaces after ,
.
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.
Done
src/stcal/jump/jump.py
Outdated
# became NaN or changed by more than the amount reasonable for a real CR shower | ||
diff = np.abs(image1 - image2) | ||
indx = np.where((np.isfinite(diff) == False)|(diff > max_shower_amplitude)) | ||
gdq[intg,:,indx[0],indx[1]] = ingdq[intg,:,indx[0],indx[1]] |
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.
Add spaces after ,
.
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.
Done
src/stcal/jump/jump.py
Outdated
# Approximate post-shower rates | ||
tempdata = indata[intg,:,:,:].copy() | ||
# Ignore any groups flagged in the shower gdq array | ||
tempdata[gdq[intg,:,:,:] & donotuse_flag != 0] = np.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.
This could be combined into a single computation by setting invalid_flags = donotuse_flag | sat_flag | jump_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.
Done
@@ -1111,6 +1123,39 @@ def find_faint_extended( | |||
num_grps_masked=num_grps_masked, | |||
max_extended_radius=max_extended_radius | |||
) | |||
|
|||
# Ensure that flagging showers didn't change final fluxes by more than the allowed amount | |||
for intg in range(nints): |
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 this loop needed? Is it possible to operate on the full data set, taking advantage of fast numpy looping, instead of slow explicit looping?
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.
Here the worry was that calling .copy() on the entire array could be extremely memory intensive for cases where there were a large number of integrations. Looping over the integration is less efficient, but it looks like it still only takes 3 seconds even for a TSO case broken into 18 ints, 30 groups, and 1024x1032 pixels.
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.
LGTM
Updated to catch additional runtime warnings, and ensure the maximum amplitude is passed in the correct units so that it works for both FAST and SLOW mode data. |
Added one more minor change based on feedback from @mwregan2 to fix a prior bug with propagating flags to smoothed masks. |
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.
Change fragment needs renamed from 307 --> 306. Otherwise looks good, will approve pending fix.
It looks like a primary result of the regresssion tests is a difference in how reference pixels are labeled - the test output shows the reference pixels now lack the DNU flag. Is this intended behavior? |
@tapastro Just double checked this for both MIRI MRS and Imaging detectors, and that change is fine. Without running find_showers the reference pixels do not get flagged as DO_NOT_USE by the jump step, and so this change actually makes their treatment more consistent between whether or not the showers algorithm was run. |
This PR addresses JP-3677 by adding a maximum_shower_amplitude parameter to the MIRI cosmic ray showers code, and ensuring that any changes in the rate image due to shower flagging are below this amplitude.
See also corresponding jwst PR spacetelescope/jwst#8890
Tasks
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>"
)jwst
regression testromancal
regression testnews fragment change types...
changes/<PR#>.apichange.rst
: change to public APIchanges/<PR#>.bugfix.rst
: fixes an issuechanges/<PR#>.general.rst
: infrastructure or miscellaneous change