Skip to content

Commit

Permalink
Changing declaration statements causing build failures. Added debuggi…
Browse files Browse the repository at this point in the history
…ng macros.
  • Loading branch information
kmacdonald-stsci committed Dec 18, 2023
1 parent 7de15fe commit 0488219
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions src/stcal/ramp_fitting/src/slope_fitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pip install -e .
/* ------------------------------------------------------------------------- */
static npy_intp current_integration;
const float LARGE_VARIANCE = 1.e8;
const float LARGE_VARIANCE_THRESHOLD = (0.01 * LARGE_VARIANCE);
const float LARGE_VARIANCE_THRESHOLD = 1.e6;
/* ------------------------------------------------------------------------- */

/* ========================================================================= */
Expand Down Expand Up @@ -999,9 +999,9 @@ create_opt_res(
struct ramp_data * rd)
{
const npy_intp nd = 4;
npy_intp dims[nd] = {0};
npy_intp dims[nd];
const npy_intp pnd = 3;
npy_intp pdims[pnd] = {0};
npy_intp pdims[pnd];
const int fortran = 0; /* Want C order */
const char * msg = "Couldn't allocate memory for opt_res products.";

Expand Down Expand Up @@ -1110,7 +1110,7 @@ create_rate_product(
struct ramp_data * rd)
{
const npy_intp nd = 2;
npy_intp dims[nd] = {0};
npy_intp dims[nd];
const int fortran = 0;
const char * msg = "Couldn't allocate memory for rate products.";

Expand Down Expand Up @@ -1146,7 +1146,7 @@ create_rateint_product(
struct ramp_data * rd)
{
const npy_intp nd = 3;
npy_intp dims[nd] = {0};
npy_intp dims[nd];
const int fortran = 0;
const char * msg = "Couldn't allocate memory for rateint products.";

Expand Down Expand Up @@ -2201,6 +2201,13 @@ py_ramp_data_get_int(
return val;
}

#define DBG_RATE_INFO \
dbg_ols_print("(%ld, %ld) median rate = %f\n", pr->row, pr->col, pr->median_rate); \
dbg_ols_print("Rate slope: %f\n", pr->rate.slope); \
dbg_ols_print("Rate DQ: %f\n", pr->rate.dq); \
dbg_ols_print("Rate var_p: %f\n", pr->rate.var_poisson); \
dbg_ols_print("Rate var_r: %f\n\n", pr->rate.var_rnoise);

/*
* Ramp fit a pixel ramp.
*/
Expand Down Expand Up @@ -2278,6 +2285,8 @@ ramp_fit_pixel(
pr->rate.slope = pr->rate.slope / pr->invvar_e_sum;
}

// DBG_RATE_INFO; /* XXX */

END:
return ret;
}
Expand Down Expand Up @@ -2312,6 +2321,21 @@ ramp_fit_pixel_integration(
return ret;
}

#define DBG_SEG_ID \
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);

#define DBG_INTEG_INFO \
dbg_ols_print("Integ %ld slope: %f\n", integ, pr->rateints[integ].slope); \
dbg_ols_print("Integ %ld dq: %f\n", integ, pr->rateints[integ].dq); \
dbg_ols_print("Integ %ld var_p: %f\n", integ, pr->rateints[integ].var_poisson); \
dbg_ols_print("Integ %ld var_r: %f\n\n", integ, pr->rateints[integ].var_rnoise);

#define DBG_DEFAULT_SEG \
dbg_ols_print("current->slope = %f\n", current->slope); \
dbg_ols_print("current->var_p = %f\n", current->var_p); \
dbg_ols_print("current->var_r = %f\n", current->var_r);

static int
ramp_fit_pixel_integration_fit_slope(
struct ramp_data * rd,
Expand All @@ -2330,16 +2354,16 @@ 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;
}

// DBG_SEG_ID; /* XXX */
// DBG_DEFAULT_SEG;

invvar_r += (1. / current->var_r);
if (pr->median_rate > 0.) {
invvar_p += (1. / current->var_p);
Expand Down Expand Up @@ -2374,6 +2398,8 @@ ramp_fit_pixel_integration_fit_slope(
pr->rateints[integ].var_err = sqrt(var_err);
}

// DBG_INTEG_INFO; /* XXX */

/* Get rate pre-computations */
if (pr->median_rate > 0.) {
pr->rate.var_poisson += invvar_p;
Expand Down Expand Up @@ -2609,6 +2635,16 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_ols(
}
}

#define DBG_OLS_CALCS \
dbg_ols_print("sumx = %f\n", sumx); \
dbg_ols_print("sumxx = %f\n", sumxx); \
dbg_ols_print("sumy = %f\n", sumy); \
dbg_ols_print("sumxy = %f\n", sumxy); \
dbg_ols_print("sumw = %f\n", sumw); \
dbg_ols_print("num = %f\n", num); \
dbg_ols_print("den = %f\n", den); \
dbg_ols_print("slope = %f\n", slope);

/*
* From the intermediate values compute the optimally weighted
* OLS fit for a segment.
Expand Down Expand Up @@ -2636,6 +2672,8 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_seg(
seg->slope = slope / rd->group_time;
seg->sigslope = sqrt(sumw * invden);

// DBG_OLS_CALCS;

/* Segment Y-intercept and uncertainty */
seg->yint = (sumxx * sumy - sumx * sumxy) * invden;
seg->sigyint = sqrt(sumxx * invden);
Expand Down

0 comments on commit 0488219

Please sign in to comment.