From c73c78d4ae7989ac198988768e9e9f854ee01a0b Mon Sep 17 00:00:00 2001 From: Ken MacDonald Date: Fri, 19 Apr 2024 16:19:28 -0400 Subject: [PATCH] Updating the documentation and cleaning up the code, as well as integrating some new modifications for the average dark current usage. --- src/stcal/ramp_fitting/src/slope_fitter.c | 459 ++++++++++++---------- 1 file changed, 255 insertions(+), 204 deletions(-) diff --git a/src/stcal/ramp_fitting/src/slope_fitter.c b/src/stcal/ramp_fitting/src/slope_fitter.c index add60cb03..12d04bb0a 100644 --- a/src/stcal/ramp_fitting/src/slope_fitter.c +++ b/src/stcal/ramp_fitting/src/slope_fitter.c @@ -526,7 +526,7 @@ ramp_fit_pixel_integration_fit_slope( static int ramp_fit_pixel_integration_fit_slope_seg( struct simple_ll_node * current, - struct ramp_data * rd, struct pixel_ramp * pr, struct simple_ll_node * seg, + struct ramp_data * rd, struct pixel_ramp * pr, npy_intp integ, int segnum); static int @@ -811,8 +811,6 @@ add_segment_to_list( return 0; } - /* XXX HERE */ - /* Make sure memory allocation worked */ seg = (struct simple_ll_node*)calloc(1, sizeof(*seg)); if (NULL==seg) { @@ -1277,8 +1275,8 @@ create_segment_list() */ static real_t real_nan_median( - real_t * arr, /* */ - npy_intp len) /* */ + real_t * arr, /* Array of numbers. */ + npy_intp len) /* The length of the array. */ { real_t med = -1.; npy_intp nan_idx = 0, med_idx; @@ -1314,9 +1312,9 @@ real_nan_median( /* Get a float from a 2-D NDARRAY */ static float get_float2( - PyArrayObject * obj, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 2D python object from which to get a number */ + npy_intp row, /* The row of the number */ + npy_intp col) /* The colunn of the number */ { float ans; @@ -1328,9 +1326,9 @@ get_float2( /* Get a byteswapped float from a 2-D NDARRAY */ static float get_float2_swp( - PyArrayObject * obj, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 2D python object from which to get a number */ + npy_intp row, /* The row of the number */ + npy_intp col) /* The colunn of the number */ { union ENDIAN { uint32_t u; @@ -1346,11 +1344,11 @@ get_float2_swp( /* Get a float from a 4-D NDARRAY */ static float get_float4( - PyArrayObject * obj, - npy_intp integ, - npy_intp group, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp integ, /* The integration for the number */ + npy_intp group, /* The group for the number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { float ans; @@ -1362,11 +1360,11 @@ get_float4( /* Get a byteswapped float from a 4-D NDARRAY */ static float get_float4_swp( - PyArrayObject * obj, - npy_intp integ, - npy_intp group, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp integ, /* The integration for the number */ + npy_intp group, /* The group for the number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { union ENDIAN { uint32_t u; @@ -1379,12 +1377,13 @@ get_float4_swp( return endian.f; } +/* Get a float from a 3-D NDARRAY. */ static float get_float3( - PyArrayObject * obj, - npy_intp integ, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp integ, /* The integration for the number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { float ans; @@ -1393,12 +1392,13 @@ get_float3( return ans; } +/* Get a byteswapped float from a 3-D NDARRAY. */ static float get_float3_swp( - PyArrayObject * obj, - npy_intp integ, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp integ, /* The integration for the number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { union ENDIAN { uint32_t u; @@ -1411,20 +1411,22 @@ get_float3_swp( return endian.f; } +/* Get a uint32_t from a 2-D NDARRAY. */ static uint32_t get_uint32_2( - PyArrayObject * obj, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { return VOID_2_U32(PyArray_GETPTR2(obj, row, col)); } +/* Get a byteswapped uint32_t from a 2-D NDARRAY. */ static uint32_t get_uint32_2_swp( - PyArrayObject * obj, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { return BSWAP32(VOID_2_U32(PyArray_GETPTR2(obj, row, col))); } @@ -1432,11 +1434,11 @@ get_uint32_2_swp( /* Get a uint32_t from a 4-D NDARRAY */ static uint32_t get_uint32_4( - PyArrayObject * obj, - npy_intp integ, - npy_intp group, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp integ, /* The integration for the number */ + npy_intp group, /* The group for the number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { uint32_t ans; @@ -1448,11 +1450,11 @@ get_uint32_4( /* Get a byteswapped uint32_t from a 4-D NDARRAY */ static uint32_t get_uint32_4_swp( - PyArrayObject * obj, - npy_intp integ, - npy_intp group, - npy_intp row, - npy_intp col) + PyArrayObject * obj, /* The 4D python object from which to get a number */ + npy_intp integ, /* The integration for the number */ + npy_intp group, /* The group for the number */ + npy_intp row, /* The row for the number */ + npy_intp col) /* The colunn for the number */ { uint32_t ans = get_uint32_4(obj, integ, group, row, col); ans = BSWAP32(ans); @@ -1465,10 +1467,10 @@ get_uint32_4_swp( */ static void get_pixel_ramp( - struct pixel_ramp * pr, - struct ramp_data * rd, - npy_intp row, - npy_intp col) + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct ramp_data * rd, /* Ramp fitting data */ + npy_intp row, /* The row of the pixel */ + npy_intp col) /* The column of the pixel */ { npy_intp integ, group; ssize_t idx = 0, integ_idx; @@ -1516,15 +1518,18 @@ get_pixel_ramp( } } +/* + * For a given pixel, get the integration and group information. + */ static void get_pixel_ramp_integration( - struct pixel_ramp * pr, - struct ramp_data * rd, - npy_intp row, - npy_intp col, - npy_intp integ, - npy_intp group, - npy_intp idx) + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct ramp_data * rd, /* Ramp fitting data */ + npy_intp row, /* The row of the pixel */ + npy_intp col, /* The column of the pixel */ + npy_intp integ, /* The integration of the pixel */ + npy_intp group, /* The group of the pixel */ + npy_intp idx) /* The index of the pixel */ { /* For a single byte, no endianness handling necessary. */ pr->groupdq[idx] = VOID_2_U8(PyArray_GETPTR4( @@ -1553,12 +1558,15 @@ get_pixel_ramp_integration( } } +/* + * Get the meta data for a pixel. + */ static void get_pixel_ramp_meta( - struct pixel_ramp * pr, - struct ramp_data * rd, - npy_intp row, - npy_intp col) + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct ramp_data * rd, /* Ramp fitting data */ + npy_intp row, /* The row of the pixel */ + npy_intp col) /* The column of the pixel */ { /* Get pixel and dimension data */ pr->row = row; @@ -1579,9 +1587,13 @@ get_pixel_ramp_meta( pr->rate.dq = pr->pixeldq; } +/* + * Zeros out the pixel ramp data structure in preparation for getting + * the information for the next pixel ramp. + */ static void get_pixel_ramp_zero( - struct pixel_ramp * pr) + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { pr->pixeldq = 0.; pr->gain = 0.; @@ -1599,11 +1611,14 @@ get_pixel_ramp_zero( memset(&(pr->rate), 0, sizeof(pr->rate)); } +/* + * Get the segment list and pedestal for a given pixel integration. + */ static void get_pixel_ramp_integration_segments_and_pedestal( - npy_intp integ, - struct pixel_ramp * pr, - struct ramp_data * rd) + npy_intp integ, /* The integration of the pixel */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct ramp_data * rd) /* Ramp fitting data */ { npy_intp idx, idx_pr; real_t fframe, int_slope; @@ -1643,7 +1658,7 @@ get_pixel_ramp_integration_segments_and_pedestal( */ static struct ramp_data * get_ramp_data( - PyObject * args) + PyObject * args) /* Arguments from the C extension function call. */ { struct ramp_data * rd = calloc(1, sizeof(*rd)); /* Allocate memory */ PyObject * Py_ramp_data; @@ -1656,11 +1671,13 @@ get_ramp_data( return NULL; } + /* Parse the arguments */ if (get_ramp_data_parse(&Py_ramp_data, rd, args)) { FREE_RAMP_DATA(rd); return NULL; } + /* Get the ramp data arrays */ if (get_ramp_data_arrays(Py_ramp_data, rd)) { FREE_RAMP_DATA(rd); return NULL; @@ -1696,8 +1713,8 @@ get_ramp_data( */ static int get_ramp_data_arrays( - PyObject * Py_ramp_data, - struct ramp_data * rd) + PyObject * Py_ramp_data, /* RampData class python object */ + struct ramp_data * rd) /* Ramp fitting data */ { /* Get numpy arrays */ rd->data = (PyArrayObject*)PyObject_GetAttrString(Py_ramp_data, "data"); @@ -1726,8 +1743,8 @@ get_ramp_data_arrays( */ static void get_ramp_data_meta( - PyObject * Py_ramp_data, - struct ramp_data * rd) + PyObject * Py_ramp_data, /* RampData class python object */ + struct ramp_data * rd) /* Ramp fitting data */ { /* Get integer meta data */ rd->groupgap = py_ramp_data_get_int(Py_ramp_data, "groupgap"); @@ -1755,9 +1772,9 @@ get_ramp_data_meta( */ static int get_ramp_data_parse( - PyObject ** Py_ramp_data, - struct ramp_data * rd, - PyObject * args) + PyObject ** Py_ramp_data, /* RampData class python object */ + struct ramp_data * rd, /* Ramp fitting data */ + PyObject * args) /* Arguments from the C extension function call. */ { char * weight = NULL; const char * optimal = "optimal"; @@ -1792,7 +1809,7 @@ get_ramp_data_parse( */ static int get_ramp_data_new_validate( - struct ramp_data * rd) + struct ramp_data * rd) /* Ramp fitting data */ { char * msg; @@ -1828,7 +1845,7 @@ get_ramp_data_new_validate( */ static void get_ramp_data_dimensions( - struct ramp_data * rd) + struct ramp_data * rd) /* Ramp fitting data */ { npy_intp * dims; @@ -1846,7 +1863,7 @@ get_ramp_data_dimensions( static void get_ramp_data_endianness( - struct ramp_data * rd) + struct ramp_data * rd) /* Ramp fitting data */ { /* XXX Endianness is now handled in the python code before entering the extension */ @@ -1862,18 +1879,6 @@ get_ramp_data_endianness( rd->get_rnoise = get_float2; rd->get_zframe = get_float3; - -# if 0 - /* Byte swapping now handled in python code. */ - rd->get_data = (PyArray_ISBYTESWAPPED(rd->data)) ? get_float4_swp : get_float4; - rd->get_err = (PyArray_ISBYTESWAPPED(rd->err)) ? get_float4_swp : get_float4; - - rd->get_pixeldq = (PyArray_ISBYTESWAPPED(rd->pixeldq)) ? get_uint32_2_swp : get_uint32_2; - - rd->get_gain = (PyArray_ISBYTESWAPPED(rd->gain)) ? get_float2_swp : get_float2; - rd->get_rnoise = (PyArray_ISBYTESWAPPED(rd->rnoise)) ? get_float2_swp : get_float2; - rd->get_zframe = (PyArray_ISBYTESWAPPED(rd->zframe)) ? get_float3_swp : get_float3; -#endif } /* @@ -1882,8 +1887,8 @@ get_ramp_data_endianness( */ static int compute_median_rate( - struct ramp_data * rd, - struct pixel_ramp * pr) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { if (1 == rd->ngroups) { return median_rate_1ngroup(rd, pr); @@ -1891,10 +1896,14 @@ compute_median_rate( return median_rate_default(rd, pr); } +/* + * Compute the median rate for a pixel ramp for the special case of + * only one group ramps.. + */ static int median_rate_1ngroup( - struct ramp_data * rd, - struct pixel_ramp * pr) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { npy_intp idx, integ; real_t accum_mrate = 0.; @@ -1909,10 +1918,13 @@ median_rate_1ngroup( return 0; } +/* + * Compute the median rate for a pixel ramp for normal ramps. + */ static int median_rate_default( - struct ramp_data * rd, - struct pixel_ramp * pr) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { int ret = 0; real_t * int_data = (real_t*)calloc(pr->ngroups, sizeof(*int_data)); @@ -1931,22 +1943,20 @@ median_rate_default( // print_delim(); // dbg_ols_print("Pixel (%ld, %ld)\n", pr->row, pr->col); + /* Compute the median rate for the pixel. */ for (integ = 0; integ < pr->nints; ++integ) { current_integration = integ; if (pr->is_0th[integ]) { - // dbg_ols_print("col %ld, is_0th\n", pr->col); /* Special case of only good 0th group */ start_idx = get_ramp_index(rd, integ, 0); mrate = pr->data[start_idx] / rd->one_group_time; } else if (pr->is_zframe[integ]) { - // dbg_ols_print("col %ld, is_zframe\n", pr->col); /* Special case of using ZERFRAME data */ start_idx = get_ramp_index(rd, integ, 0); mrate = pr->data[start_idx] / rd->frame_time; } else { - // dbg_ols_print("col %ld, is_default\n", pr->col); /* Get the data and DQ flags for this integration. */ int_data = median_rate_get_data(int_data, integ, rd, pr); int_dq = median_rate_get_dq(int_dq, integ, rd, pr); @@ -1976,10 +1986,10 @@ median_rate_default( */ static real_t * median_rate_get_data ( - real_t * data, - npy_intp integ, - struct ramp_data * rd, - struct pixel_ramp * pr) + real_t * data, /* The location to receive the integration data */ + npy_intp integ, /* The intergration for the data */ + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { npy_intp start_idx = get_ramp_index(rd, integ, 0); @@ -1993,10 +2003,10 @@ median_rate_get_data ( */ static uint8_t * median_rate_get_dq ( - uint8_t * data, - npy_intp integ, - struct ramp_data * rd, - struct pixel_ramp * pr) + uint8_t * data, /* The location to receive the integration DQ flags */ + npy_intp integ, /* The intergration for the data */ + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { npy_intp group, idx = get_ramp_index(rd, integ, 0); @@ -2005,9 +2015,6 @@ median_rate_get_dq ( data[group] = pr->groupdq[idx]; } - /* I have no idea why this doesn't work, but the above does. */ - //memcpy(data, &(pr->groupdq[idx]), pr->ngroups * sizeof(data[0])); - return data; } @@ -2019,11 +2026,11 @@ median_rate_get_dq ( */ static int median_rate_integration( - real_t * mrate, - real_t * int_data, - uint8_t * int_dq, - struct ramp_data * rd, - struct pixel_ramp * pr) + real_t * mrate, /* The location to store the integraiton median rate */ + real_t * int_data, /* The integration data */ + uint8_t * int_dq, /* The integration DQ flags */ + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { int ret = 0; real_t * loc_integ = (real_t*)calloc(pr->ngroups, sizeof(*loc_integ)); @@ -2074,10 +2081,10 @@ median_rate_integration( */ static int median_rate_integration_sort( - real_t * loc_integ, - uint8_t * int_dq, - struct ramp_data * rd, - struct pixel_ramp * pr) + real_t * loc_integ, /* Local copy of the integration data */ + uint8_t * int_dq, /* Local copy of the integration DQ flags */ + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { npy_intp k, ngroups = pr->ngroups; real_t loc0 = loc_integ[0]; @@ -2106,7 +2113,6 @@ median_rate_integration_sort( loc_integ[0] = loc0; } - /* XXX */ // print_real_array("Pre-sort: ", loc_integ, ngroups-1, 1, __LINE__); /* NaN sort first differences */ qsort(loc_integ, ngroups-1, sizeof(loc_integ[0]), median_rate_integration_sort_cmp); @@ -2114,11 +2120,13 @@ median_rate_integration_sort( return nan_cnt; } -/* The comparison function for qsort with NaN's */ +/* + * The comparison function for qsort with NaN's + */ static int median_rate_integration_sort_cmp( - const void * aa, - const void * bb) + const void * aa, /* Pointer to a number to be compared */ + const void * bb) /* Pointer to a number to be compared */ { real_t a = VOID_2_REAL(aa); real_t b = VOID_2_REAL(bb); @@ -2140,12 +2148,15 @@ median_rate_integration_sort_cmp( return ans; } +/* + * Fit a ramp for each pixel. + */ static int ols_slope_fit_pixels( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct rate_product * rate_prod, - struct rateint_product * rateint_prod) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct rate_product * rate_prod, /* The rate product data structure */ + struct rateint_product * rateint_prod) /* The rateints product data structure */ { int ret = 0; npy_intp row, col; @@ -2165,7 +2176,6 @@ ols_slope_fit_pixels( ret = 1; goto END; } - // goto END; /* XXX REMOVED THIS!!! */ } } @@ -2173,10 +2183,14 @@ ols_slope_fit_pixels( return ret; } +/* + * Print the values for the various data types of interest and the + * data types we actually have. + */ static void print_ramp_data_types( - struct ramp_data * rd, - int line) + struct ramp_data * rd, /* Ramp fitting data */ + int line) /* Calling line */ { printf("[%s:%d]\n", __FILE__, line); printf("NPY_DOUBLE = %d\n", NPY_DOUBLE); @@ -2192,11 +2206,14 @@ print_ramp_data_types( printf("PyArray_TYPE(rd->rnoise)) = %d\n", PyArray_TYPE(rd->rnoise)); } +/* + * Packages objects to be returned from ramp fitting. + */ static PyObject * package_results( - struct rate_product * rate, - struct rateint_product * rateints, - struct ramp_data * rd) + struct rate_product * rate, /* The rate product data structure */ + struct rateint_product * rateints, /* The rateints product data structure */ + struct ramp_data * rd) /* Ramp fitting data */ { PyObject * image_info = Py_None; PyObject * cube_info = Py_None; @@ -2218,8 +2235,13 @@ package_results( return result; } +/* + * Prints meta data for the ramp data structure. + */ static void -print_rd_type_info(struct ramp_data * rd) { +print_rd_type_info( + struct ramp_data * rd) /* Ramp fitting data */ +{ print_delim(); print_npy_types(); dbg_ols_print("data = %d (%d)\n", PyArray_TYPE(rd->data), NPY_FLOAT); @@ -2237,7 +2259,7 @@ print_rd_type_info(struct ramp_data * rd) { */ static void prune_segment_list( - struct segment_list * segs) + struct segment_list * segs) /* The list of segments for the integration */ { struct simple_ll_node * seg = NULL; struct simple_ll_node * prev = NULL; @@ -2294,8 +2316,8 @@ prune_segment_list( */ static float py_ramp_data_get_float( - PyObject * rd, - const char * attr) + PyObject * rd, /* The python object for the ramp data */ + const char * attr) /* The float attribute to get */ { PyObject * Obj; float val; @@ -2312,8 +2334,8 @@ py_ramp_data_get_float( */ static int py_ramp_data_get_int( - PyObject * rd, - const char * attr) + PyObject * rd, /* The python object for the ramp data */ + const char * attr) /* The integer attribute to get */ { PyObject * Obj; int val; @@ -2338,8 +2360,8 @@ py_ramp_data_get_int( */ static int ramp_fit_pixel( - struct ramp_data * rd, - struct pixel_ramp * pr) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { int ret = 0; npy_intp integ; @@ -2383,6 +2405,8 @@ ramp_fit_pixel( } } + /* XXX Maybe shorten this function by making the below part of another function */ + if (rd->nints == dnu_cnt) { pr->rate.dq |= rd->dnu; } @@ -2427,9 +2451,9 @@ ramp_fit_pixel( */ static int ramp_fit_pixel_integration( - struct ramp_data * rd, - struct pixel_ramp * pr, - npy_intp integ) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + npy_intp integ) /* The integration */ { int ret = 0; @@ -2452,6 +2476,7 @@ ramp_fit_pixel_integration( return ret; } +/* Convenience macros for debugging */ #define DBG_SEG_ID do {\ dbg_ols_print(" *** [Integ: %ld] (%ld, %ld) Seg: %d, Length: %ld, Start: %ld, End: %ld\n", \ integ, pr->row, pr->col, segcnt, current->length, current->start, current->end); \ @@ -2471,11 +2496,14 @@ ramp_fit_pixel_integration( dbg_ols_print("current->var_e = %.10f\n", current->var_e); \ } while(0) +/* + * Fit the integration ramp. + */ static int ramp_fit_pixel_integration_fit_slope( - struct ramp_data * rd, - struct pixel_ramp * pr, - npy_intp integ) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + npy_intp integ) /* The integration */ { int ret = 0; int segcnt = 0; @@ -2486,6 +2514,8 @@ ramp_fit_pixel_integration_fit_slope( return ret; } + /* XXX Think about how to shorten this function */ + /* Fit slope to each segment. */ for (current = pr->segs[integ].head; current; current = current->flink) { segcnt++; @@ -2493,7 +2523,7 @@ ramp_fit_pixel_integration_fit_slope( // DBG_SEG_ID; /* XXX */ ret = ramp_fit_pixel_integration_fit_slope_seg( - current, rd, pr, current, integ, segcnt); + current, rd, pr, integ, segcnt); if (-1 == ret) { continue; } @@ -2552,14 +2582,16 @@ ramp_fit_pixel_integration_fit_slope( return ret; } +/* + * Fit slope to a segment of an integration. + */ static int ramp_fit_pixel_integration_fit_slope_seg( - struct simple_ll_node * current, - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - npy_intp integ, - int segnum) + struct simple_ll_node * current, /* The current segment to fit */ + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + npy_intp integ, /* The current integration */ + int segnum) /* The number of the current segment */ { // dbg_ols_print("[%ld] segnum = %d, length = %ld\n", integ, segnum, current->length); if (1 == current->length) { @@ -2580,15 +2612,15 @@ ramp_fit_pixel_integration_fit_slope_seg( } /* - * The default computation for a segment. + * The default computation for a segment default case. */ static int ramp_fit_pixel_integration_fit_slope_seg_default( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - npy_intp integ, - int segnum) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + npy_intp integ, /* The current integration */ + int segnum) /* The number of the current segment */ { int ret = 0; real_t snr, power; @@ -2608,13 +2640,16 @@ ramp_fit_pixel_integration_fit_slope_seg_default( return ret; } +/* + * The default computation for the special case of a segment of length 1. + */ static int ramp_fit_pixel_integration_fit_slope_seg_len1( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - npy_intp integ, - int segnum) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + npy_intp integ, /* The current integration */ + int segnum) /* The number of the current segment */ { npy_intp idx; real_t timing = rd->group_time; @@ -2634,7 +2669,7 @@ ramp_fit_pixel_integration_fit_slope_seg_len1( seg->slope = pr->data[idx] / timing; pden = (timing * pr->gain); - seg->var_p = (pr->median_rate pr->dcurrent) / pden; + seg->var_p = (pr->median_rate + pr->dcurrent) / pden; /* Segment read noise variance */ rnum = pr->rnoise / timing; @@ -2653,13 +2688,16 @@ ramp_fit_pixel_integration_fit_slope_seg_len1( return 0; } +/* + * The default computation for the special case of a segment of length 2. + */ static int ramp_fit_pixel_integration_fit_slope_seg_len2( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - npy_intp integ, - int segnum) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + npy_intp integ, /* The current integration */ + int segnum) /* The number of the current segment */ { npy_intp idx; real_t data_diff, _2nd_read, data0, data1, rnum, rden, pden; @@ -2679,7 +2717,7 @@ ramp_fit_pixel_integration_fit_slope_seg_len2( /* Segment Poisson variance */ if (pr->median_rate > 0.) { pden = (rd->group_time * pr->gain); - seg->var_p = (pr->median_rate pr->dcurrent) / pden; + seg->var_p = (pr->median_rate + pr->dcurrent) / pden; } else { seg->var_p = pr->dcurrent; } @@ -2726,12 +2764,12 @@ ramp_fit_pixel_integration_fit_slope_seg_len2( */ static void ramp_fit_pixel_integration_fit_slope_seg_default_weighted( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - npy_intp integ, - int segnum, - real_t power) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + npy_intp integ, /* The current integration */ + int segnum, /* The number of the current segment */ + real_t power) /* The power of the segment */ { struct ols_calcs ols = {0}; @@ -2751,13 +2789,13 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted( */ static void ramp_fit_pixel_integration_fit_slope_seg_default_weighted_ols( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - struct ols_calcs * ols, - npy_intp integ, - int segnum, - real_t power) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + struct ols_calcs * ols, /* Intermediate calculations */ + npy_intp integ, /* The current integration */ + int segnum, /* The number of the current segment */ + real_t power) /* The power of the segment */ { npy_intp idx, group; real_t mid, weight, invrn2, invmid, data, xval, xwt; @@ -2790,6 +2828,7 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_ols( } } +/* Convenience macros for debugging */ #define DBG_OLS_CALCS do { \ dbg_ols_print("sumx = %f\n", sumx); \ dbg_ols_print("sumxx = %f\n", sumxx); \ @@ -2808,13 +2847,13 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_ols( */ static void ramp_fit_pixel_integration_fit_slope_seg_default_weighted_seg( - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - struct ols_calcs * ols, - npy_intp integ, - int segnum, - real_t power) + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + struct ols_calcs * ols, /* Intermediate calculations */ + npy_intp integ, /* The current integration */ + int segnum, /* The number of the current segment */ + real_t power) /* The power of the segment */ { real_t slope, num, den, invden, rnum=0., rden=0., pden=0., seglen; real_t sumx=ols->sumx, sumxx=ols->sumxx, sumy=ols->sumy, @@ -2840,7 +2879,7 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_seg( /* Segment Poisson variance */ if (pr->median_rate > 0.) { pden = (rd->group_time * pr->gain * (seglen - 1.)); - seg->var_p = (pr->median_rate pr->dcurrent) / pden; + seg->var_p = (pr->median_rate + pr->dcurrent) / pden; } else { seg->var_p = pr->dcurrent; } @@ -2866,10 +2905,13 @@ ramp_fit_pixel_integration_fit_slope_seg_default_weighted_seg( } } +/* + * Save off the values computed for the optional results product. + */ static int save_opt_res( - struct opt_res_product * opt_res, - struct ramp_data * rd) + struct opt_res_product * opt_res, /* The optional results product */ + struct ramp_data * rd) /* The ramp fitting data */ { void * ptr = NULL; npy_intp integ, segnum, row, col, idx; @@ -2972,11 +3014,14 @@ save_opt_res( } /* XXX Can this fail? */ +/* + * Save the computed ramp fitting results. + */ static int save_ramp_fit( - struct rateint_product * rateint_prod, - struct rate_product * rate_prod, - struct pixel_ramp * pr) + struct rate_product * rate_prod, /* The rate product data structure */ + struct rateint_product * rateints_prod, /* The rateints product data structure */ + struct pixel_ramp * pr) /* Pixel ramp fitting data */ { void * ptr = NULL; npy_intp integ; @@ -3061,15 +3106,17 @@ save_ramp_fit( return 0; } -/* Compute the signal to noise ratio of the segment. */ +/* + * Compute the signal to noise ratio of the segment. + */ static int segment_snr( - real_t * snr, - npy_intp integ, - struct ramp_data * rd, - struct pixel_ramp * pr, - struct simple_ll_node * seg, - int segnum) + real_t * snr, /* The computed SNR */ + npy_intp integ, /* The current integration */ + struct ramp_data * rd, /* Ramp fitting data */ + struct pixel_ramp * pr, /* Pixel ramp fitting data */ + struct simple_ll_node * seg, /* The current segment to fit */ + int segnum) /* The number of the current segment */ { npy_intp idx_s, idx_e; real_t data, num, den, S, start, end, sqrt_den = 0.; @@ -3093,10 +3140,12 @@ segment_snr( return 0; } -/* Compute the weighting power based on the SNR. */ +/* + * Compute the weighting power based on the SNR. + */ static real_t snr_power( - real_t snr) + real_t snr) /* The computed SNR */ { if (snr < 5.) { return 0.; @@ -3117,6 +3166,8 @@ snr_power( /* Debug Functions */ /* ------------------------------------------------------------------------- */ +/* XXX HERE Maybe continue the documentation for debugging functions. */ + /* * This prints some of the ramp_data information. This function is primarily * used for debugging and development purposes.