Skip to content

Commit

Permalink
Merge branch 'main' into jp-3677
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro authored Nov 25, 2024
2 parents 2f0ab96 + d0844b5 commit 1900157
Show file tree
Hide file tree
Showing 7 changed files with 474 additions and 50 deletions.
5 changes: 5 additions & 0 deletions changes/318.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
For `ramp_fitting`, the `CRMAG` element was not originally implemented in
the C-extension for ramp fitting. It is now implemented. A bug in the read
noise recalculation for CHARGELOSS when using the multiprocessing option has
been fixed. Further, in `JWST` regression tests have been added to test for
multiprocessing to ensure testing for anything that could affect multiprocessing.
1 change: 1 addition & 0 deletions changes/319.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update weight threshold calculation in outlier detection to work around numpy bug that introduces small numerical differences for a mean of a masked array.
23 changes: 9 additions & 14 deletions src/stcal/outlier_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,15 @@ def compute_weight_threshold(weight, maskpt):
float
The weight threshold for this integration.
'''
# necessary in order to assure that mask gets applied correctly
if hasattr(weight, '_mask'):
del weight._mask
mask_zero_weight = np.equal(weight, 0.)
mask_nans = np.isnan(weight)
# Combine the masks
weight_masked = np.ma.array(weight, mask=np.logical_or(
mask_zero_weight, mask_nans))
# Sigma-clip the unmasked data
weight_masked = sigma_clip(weight_masked, sigma=3, maxiters=5)
mean_weight = np.mean(weight_masked)
# Mask pixels where weight falls below maskpt percent
weight_threshold = mean_weight * maskpt
return weight_threshold
return np.mean(
sigma_clip(
weight[np.isfinite(weight) & (weight != 0)],
sigma=3,
maxiters=5,
masked=False,
copy=False,
),
dtype='f8') * maskpt


def _abs_deriv(array):
Expand Down
17 changes: 13 additions & 4 deletions src/stcal/ramp_fitting/ols_fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def ols_ramp_fit_multi(ramp_data, buffsize, save_opt, readnoise_2d, gain_2d, wei
gain_2d : ndarray
gain for all pixels
algorithm : str
'OLS' specifies that ordinary least squares should be used;
'GLS' specifies that generalized least squares should be used.
weighting : str
'optimal' specifies that optimal weighting should be used;
currently the only weighting supported.
Expand Down Expand Up @@ -214,6 +210,11 @@ def assemble_pool_results(ramp_data, save_opt, pool_results, rows_per_slice):
"""
# Create output arrays for each output tuple. The input ramp data and
# slices are needed for this.
for result in pool_results:
image_slice, integ_slice, opt_slice = result
if image_slice is None or integ_slice is None:
return None, None, None

image_info, integ_info, opt_info = create_output_info(ramp_data, pool_results, save_opt)

# Loop over the slices and assemble each slice into the main return arrays.
Expand Down Expand Up @@ -570,6 +571,14 @@ def slice_ramp_data(ramp_data, start_row, nrows):
ramp_data_slice.flags_saturated = ramp_data.flags_saturated
ramp_data_slice.flags_no_gain_val = ramp_data.flags_no_gain_val
ramp_data_slice.flags_unreliable_slope = ramp_data.flags_unreliable_slope
ramp_data_slice.flags_chargeloss = ramp_data.flags_chargeloss

# For possible CHARGELOSS flagging.
if ramp_data.orig_gdq is not None:
ogdq = ramp_data.orig_gdq[:, :, start_row : start_row + nrows, :].copy()
ramp_data_slice.orig_gdq = ogdq
else:
ramp_data_slice.orig_gdq = None

# Slice info
ramp_data_slice.start_row = start_row
Expand Down
Loading

0 comments on commit 1900157

Please sign in to comment.