Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

drlaw1558
Copy link
Contributor

@drlaw1558 drlaw1558 commented Oct 15, 2024

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

  • update or add relevant tests
  • update relevant docstrings and / or docs/ page
  • Does this PR change any API used downstream? (if not, label with no-changelog-entry-needed)
    • write news fragment(s) in changes/: echo "changed something" > changes/<PR#>.<changetype>.rst (see below for change types)
    • run regression tests with this branch installed ("git+https://github.com/<fork>/stcal@<branch>")
news fragment change types...
  • changes/<PR#>.apichange.rst: change to public API
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.general.rst: infrastructure or miscellaneous change

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 77.77778% with 6 lines in your changes missing coverage. Please review.

Project coverage is 86.50%. Comparing base (60bd3b8) to head (3f6f8d3).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
src/stcal/jump/jump.py 77.77% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #306      +/-   ##
==========================================
+ Coverage   86.21%   86.50%   +0.29%     
==========================================
  Files          47       49       +2     
  Lines        8812     8868      +56     
==========================================
+ Hits         7597     7671      +74     
+ Misses       1215     1197      -18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@drlaw1558
Copy link
Contributor Author

Not sure why I can't request a review, but tagging @kmacdonald-stsci

@ddavis-stsci
Copy link
Collaborator

The romancal regression tests pass
https://github.com/spacetelescope/RegressionTests/actions/runs/11365425316
so we're good with the changes

Copy link
Collaborator

@kmacdonald-stsci kmacdonald-stsci left a 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.

@@ -317,6 +320,7 @@ def detect_jumps(
)
log.info("Total snowballs = %i", total_snowballs)
number_extended_events = total_snowballs

if find_showers:
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces after ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces after ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces after ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add spaces after ,.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# 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
Copy link
Collaborator

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.

Copy link
Contributor Author

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):
Copy link
Collaborator

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?

Copy link
Contributor Author

@drlaw1558 drlaw1558 Oct 17, 2024

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.

Copy link
Collaborator

@kmacdonald-stsci kmacdonald-stsci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@drlaw1558
Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants