Skip to content

Commit

Permalink
Updating the computation of SNR to handle non-positive values.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmacdonald-stsci committed Dec 14, 2023
1 parent b5ed0dd commit 4e31c5b
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions src/stcal/ramp_fitting/src/slope_fitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,7 @@ ols_slope_fit_pixels(
ret = 1;
goto END;
}
// goto END; /* XXX REMOVED THIS!!! */
}
}

Expand Down Expand Up @@ -2217,6 +2218,7 @@ ramp_fit_pixel(
ret = 1;
goto END;
}
// dbg_ols_print("(%ld, %ld) median rate = %f\n", pr->row, pr->col, pr->median_rate);

/* Clean up any thing from the last pixel ramp */
clean_segment_list(pr->nints, pr->segs);
Expand Down Expand Up @@ -2328,15 +2330,15 @@ ramp_fit_pixel_integration_fit_slope(
/* Fit slope to each segment. */
for (current = pr->segs[integ].head; current; current = current->flink) {
segcnt++;
#if 0
dbg_ols_print(" *** [%ld] (%ld, %ld) Seg: %d, Length: %ld, Start: %ld, End: %ld\n",
integ, pr->row, pr->col, segcnt, current->length, current->start, current->end);
#endif
ret = ramp_fit_pixel_integration_fit_slope_seg(
current, rd, pr, current, integ, segcnt);
if (-1 == ret) {
continue;
}
#if 0
dbg_ols_print(" *** [%ld] (%ld, %ld) Seg: %d, Length: %ld, Start: %ld, End: %ld\n",
integ, pr->row, pr->col, segcnt, current->length, current->start, current->end);
#endif

invvar_r += (1. / current->var_r);
if (pr->median_rate > 0.) {
Expand Down Expand Up @@ -2394,17 +2396,17 @@ ramp_fit_pixel_integration_fit_slope_seg(
{
// dbg_ols_print("[%ld] segnum = %d, length = %ld\n", integ, segnum, current->length);
if (1 == current->length) {
//dbg_ols_print("(%ld, %ld) Segment %d has length 1\n", pr->row, pr->col, segnum);
// dbg_ols_print("(%ld, %ld) Segment %d has length 1\n", pr->row, pr->col, segnum);
rd->special1++;
return ramp_fit_pixel_integration_fit_slope_seg_len1(
rd, pr, current, integ, segnum);
} else if (2 == current->length) {
//dbg_ols_print("(%ld, %ld) Segment %d has length 2\n", pr->row, pr->col, segnum);
// dbg_ols_print("(%ld, %ld) Segment %d has length 2\n", pr->row, pr->col, segnum);
rd->special2++;
return ramp_fit_pixel_integration_fit_slope_seg_len2(
rd, pr, current, integ, segnum);
}
//dbg_ols_print("(%ld, %ld) Segment %d has length >2\n", pr->row, pr->col, segnum);
// dbg_ols_print("(%ld, %ld) Segment %d has length >2\n", pr->row, pr->col, segnum);

return ramp_fit_pixel_integration_fit_slope_seg_default(
rd, pr, current, integ, segnum);
Expand Down Expand Up @@ -2783,7 +2785,6 @@ segment_snr(
{
npy_intp idx_s, idx_e;
float data, num, den, S, start, end;
//char * msg = NULL;

idx_s = get_ramp_index(rd, integ, seg->start);
idx_e = idx_s + seg->length - 1;
Expand All @@ -2792,17 +2793,8 @@ segment_snr(
data = end - start;
den = pr->rnoise * pr->rnoise + data * pr->gain;

if (den < 0.) {
/* XXX
* Not sure if this exception should be here.
* If not exception could set snr to -1. as an
* indication of failure.
*/
// msg = "SNR denominator is less than or equal to zero";
//PyErr_SetString(PyExc_ValueError, msg);
//err_ols_print("(%ld, %ld) %s\n", pr->row, pr->col, msg);
*snr = -1.;
return 1;
if (0.0 == den) {
*snr = 0.;
} else {
num = data * pr->gain;
S = num / sqrt(den);
Expand Down

0 comments on commit 4e31c5b

Please sign in to comment.