Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
Add unit tests
  • Loading branch information
mwregan2 committed Nov 12, 2024
1 parent 6985732 commit fb6bfea
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/stcal/jump/twopoint_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,27 @@ def find_crs(
min_usable_groups = ngrps - max_flagged_grps
total_groups = nints * ngrps - total_flagged_grps
min_usable_diffs = min_usable_groups - 1
# Determine whether there are enough usable groups for both the two sigma clip options and
# baseline jump detection.
if ((only_use_ints and nints < minimum_sigclip_groups) # sigclip across ints with not enough ints
or (not only_use_ints and (ngrps < minimum_sigclip_groups) and # sigclip within an int not enough groups
min_usable_groups < minimum_groups)): # regular jump detection minimum groups
log.info("Jump Step was skipped because exposure has less than the minimum number of usable groups")
dummy = np.zeros((dataa.shape[1] - 1, dataa.shape[2], dataa.shape[3]), dtype=np.float32)
return gdq, row_below_gdq, row_above_gdq, 0, dummy
sig_clip_grps_fails = False
total_noise_min_grps_fails = False
# Determine whether there are enough usable groups the two sigma clip options
if (only_use_ints and nints < minimum_sigclip_groups) \
or \
(not only_use_ints and total_sigclip_groups < minimum_sigclip_groups):
sig_clip_grps_fails = True
if min_usable_groups < minimum_groups:
total_noise_min_grps_fails = True

if total_noise_min_grps_fails and sig_clip_grps_fails:
log.info("Jump Step was skipped because exposure has less than the minimum number of usable groups")
dummy = np.zeros((dataa.shape[1] - 1, dataa.shape[2], dataa.shape[3]), dtype=np.float32)
return gdq, row_below_gdq, row_above_gdq, -99, dummy
#
# if ((only_use_ints and nints < minimum_sigclip_groups) # sigclip across ints with not enough ints
# or (not only_use_ints and (ngrps < minimum_sigclip_groups) and # sigclip within an int not enough groups
# min_usable_groups < minimum_groups)): # regular jump detection minimum groups
# log.info("Jump Step was skipped because exposure has less than the minimum number of usable groups")
# dummy = np.zeros((dataa.shape[1] - 1, dataa.shape[2], dataa.shape[3]), dtype=np.float32)
# return gdq, row_below_gdq, row_above_gdq, -99, dummy
else:
# set 'saturated' or 'do not use' pixels to nan in data
dat[np.where(np.bitwise_and(gdq, sat_flag))] = np.nan
Expand Down
92 changes: 92 additions & 0 deletions tests/test_twopoint_difference.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,98 @@ def _cube(ngroups, nints=1, nrows=204, ncols=204, readnoise=10):

return _cube

def test_sigclip_not_enough_groups(setup_cube):
ngroups = 10
nints = 9
nrows = 200
ncols = 200
data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=8, nrows=2, ncols=2, readnoise=8)
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(

Check warning on line 30 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L25-L30

Added lines #L25 - L30 were not covered by tests
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=10, minimum_groups=5
)
assert total_crs == -99

Check warning on line 35 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L35

Added line #L35 was not covered by tests

def test_sigclip_not_enough_groups(setup_cube):
ngroups = 5
nints = 9
nrows = 200
ncols = 200
data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=8, nrows=2, ncols=2, readnoise=8)
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(

Check warning on line 43 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L38-L43

Added lines #L38 - L43 were not covered by tests
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=11, minimum_groups=6
)
assert total_crs == -99

Check warning on line 48 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L48

Added line #L48 was not covered by tests

def test_sigclip_not_enough_groups(setup_cube):
ngroups = 12
nints = 9
nrows = 200
ncols = 200

data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=8, nrows=2, ncols=2, readnoise=8)
data[0, 0:2, 0:, 0] = 1
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=11, minimum_groups=16
)
assert total_crs == -99

def test_sigclip_with_num_small_groups(setup_cube):
ngroups = 12
nints = 190

data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=nints, nrows=2, ncols=2, readnoise=8)
data[0, 0:2, 0:, 0] = 1
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=11, minimum_groups=16
)
assert total_crs != -99

def test_nosigclip_with_enough_groups(setup_cube):
ngroups = 12
nints = 1

data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=nints, nrows=2, ncols=2, readnoise=8)
data[0, 0:2, 0:, 0] = 1
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=11, minimum_groups=5
)
assert total_crs != -99

def test_nosigclip_with_num_small_groups(setup_cube):
ngroups = 4
nints = 1

Check warning on line 93 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L92-L93

Added lines #L92 - L93 were not covered by tests

data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=nints, nrows=2, ncols=2, readnoise=8)
data[0, 0:2, 0:, 0] = 1
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(

Check warning on line 97 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L95-L97

Added lines #L95 - L97 were not covered by tests
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=11, minimum_groups=16
)
assert total_crs == -99

Check warning on line 102 in tests/test_twopoint_difference.py

View check run for this annotation

Codecov / codecov/patch

tests/test_twopoint_difference.py#L102

Added line #L102 was not covered by tests

def test_nosigclip_with_num_small_groups(setup_cube):
ngroups = 4
nints = 100

data, gdq, nframes, read_noise, rej_threshold = setup_cube(ngroups, nints=nints, nrows=2, ncols=2, readnoise=8)
data[0, 0:2, 0:, 0] = 1
out_gdq, row_below_gdq, rows_above_gdq, total_crs, stddev = find_crs(
data, gdq, read_noise, rej_threshold, rej_threshold, rej_threshold,
nframes, False, 200, 10, DQFLAGS,
minimum_sigclip_groups=100, minimum_groups=16
)
assert total_crs != -99

def test_varying_groups(setup_cube):
ngroups = 5
Expand Down

0 comments on commit fb6bfea

Please sign in to comment.