Skip to content

Commit

Permalink
JP-3678: Ensure C extension works with multiprocessing (#268)
Browse files Browse the repository at this point in the history
* Updating the use of the C extension, making sure the selection of the C extension gets properly set for multiprocessing.

* Updating the change log.

* Changing some logging statements from 'info' to 'debug'.
  • Loading branch information
kmacdonald-stsci authored Jul 5, 2024
1 parent 3fa4d42 commit 8a36bf4
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ Changes to API
Bug Fixes
---------

-

ramp_fitting
~~~~~~~~~~~~

- When OLS_C was selected as the ramp fitting algorithm with multiprocessing, the C
extension was not called. The old python code was called. This bug has been fixed,
so the C extension is properly run when selecting multiprocessing. [#268]

1.7.2 (2024-06-12)
==================
Expand Down
12 changes: 9 additions & 3 deletions src/stcal/ramp_fitting/ols_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def ols_ramp_fit_multi(ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, wei
nrows = ramp_data.data.shape[2]
num_available_cores = cpu_count()
number_slices = utils.compute_num_slices(max_cores, nrows, num_available_cores)
log.info(f"Number of multiprocessing slices: {number_slices}")

# For MIRI datasets having >1 group, if all pixels in the final group are
# flagged as DO_NOT_USE, resize the input model arrays to exclude the
Expand Down Expand Up @@ -574,6 +575,8 @@ def slice_ramp_data(ramp_data, start_row, nrows):
ramp_data_slice.start_row = start_row
ramp_data_slice.num_rows = nrows

ramp_data_slice.run_c_code = ramp_data.run_c_code

return ramp_data_slice


Expand Down Expand Up @@ -661,19 +664,20 @@ def ols_ramp_fit_single(ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, we
opt_info : tuple
The tuple of computed optional results arrays for fitting.
"""
# use_c = False
# use_c = True # XXX Change to default as False
use_c = ramp_data.dbg_run_c_code
use_c = ramp_data.run_c_code
if use_c:
c_start = time.time()

ramp_data, gain_2d, readnoise_2d, bswap = endianness_handler(ramp_data, gain_2d, readnoise_2d)

if ramp_data.drop_frames1 is None:
ramp_data.drop_frames1 = 0
log.debug("Entering C extension")
image_info, integ_info, opt_info = ols_slope_fitter(
ramp_data, gain_2d, readnoise_2d, weighting, save_opt)

log.debug("Returning from C extension")

c_end = time.time()

# Read noise is used after STCAL ramp fitting for the CHARGELOSS
Expand All @@ -694,8 +698,10 @@ def ols_ramp_fit_single(ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, we

p_start = time.time()

log.debug("Entering python code")
image_info, integ_info, opt_info = ols_ramp_fit_single_python(
ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, weighting)
log.debug("Returning from python ")

p_end = time.time()
p_diff = p_end - p_start
Expand Down
2 changes: 1 addition & 1 deletion src/stcal/ramp_fitting/ramp_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def ramp_fit(
ramp_data = create_ramp_fit_class(model, dqflags, suppress_one_group)

if algorithm.upper() == "OLS_C":
ramp_data.dbg_run_c_code = True
ramp_data.run_c_code = True

return ramp_fit_data(
ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, algorithm, weighting, max_cores, dqflags
Expand Down
2 changes: 1 addition & 1 deletion src/stcal/ramp_fitting/ramp_fit_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self):
self.suppress_one_group_ramps = False

# C code debugging switch.
self.dbg_run_c_code = False
self.run_c_code = False

self.one_groups_locs = None # One good group locations.
self.one_groups_time = None # Time to use for one good group ramps.
Expand Down

0 comments on commit 8a36bf4

Please sign in to comment.