Skip to content

Commit

Permalink
Updating the STCAL code to use the algorithm class variable in the JW…
Browse files Browse the repository at this point in the history
…ST RampFitStep class to call the C code vs the python code. To call the C code set the algorithm class variable needs to be set to 'OLS_C'.
  • Loading branch information
kmacdonald-stsci committed Apr 24, 2024
1 parent a91f089 commit 10f7f74
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/stcal/ramp_fitting/ols_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,9 @@ 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 = False
# use_c = True
# use_c = ramp_data.dbg_run_c_code
use_c = ramp_data.dbg_run_c_code
if use_c:
print(" ")
print("=" * 80)
Expand All @@ -689,6 +689,11 @@ def ols_ramp_fit_single(ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, we
if gain_bswap:
gain_2d.newbyteorder('S').byteswap(inplace=True)

Check warning on line 690 in src/stcal/ramp_fitting/ols_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ols_fit.py#L686-L690

Added lines #L686 - L690 were not covered by tests

c_diff = c_end - c_start
print('-' * 80)
print(f" **** Total C time: {c_diff}")
print('-' * 80)

Check warning on line 695 in src/stcal/ramp_fitting/ols_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ols_fit.py#L692-L695

Added lines #L692 - L695 were not covered by tests

return image_info, integ_info, opt_info

Check warning on line 697 in src/stcal/ramp_fitting/ols_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ols_fit.py#L697

Added line #L697 was not covered by tests

# XXX start python time
Expand All @@ -702,8 +707,10 @@ def ols_ramp_fit_single(ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, we

# XXX end python time
p_end = time.time()
if use_c:
c_python_time_comparison(c_start, c_end, p_start, p_end)
p_diff = p_end - p_start
print('-' * 80)
print(f" **** Total Python time: {p_diff}")
print('-' * 80)

return image_info, integ_info, opt_info

Expand Down
4 changes: 4 additions & 0 deletions src/stcal/ramp_fitting/ramp_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ def ramp_fit(
# data models.
ramp_data = create_ramp_fit_class(model, dqflags, suppress_one_group)

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

Check warning on line 176 in src/stcal/ramp_fitting/ramp_fit.py

View check run for this annotation

Codecov / codecov/patch

src/stcal/ramp_fitting/ramp_fit.py#L175-L176

Added lines #L175 - L176 were not covered by tests

return ramp_fit_data(
ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, algorithm, weighting, max_cores, dqflags
)
Expand Down Expand Up @@ -242,6 +245,7 @@ def ramp_fit_data(
)
opt_info = None
else:
# Default to OLS.
# Get readnoise array for calculation of variance of noiseless ramps, and
# gain array in case optimal weighting is to be done
nframes = ramp_data.nframes
Expand Down
4 changes: 3 additions & 1 deletion src/stcal/ramp_fitting/ramp_fit_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ def __init__(self):
# One group ramp suppression for saturated ramps after 0th group.
self.suppress_one_group_ramps = False

# C code debugging switch.
self.dbg_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.

self.current_integ = -1

def set_arrays(self, data, err, groupdq, pixeldq, average_dark_current):
self.dbg_run_c_code = False
"""
Set the arrays needed for ramp fitting.
Expand Down

0 comments on commit 10f7f74

Please sign in to comment.