-
Notifications
You must be signed in to change notification settings - Fork 169
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-3593: Saturation step should increase flagging for group 3 saturation #8499
Changes from 22 commits
9e79eff
f2ba9c8
9335de7
d4658b3
f8e394c
a436b40
5333cea
0455eb1
5a2601c
85a7bab
4300770
d64c67c
9948880
0f145e5
343b631
17677b0
f7271da
b632603
850aa05
9b01f26
444b11e
66d98d3
fdcbd8d
1207d58
8f90a84
be2b053
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,8 @@ def flag_saturation(input_model, ref_model, n_pix_grow_sat): | |
""" | ||
|
||
data = input_model.data | ||
ngroups = input_model.meta.exposure.ngroups | ||
nframes = input_model.meta.exposure.nframes | ||
|
||
# Create the output model as a copy of the input | ||
output_model = input_model.copy() | ||
|
@@ -68,9 +70,10 @@ def flag_saturation(input_model, ref_model, n_pix_grow_sat): | |
sat_dq = ref_sub_model.dq.copy() | ||
ref_sub_model.close() | ||
|
||
read_pattern = [[x + 1 + groupstart * nframes for x in range(nframes)] for groupstart in range(ngroups)] | ||
gdq_new, pdq_new, zframe = flag_saturated_pixels( | ||
data, gdq, pdq, sat_thresh, sat_dq, ATOD_LIMIT, dqflags.pixel, | ||
n_pix_grow_sat=n_pix_grow_sat, zframe=zframe) | ||
n_pix_grow_sat=n_pix_grow_sat, read_pattern=read_pattern, zframe=zframe) | ||
|
||
# Save the flags in the output GROUPDQ array | ||
output_model.groupdq = gdq_new | ||
|
@@ -117,6 +120,8 @@ def irs2_flag_saturation(input_model, ref_model, n_pix_grow_sat): | |
nints = data.shape[0] | ||
ngroups = data.shape[1] | ||
detector = input_model.meta.instrument.detector | ||
nframes = input_model.meta.exposure.nframes | ||
read_pattern = [[x + 1 + groupstart * nframes for x in range(nframes)] for groupstart in range(ngroups)] | ||
|
||
# create a mask of the appropriate size | ||
irs2_mask = x_irs2.make_mask(input_model) | ||
|
@@ -160,6 +165,31 @@ def irs2_flag_saturation(input_model, ref_model, n_pix_grow_sat): | |
irs2_mask, detector) | ||
# check for saturation | ||
flag_temp = np.where(sci_temp >= sat_thresh, SATURATED, 0) | ||
if group == 2: | ||
# Identify groups which we wouldn't expect to saturate by the third group, | ||
# on the basis of the first group | ||
scigp1 = x_irs2.from_irs2(data[ints, 0, :, :], irs2_mask, detector) | ||
mask = scigp1 / np.mean(read_pattern[0]) * read_pattern[2][-1] < sat_thresh | ||
|
||
# Identify groups with suspiciously large values in the second group | ||
scigp2 = x_irs2.from_irs2(data[ints, 1, :, :], irs2_mask, detector) | ||
mask &= scigp2 > sat_thresh / len(read_pattern[1]) | ||
|
||
# Identify groups that are saturated in the third group | ||
gp3mask = np.where(flag_temp & SATURATED, True, False) | ||
mask &= gp3mask | ||
|
||
# Flag the 2nd group for the pixels passing that gauntlet | ||
dq_temp = x_irs2.from_irs2(groupdq[ints, 1, :, :], irs2_mask, detector) | ||
dq_temp[mask] |= SATURATED | ||
# flag any pixels that border saturated pixels | ||
if n_pix_grow_sat > 0: | ||
dq_temp = adjacency_sat(dq_temp, SATURATED, n_pix_grow_sat) | ||
# set the flags in dq array for group 2, i.e. index 1 | ||
x_irs2.to_irs2(flagarray, dq_temp, irs2_mask, detector) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is being passed back correctly; we're populating flagarray, but flagarray only gets put into the groupdq array a few lines later for group==2 whereas we're trying to set saturation bits for group==1. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @drlaw1558 I made some changes and I believe you were correct and now it sets the flags ok, can you verify please? |
||
np.bitwise_or(groupdq[ints, 1, ...], flagarray, | ||
groupdq[ints, 1, ...]) | ||
|
||
# check for A/D floor | ||
flaglow_temp = np.where(sci_temp <= 0, AD_FLOOR | DONOTUSE, 0) | ||
|
||
|
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.
Nearly there, but I think this line is problematic. Since it's using the existing groupdq array, it's going to be growing ALL pixels flagged as SATURATED, not just those that passed the gauntlet above, so things in group1 will get grown twice.
I think this should be possible to deal with by replacing
dq_temp = x_irs2.from_irs2(groupdq[ints, 1, :, :], irs2_mask, detector)
with
dq_temp = np.zeros_like(mask).astype(int)
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.
I suppose it would probably be better form though to explicitly cast the dq_temp to be the same dtype as groupdq.