Skip to content

Commit

Permalink
Code style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
drlaw1558 committed Oct 17, 2024
1 parent 495655d commit 66f0bb6
Showing 1 changed file with 77 additions and 98 deletions.
175 changes: 77 additions & 98 deletions src/stcal/jump/jump.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,51 +304,6 @@ def detect_jumps(
dqflags['DO_NOT_USE']
gdq[gdq == np.bitwise_or(dqflags['SATURATED'], dqflags['JUMP_DET'])] = \
dqflags['SATURATED']
# This is the flag that controls the flagging of snowballs.
if expand_large_events:
gdq, total_snowballs = flag_large_events(
gdq,
jump_flag,
sat_flag,
min_sat_area=min_sat_area,
min_jump_area=min_jump_area,
expand_factor=expand_factor,
sat_required_snowball=sat_required_snowball,
min_sat_radius_extend=min_sat_radius_extend,
edge_size=edge_size,
sat_expand=sat_expand,
max_extended_radius=max_extended_radius,
mask_persist_grps_next_int=mask_persist_grps_next_int,
persist_grps_flagged=persist_grps_flagged,
)
log.info("Total snowballs = %i", total_snowballs)
number_extended_events = total_snowballs
if find_showers:
gdq, num_showers = find_faint_extended(
data,
gdq,
pdq,
readnoise_2d,
frames_per_group,
minimum_sigclip_groups,
dqflags,
snr_threshold=extend_snr_threshold,
min_shower_area=extend_min_area,
inner=extend_inner_radius,
outer=extend_outer_radius,
sat_flag=sat_flag,
jump_flag=jump_flag,
ellipse_expand=extend_ellipse_expand_ratio,
num_grps_masked=grps_masked_after_shower,
max_extended_radius=max_extended_radius,
)
log.info("Total showers= %i", num_showers)
number_extended_events = num_showers

# This is where we look for micrometeorite flashes if the triggering
# threshold is less than the entire array
if (mmflashfrac < 1):
gdq = find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac)

else:
yinc = int(n_rows // n_slices)
Expand Down Expand Up @@ -475,51 +430,53 @@ def detect_jumps(
gdq[gdq == np.bitwise_or(dqflags['SATURATED'], dqflags['JUMP_DET'])] = \
dqflags['SATURATED']

# This is the flag that controls the flagging of snowballs.
if expand_large_events:
gdq, total_snowballs = flag_large_events(
gdq,
jump_flag,
sat_flag,
min_sat_area=min_sat_area,
min_jump_area=min_jump_area,
expand_factor=expand_factor,
sat_required_snowball=sat_required_snowball,
min_sat_radius_extend=min_sat_radius_extend,
edge_size=edge_size,
sat_expand=sat_expand,
max_extended_radius=max_extended_radius,
mask_persist_grps_next_int=mask_persist_grps_next_int,
persist_grps_flagged=persist_grps_flagged,
)
log.info("Total snowballs = %i", total_snowballs)
number_extended_events = total_snowballs
if find_showers:
gdq, num_showers = find_faint_extended(
data,
gdq,
pdq,
readnoise_2d,
frames_per_group,
minimum_sigclip_groups,
dqflags,
snr_threshold=extend_snr_threshold,
min_shower_area=extend_min_area,
inner=extend_inner_radius,
outer=extend_outer_radius,
sat_flag=sat_flag,
jump_flag=jump_flag,
ellipse_expand=extend_ellipse_expand_ratio,
num_grps_masked=grps_masked_after_shower,
max_extended_radius=max_extended_radius,
)
log.info("Total showers= %i", num_showers)
number_extended_events = num_showers
# Look for snowballs in near-IR data
if expand_large_events:
gdq, total_snowballs = flag_large_events(

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L435

Added line #L435 was not covered by tests
gdq,
jump_flag,
sat_flag,
min_sat_area=min_sat_area,
min_jump_area=min_jump_area,
expand_factor=expand_factor,
sat_required_snowball=sat_required_snowball,
min_sat_radius_extend=min_sat_radius_extend,
edge_size=edge_size,
sat_expand=sat_expand,
max_extended_radius=max_extended_radius,
mask_persist_grps_next_int=mask_persist_grps_next_int,
persist_grps_flagged=persist_grps_flagged,
)
log.info("Total snowballs = %i", total_snowballs)
number_extended_events = total_snowballs

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L450-L451

Added lines #L450 - L451 were not covered by tests

# Look for showers in mid-IR data
if find_showers:
gdq, num_showers = find_faint_extended(

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L455

Added line #L455 was not covered by tests
data,
gdq,
pdq,
readnoise_2d,
frames_per_group,
minimum_sigclip_groups,
dqflags,
snr_threshold=extend_snr_threshold,
min_shower_area=extend_min_area,
inner=extend_inner_radius,
outer=extend_outer_radius,
sat_flag=sat_flag,
jump_flag=jump_flag,
ellipse_expand=extend_ellipse_expand_ratio,
num_grps_masked=grps_masked_after_shower,
max_extended_radius=max_extended_radius,
)
log.info("Total showers= %i", num_showers)
number_extended_events = num_showers

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L473-L474

Added lines #L473 - L474 were not covered by tests

# This is where we look for micrometeorite flashes if the triggering
# threshold is less than the entire array
if (mmflashfrac < 1):
gdq = find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac)
# Look for micrometeorite flashes if the triggering
# threshold is less than the entire array
if (mmflashfrac < 1):
gdq = find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac)

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L479

Added line #L479 was not covered by tests

elapsed = time.time() - start
log.info("Total elapsed time = %g sec", elapsed)
Expand All @@ -532,20 +489,42 @@ def detect_jumps(
# Return the updated data quality arrays
return gdq, pdq, total_primary_crs, number_extended_events, stddev

# Find micrometeorite flashes that light up the entire array in a small number
# of groups. Do this by looking for cases where greater than mmflash_pct percent
# of the array is flagged as 'JUMP_DET' and flag the entire array.
# Find micrometeorite flashes
def find_micrometeorite_flashes(gdq, jump_flag, mmflashfrac):
npix = gdq.shape[2]*gdq.shape[3] # Number of pixels in array
"""
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.
Parameters
----------
gdq : int, 4D array
Group dq array
jump_flag : int
DQ flag for jump detection.
mmflashfrac : float
Fraction of the array that can be flagged as a jump before the entire array
will be flagged.
Returns
-------
gdq : int, 4D array
Updated group dq array
"""
log.info("Looking for micrometeorite flashes")

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L514

Added line #L514 was not covered by tests

nints, ngroups, nrows, ncols = gdq.shape

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L516

Added line #L516 was not covered by tests

npix = nrows * ncols # Number of pixels in array

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L518

Added line #L518 was not covered by tests
# Loop over integrations
for ii in range(0,gdq.shape[0]):
for ii in range(0, nints):

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

View check run for this annotation

Codecov / codecov/patch

src/stcal/jump/jump.py#L520

Added line #L520 was not covered by tests
# Loop over groups
for jj in range(0,gdq.shape[1]):
indx = np.where(gdq[ii,jj,:,:] & jump_flag != 0)
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("Detected a micrometeorite flash in integ = %i, group= %i", ii, jj)
gdq[ii, jj, :, :] = gdq[ii, jj, :, :] | jump_flag
log.info(f"Detected a micrometeorite flash in integ = {ii}, group = {jj}")
return gdq

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#L522-L528

Added lines #L522 - L528 were not covered by tests

def flag_large_events(
Expand Down

0 comments on commit 66f0bb6

Please sign in to comment.