Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move compute_center_times from straxen to strax #938

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions strax/processing/peak_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_time(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.
Expand Down
Loading