Skip to content

Commit

Permalink
Fixing ZEROFRAME logic bug, as well as removing debugging code.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmacdonald-stsci committed Oct 17, 2023
1 parent 1d4efcc commit c788b07
Showing 1 changed file with 40 additions and 57 deletions.
97 changes: 40 additions & 57 deletions src/stcal/ramp_fitting/src/slope_fitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ struct pixel_ramp {
float zframe; /* The pixel ZEROFRAME */

/* Timing bool */
/* XXX should be arrays of length nints */
uint8_t * is_zframe; /* Boolean to use ZEROFRAME */
uint8_t * is_0th; /* Boolean to use ZEROFRAME */

Expand Down Expand Up @@ -564,6 +563,9 @@ print_pixel_ramp_dq(struct ramp_data * rd, struct pixel_ramp * pr, int line);
static void
print_pixel_ramp_info(struct ramp_data * rd, struct pixel_ramp * pr, int line);

static void
print_pixel_ramp_stats(struct pixel_ramp * pr, int line);

static void
print_PyArrayObject_info(PyArrayObject * obj);

Expand All @@ -586,6 +588,9 @@ print_segment_opt_res(
struct simple_ll_node * seg, struct ramp_data * rd,
npy_intp integ, int segnum, int line);

static void
print_stats(struct pixel_ramp * pr, npy_intp integ);

static void
print_uint8_array(uint8_t * arr, int len, int ret, int line);

Expand Down Expand Up @@ -722,7 +727,7 @@ ols_slope_fitter(PyObject * module, PyObject * args) {

goto CLEANUP;
ERROR:
/* XXX Clean up errors */
/* Clean up errors */
clean_rate_product(&rate_prod);
clean_rateint_product(&rateint_prod);

Expand Down Expand Up @@ -1412,6 +1417,13 @@ get_pixel_ramp(
pr->data[integ_idx] = zframe;
pr->groupdq[integ_idx] = 0;
pr->stats[integ].cnt_good = 1;
pr->stats[integ].cnt_dnu_sat--;
if (pr->ngroups == pr->stats[integ].cnt_sat) {
pr->stats[integ].cnt_sat--;
}
if (pr->ngroups == pr->stats[integ].cnt_dnu) {
pr->stats[integ].cnt_dnu--;
}
pr->is_zframe[integ] = 1;
}
}
Expand Down Expand Up @@ -1814,8 +1826,6 @@ median_rate_default(
for (integ = 0; integ < pr->nints; ++integ) {
current_integration = integ;

/* XXX current dev */

if (pr->is_0th[integ]) {
// dbg_ols_print("col %ld, is_0th\n", pr->col);
/* Special case of only good 0th group */
Expand Down Expand Up @@ -2012,7 +2022,6 @@ median_rate_integration_sort_cmp(
return ans;
}

/* XXX needs work */
static int
ols_slope_fit_pixels(
struct ramp_data * rd,
Expand All @@ -2027,8 +2036,6 @@ ols_slope_fit_pixels(
for (col = 0; col < rd->ncols; ++col) {
get_pixel_ramp(pr, rd, row, col);

/* XXX Maybe check pixeldq for bad pixel, so no usefule stuff. */

/* Compute ramp fitting */
if (ramp_fit_pixel(rd, pr)) {
ret = 1;
Expand Down Expand Up @@ -2159,16 +2166,10 @@ py_ramp_data_get_float(
float val;
int ans;

/* XXX Here */
Obj = PyObject_GetAttrString(rd, attr);
ans = PyFloat_Check(Obj);
val = (float)PyFloat_AsDouble(Obj);

/* XXX Not sure what to do here */
if (!ans) {
dbg_ols_print("ans = %d, PyFloat_Check(%s): False, val = %f\n", ans, attr, val);
}

return val;
}

Expand All @@ -2185,16 +2186,10 @@ py_ramp_data_get_int(
int val;
int ans;

/* XXX Here */
Obj = PyObject_GetAttrString(rd, attr);
ans = PyLong_Check(Obj);
val = (int)PyLong_AsLong(Obj);

/* XXX Not sure what to do here */
if (!ans) {
dbg_ols_print("ans = %d, PyFloat_Check(%s): False, val = %d\n", ans, attr, val);
}

return val;
}

Expand Down Expand Up @@ -2261,9 +2256,6 @@ ramp_fit_pixel(
pr->rate.slope = pr->rate.slope / pr->invvar_e_sum;
}

/* XXX */
//dbg_ols_print("pr->rateints[0].var_err = %f\n", pr->rateints[0].var_err);

END:
return ret;
}
Expand All @@ -2284,7 +2276,7 @@ ramp_fit_pixel_integration(
goto END;
}

if (0 == pr->stats[integ].cnt_good) {
if (rd->ngroups == pr->stats[integ].cnt_dnu_sat) {
pr->rateints[integ].dq |= rd->dnu;
if (rd->ngroups == pr->stats[integ].cnt_sat) {
pr->rateints[integ].dq |= rd->sat;
Expand Down Expand Up @@ -2332,12 +2324,6 @@ ramp_fit_pixel_integration_fit_slope(

invvar_e += (1. / current->var_e);

/* XXX */
if (0==integ && 0) {
tmp = (1. / current->var_e);
dbg_ols_print("current->var_e = %f\n", current->var_e);
dbg_ols_print("tmp = %f\n", tmp);
}
slope_i_num += (current->slope / current->var_e);
}

Expand All @@ -2350,11 +2336,6 @@ ramp_fit_pixel_integration_fit_slope(
pr->rateints[integ].slope = slope_i_num * var_err;
pr->rateints[integ].var_err = sqrt(var_err);

/* XXX */
if (0==integ && 0) {
dbg_ols_print("[%ld] var_err = %f\n", pr->rateints[integ].var_err);
}

/* Get rate pre-computations */
if (pr->median_rate > 0.) {
pr->rate.var_poisson += invvar_p;
Expand Down Expand Up @@ -2500,15 +2481,6 @@ ramp_fit_pixel_integration_fit_slope_seg_len2(
// seg->var_e = 2. * pr->rnoise * pr->rnoise; /* XXX Is this right? */
seg->var_e = seg->var_p + seg->var_r;

/* XXX */
if (0==integ && 0) {
print_delim();
dbg_ols_print("Integ: %ld, seg: %d\n", integ, segnum);
dbg_ols_print("pr->rnoise = %f\n", pr->rnoise);
dbg_ols_print("seg->var_e = %f\n", seg->var_e);
print_delim();
}

if (rd->save_opt) {
seg->sigslope = sqrt2 * pr->rnoise;
_2nd_read = (float)seg->start + 1.;
Expand All @@ -2522,18 +2494,6 @@ ramp_fit_pixel_integration_fit_slope_seg_len2(
seg->weight = wt;
}

if (0) {
print_delim();
tmp = 1. / seg->var_e;
dbg_ols_print("data_diff = %f\n", data_diff);
dbg_ols_print("yint = %f\n", seg->yint);
dbg_ols_print("var = %f\n", seg->var_e);
dbg_ols_print("invvar = %f\n", tmp);
dbg_ols_print("sigyint = %f\n", seg->sigyint);
dbg_ols_print("sigslope = %f\n", seg->sigslope);
print_delim();
}

return 0;
}

Expand Down Expand Up @@ -2651,7 +2611,6 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_seg(
/* Segment total variance */
seg->var_e = seg->var_p + seg->var_r;

/* XXX WEIGHTS */
if (rd->save_opt) {
seg->weight = 1. / seg->var_e;
seg->weight *= seg->weight;
Expand Down Expand Up @@ -2943,6 +2902,17 @@ print_segment_opt_res(
print_delim();
}

static void
print_stats(struct pixel_ramp * pr, npy_intp integ) {
print_delim();
dbg_ols_print("GDQ stats for integration %ld\n", integ);
dbg_ols_print(" cnt_sat = %d\n", pr->stats[integ].cnt_sat);
dbg_ols_print(" cnt_dnu = %d\n", pr->stats[integ].cnt_dnu);
dbg_ols_print(" cnt_dnu_sat = %d\n", pr->stats[integ].cnt_dnu_sat);
dbg_ols_print(" cnt_good = %d\n", pr->stats[integ].cnt_good);
dbg_ols_print(" jump_det = %d\n", pr->stats[integ].jump_det);
}

static void
print_uint8_array(uint8_t * arr, int len, int ret, int line) {
int k;
Expand Down Expand Up @@ -3037,7 +3007,6 @@ print_pixel_ramp_info(struct ramp_data * rd, struct pixel_ramp * pr, int line) {
printf("DQ:\n");
print_pixel_ramp_dq(rd, pr, -1);

/* XXX */
print_delim();
}

Expand Down Expand Up @@ -3087,6 +3056,20 @@ print_intp_array(npy_intp * arr, int len, int ret) {
return;
}

static void
print_pixel_ramp_stats(struct pixel_ramp * pr, int line)
{
npy_intp integ;

print_delim();
printf("[%d] Pixel ramp stats: \n", line);
for (integ=0; integ<pr->nints; ++integ) {
print_stats(pr, integ);
printf("\n");
}
print_delim();
}

/*
* Print some information about a PyArrayObject. This function is primarily
* used for debugging and development.
Expand Down

0 comments on commit c788b07

Please sign in to comment.