From d4048cb605fbb694126bec0205a62d604e180903 Mon Sep 17 00:00:00 2001 From: dachengx Date: Wed, 18 Dec 2024 12:50:18 -0600 Subject: [PATCH 1/2] Move `compute_center_times` from straxen to strax --- strax/processing/peak_properties.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/strax/processing/peak_properties.py b/strax/processing/peak_properties.py index 7bc814ba..ab43b8ee 100644 --- a/strax/processing/peak_properties.py +++ b/strax/processing/peak_properties.py @@ -70,6 +70,20 @@ def compute_index_of_fraction(peak, fractions_desired, result): result[-1] = peak["length"] +@export +@numba.njit(cache=True, nogil=True) +def compute_center_times(peaks): + result = np.zeros(len(peaks), dtype=np.int64) + for p_i, p in enumerate(peaks): + t = 0 + for t_i, weight in enumerate(p["data"]): + t += t_i * p["dt"] * weight + result[p_i] = ( + t / p["area"] + p["dt"] / 2 + p["time"] + ) # converting from float to int, implicit floor + return result + + @export def compute_widths(peaks, select_peaks_indices=None): """Compute widths in ns at desired area fractions for peaks. From 65e4bba6d8334792fd0f441b50983357c5046b67 Mon Sep 17 00:00:00 2001 From: dachengx Date: Wed, 18 Dec 2024 12:51:05 -0600 Subject: [PATCH 2/2] Minor rename --- strax/processing/peak_properties.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strax/processing/peak_properties.py b/strax/processing/peak_properties.py index ab43b8ee..2c7506e0 100644 --- a/strax/processing/peak_properties.py +++ b/strax/processing/peak_properties.py @@ -72,7 +72,7 @@ def compute_index_of_fraction(peak, fractions_desired, result): @export @numba.njit(cache=True, nogil=True) -def compute_center_times(peaks): +def compute_center_time(peaks): result = np.zeros(len(peaks), dtype=np.int64) for p_i, p in enumerate(peaks): t = 0