Skip to content

Commit

Permalink
Safety catch to ensure we dont flag too much with micrometeorite routine
Browse files Browse the repository at this point in the history
  • Loading branch information
drlaw1558 committed Oct 21, 2024
1 parent 66f0bb6 commit 272dcfc
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/stcal/jump/jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,12 +490,16 @@ def detect_jumps(
return gdq, pdq, total_primary_crs, number_extended_events, stddev

# Find micrometeorite flashes
def find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac):
def find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac, mmflashnmax=5):
"""
This routine looks for micrometeorite flashes that light up the entire array in a small number
of groups. It does this by looking for cases where greater than mmflash_pct percent
of the array is flagged as 'JUMP_DET', and flags the entire array as JUMP_DET in such cases.
Since such flashes are rare (a few per instrument per year, although they can affect 2-3 groups)
this routine also applies a safety catch to ensure that not too many are flagged in any one
exposure due to unexpected detector effects.
Parameters
----------
gdq : int, 4D array
Expand All @@ -505,6 +509,9 @@ def find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac):
mmflashfrac : float
Fraction of the array that can be flagged as a jump before the entire array
will be flagged.
mmflashnmax : float
Maximum number of groups in any given exposure that can be affected by
micrometeorites before we declare a detection failure and flag nothing.
Returns
-------
gdq : int, 4D array
Expand All @@ -516,15 +523,30 @@ def find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac):
nints, ngroups, nrows, ncols = gdq.shape

Check warning on line 523 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L523

Added line #L523 was not covered by tests

npix = nrows * ncols # Number of pixels in array

Check warning on line 525 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L525

Added line #L525 was not covered by tests

# Initial loop over integrations + groups to find flashes
flash_int, flash_group = [], []

Check warning on line 528 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L528

Added line #L528 was not covered by tests
# Loop over integrations
for ii in range(0, nints):

Check warning on line 530 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L530

Added line #L530 was not covered by tests
# Loop over groups
for jj in range(0, ngroups):
indx = np.where(gdq[ii, jj, :, :] & jump_flag != 0)
fraction = float(len(indx[0])) / npix
if (fraction > mmflashfrac):
gdq[ii, jj, :, :] = gdq[ii, jj, :, :] | jump_flag
log.info(f"Detected a micrometeorite flash in integ = {ii}, group = {jj}")
flash_int.append(ii)
flash_group.append(jj)

Check warning on line 537 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L532-L537

Added lines #L532 - L537 were not covered by tests

# If an unrealistically large number of flashes were found, fail out
nflash=len(flash_int)
if (nflash > mmflashnmax):
log.info(f"Unreasonably large number of possible micrometeorite flashes detected ({nflash})")
log.info("Quitting micrometeorite routine and flagging nothing.")

Check warning on line 543 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L540-L543

Added lines #L540 - L543 were not covered by tests
else:
for kk in range(0, nflash):
ii, jj = flash_int[kk], flash_group[kk]
gdq[ii, jj, :, :] = gdq[ii, jj, :, :] | jump_flag
log.info(f"Flagged a micrometeorite flash in integ = {ii}, group = {jj}")

Check warning on line 548 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L545-L548

Added lines #L545 - L548 were not covered by tests

return gdq

Check warning on line 550 in src/stcal/jump/jump.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L550

Added line #L550 was not covered by tests

def flag_large_events(
Expand Down

0 comments on commit 272dcfc

Please sign in to comment.