Skip to content

Commit

Permalink
Updating the handling of bad gain values. Base ramp fit and case test…
Browse files Browse the repository at this point in the history
…ing pass.
  • Loading branch information
kmacdonald-stsci committed Dec 1, 2023
1 parent babd235 commit b5ed0dd
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/stcal/ramp_fitting/src/slope_fitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,12 +1492,16 @@ get_pixel_ramp_meta(
/* Get pixel and dimension data */
pr->row = row;
pr->col = col;
npy_intp integ;

pr->pixeldq = rd->get_pixeldq(rd->pixeldq, row, col);

pr->gain = rd->get_gain(rd->gain, row, col);
if (pr->gain < 0. || isnan(pr->gain)) {
if (pr->gain <= 0. || isnan(pr->gain)) {
pr->pixeldq |= (rd->dnu | rd->ngval);
for (integ=0; integ<rd->nints; ++integ) {
pr->rateints[integ].dq = pr->pixeldq;
}
}
pr->rnoise = rd->get_rnoise(rd->rnoise, row, col);
pr->rate.dq = pr->pixeldq;
Expand Down Expand Up @@ -2241,17 +2245,16 @@ ramp_fit_pixel(

if (rd->nints == dnu_cnt) {
pr->rate.dq |= rd->dnu;
pr->rate.slope = NAN;
}
if (rd->nints == sat_cnt) {
pr->rate.dq |= rd->sat;
pr->rate.slope = NAN;
}

if ((pr->median_rate > 0.) && (0. != pr->rate.var_poisson)) {
if ((pr->median_rate > 0.) && (pr->rate.var_poisson > 0.)) {
pr->rate.var_poisson = 1. / pr->rate.var_poisson;
}
if (pr->rate.var_poisson >= LARGE_VARIANCE_THRESHOLD) {
if ((pr->rate.var_poisson >= LARGE_VARIANCE_THRESHOLD)
|| (pr->rate.var_poisson < 0.)){
pr->rate.var_poisson = 0.;
}
if (pr->rate.var_rnoise > 0.) {
Expand All @@ -2261,6 +2264,14 @@ ramp_fit_pixel(
pr->rate.var_rnoise = 0.;
}
pr->rate.var_err = sqrt(pr->rate.var_poisson + pr->rate.var_rnoise);

if (pr->rate.dq & rd->invalid) {
pr->rate.slope = NAN;
pr->rate.var_poisson = 0.;
pr->rate.var_rnoise = 0.;
pr->rate.var_err = 0.;
}

if (!isnan(pr->rate.slope)) {
pr->rate.slope = pr->rate.slope / pr->invvar_e_sum;
}
Expand Down Expand Up @@ -2349,9 +2360,17 @@ ramp_fit_pixel_integration_fit_slope(
if (pr->rateints[integ].var_rnoise >= LARGE_VARIANCE_THRESHOLD) {
pr->rateints[integ].var_rnoise = 0.;
}
var_err = 1. / invvar_e;
pr->rateints[integ].slope = slope_i_num * var_err;
pr->rateints[integ].var_err = sqrt(var_err);

if (pr->rateints[integ].dq & rd->invalid) {
pr->rateints[integ].slope = NAN;
pr->rateints[integ].var_poisson = 0.;
pr->rateints[integ].var_rnoise = 0.;
pr->rateints[integ].var_err = 0.;
} else {
var_err = 1. / invvar_e;
pr->rateints[integ].slope = slope_i_num * var_err;
pr->rateints[integ].var_err = sqrt(var_err);
}

/* Get rate pre-computations */
if (pr->median_rate > 0.) {
Expand Down

0 comments on commit b5ed0dd

Please sign in to comment.