Skip to content

Commit 25ab19d

Browse files
Fixed an out of bounds error coming from IntegratePeaksShoeboxTOF alg… (#39124)
* Fixed an out of bounds error coming from IntegratePeaksShoeboxTOF algorithm * added a concise fix * updated as per PR comments * update system test for IntegratePeaksTOFShoebox
1 parent 02999cd commit 25ab19d

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

Framework/PythonInterface/plugins/algorithms/IntegratePeaksShoeboxTOF.py

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class WeakPeak:
5656
tof_fwhm: float
5757
tof_bin_width: float
5858
ipks_near: np.ndarray
59+
kernel_shape: tuple
5960

6061

6162
class ShoeboxResult:
@@ -400,7 +401,9 @@ def PyExec(self):
400401
# look for possible strong peaks at any TOF in the window (won't know if strong until all pks integrated)
401402
ipks_near, _ = find_ipks_in_window(ws, peaks, ispecs, ipk)
402403
fwhm = fwhm if get_nbins_from_b2bexp_params else None # not calculated but not going to be used
403-
weak_peaks_list.append(WeakPeak(ipk, ispecs[ipos[0], ipos[1]], x[ipos[-1]], fwhm, bin_width, ipks_near))
404+
weak_peaks_list.append(
405+
WeakPeak(ipk, ispecs[ipos[0], ipos[1]], x[ipos[-1]], fwhm, bin_width, ipks_near, (nrows, ncols, nbins))
406+
)
404407
else:
405408
if status == PEAK_STATUS.STRONG:
406409
ipks_strong.append(ipk)
@@ -443,12 +446,43 @@ def PyExec(self):
443446
peak, peak.getDetectorID(), bank_name, nshoebox * kernel.shape[0], nshoebox * kernel.shape[1], nrows_edge, ncols_edge
444447
)
445448
x, y, esq, ispecs = get_and_clip_data_arrays(ws, peak_data, pk_tof, kernel, nshoebox)
449+
446450
# integrate at previously found ipos
451+
if weak_pk.ispec not in ispecs:
452+
nrows = max(kernel.shape[0], weak_pk.kernel_shape[0])
453+
ncols = max(kernel.shape[0], weak_pk.kernel_shape[0])
454+
peak_data = array_converter.get_peak_data(
455+
peak,
456+
peak.getDetectorID(),
457+
bank_name,
458+
nshoebox * nrows,
459+
nshoebox * ncols,
460+
nrows_edge,
461+
ncols_edge,
462+
)
463+
x, y, esq, ispecs = get_and_clip_data_arrays(ws, peak_data, pk_tof, kernel, nshoebox)
447464
ipos = [*np.argwhere(ispecs == weak_pk.ispec)[0], np.argmin(abs(x - weak_pk.tof))]
448465
peaks_det_ids[ipk] = peak_data.detids
449466

450467
det_edges = peak_data.det_edges if not integrate_on_edge else None
451-
intens, sigma, i_over_sig, status = integrate_shoebox_at_pos(y, esq, kernel, ipos, weak_peak_threshold, det_edges)
468+
intens, sigma, i_over_sig, status, ipos, nrows, ncols, nbins = integrate_peak(
469+
ws,
470+
peaks,
471+
ipk,
472+
kernel,
473+
nrows,
474+
ncols,
475+
nbins,
476+
x,
477+
y,
478+
esq,
479+
ispecs,
480+
ipos,
481+
det_edges,
482+
weak_peak_threshold,
483+
False,
484+
)
485+
452486
# scale summed intensity by bin width to get integrated area
453487
intens = intens * weak_pk.tof_bin_width
454488
sigma = sigma * weak_pk.tof_bin_width

Testing/SystemTests/tests/framework/SXDAnalysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def runTest(self):
168168
self.integrated_peaks = sxd.get_peaks(runno, PEAK_TYPE.FOUND, INTEGRATION_TYPE.SHOEBOX)
169169

170170
def validate(self):
171-
intens_over_sigma = [0.0, 9.638, 10.265, 136.535, 0.0]
171+
intens_over_sigma = [0.0, 12.749, 11.941, 136.535, 0.0]
172172
self.assertTrue(np.allclose(self.integrated_peaks.column("Intens/SigInt"), intens_over_sigma, atol=1e-2))
173173

174174

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed an out of bounds error coming from :ref:`algm-IntegratePeaksShoeboxTOF` when integrating peaks.

0 commit comments

Comments
 (0)