Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3.13 preparation for ramp fitting. #303

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changes/303.general.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Preparing ramp fitting for the upgrade to python 3.13. In python 3.13, the C-API
function ``PyLong_AsLong`` raises an exception if the object passed to it is
``NoneType``. There are two integer attributes for the ``RampData`` class that
can be ``NoneType``, so a check for ``NoneType`` for these attributes was added.
30 changes: 28 additions & 2 deletions src/stcal/ramp_fitting/src/slope_fitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ const real_t LARGE_VARIANCE_THRESHOLD = 1.e6;
#define dbg_ols_print_pixel(PR) \
printf("[C:%d] Pixel (%ld, %ld)\n", __LINE__, (PR)->row, (PR)->col)


#define dbg_pyerr(S) \
do { \
print_delim(); \
dbg_ols_print("%s\n", S); \
PyErr_Print(); \
print_delim(); \
} while(0)

/* ------------------------------------------------------------------------- */

/* ========================================================================= */
Expand Down Expand Up @@ -1828,11 +1837,20 @@ get_ramp_data_meta(
PyObject * Py_ramp_data, /* The RampData class */
struct ramp_data * rd) /* The ramp data */
{
PyObject * test = Py_None;

/* Get integer meta data */
rd->groupgap = py_ramp_data_get_int(Py_ramp_data, "groupgap");
rd->nframes = py_ramp_data_get_int(Py_ramp_data, "nframes");
rd->suppress1g = py_ramp_data_get_int(Py_ramp_data, "suppress_one_group_ramps");
rd->dropframes = py_ramp_data_get_int(Py_ramp_data, "drop_frames1");

test = PyObject_GetAttrString(Py_ramp_data, "drop_frames1");
if (!test|| (test == Py_None)) {
rd->dropframes = 0;
} else {
rd->dropframes = py_ramp_data_get_int(Py_ramp_data, "drop_frames1");
}
Py_XDECREF(test);

rd->ped_tmp = ((rd->nframes + 1) / 2. + rd->dropframes) / (rd->nframes + rd->groupgap);

Expand All @@ -1842,7 +1860,15 @@ get_ramp_data_meta(
rd->sat = py_ramp_data_get_int(Py_ramp_data, "flags_saturated");
rd->ngval = py_ramp_data_get_int(Py_ramp_data, "flags_no_gain_val");
rd->uslope = py_ramp_data_get_int(Py_ramp_data, "flags_unreliable_slope");
rd->chargeloss = py_ramp_data_get_int(Py_ramp_data, "flags_chargeloss");

test = PyObject_GetAttrString(Py_ramp_data, "flags_chargeloss");
if (!test|| (test == Py_None)) {
rd->chargeloss = 0;
} else {
rd->chargeloss = py_ramp_data_get_int(Py_ramp_data, "flags_chargeloss");
}
Py_XDECREF(test);

rd->invalid = rd->dnu | rd->sat;

/* Debugging switch */
Expand Down
Loading