Skip to content

Commit

Permalink
More flexible input of find_n_competing function (#1532)
Browse files Browse the repository at this point in the history
* More flexible input of `find_n_competing` function

* Update version
  • Loading branch information
dachengx authored Jan 19, 2025
1 parent 6eedac3 commit ecfc016
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions straxen/plugins/peaks/peak_proximity.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PeakProximity(strax.OverlapWindowPlugin):
"""Look for peaks around a peak to determine how many peaks are in proximity (in time) of a
peak."""

__version__ = "0.4.0"
__version__ = "0.4.1"

depends_on = "peak_basics"
dtype = [
Expand Down Expand Up @@ -57,7 +57,9 @@ def get_window_size(self):

def compute(self, peaks):
windows = strax.touching_windows(peaks, peaks, window=self.nearby_window)
n_left, n_tot = self.find_n_competing(peaks, windows, fraction=self.min_area_fraction)
n_left, n_tot = self.find_n_competing(
peaks, peaks, windows, fraction=self.min_area_fraction
)

t_to_prev_peak = np.ones(len(peaks), dtype=np.int64) * self.peak_max_proximity_time
t_to_prev_peak[1:] = peaks["time"][1:] - peaks["endtime"][:-1]
Expand All @@ -77,15 +79,17 @@ def compute(self, peaks):

@staticmethod
@numba.jit(nopython=True, nogil=True, cache=True)
def find_n_competing(peaks, windows, fraction):
def find_n_competing(peaks_in_roi, peaks, windows, fraction):
n_left = np.zeros(len(peaks), dtype=np.int32)
n_tot = n_left.copy()
areas_in_roi = peaks_in_roi["area"]
areas = peaks["area"]

dig = np.searchsorted(peaks_in_roi["center_time"], peaks["center_time"])
for i, peak in enumerate(peaks):
left_i, right_i = windows[i]
threshold = areas[i] * fraction
n_left[i] = np.sum(areas[left_i:i] > threshold)
n_tot[i] = n_left[i] + np.sum(areas[i + 1 : right_i] > threshold)
n_left[i] = np.sum(areas_in_roi[left_i : dig[i]] > threshold)
n_tot[i] = n_left[i] + np.sum(areas_in_roi[dig[i] : right_i] > threshold)

return n_left, n_tot

0 comments on commit ecfc016

Please sign in to comment.