Skip to content

Commit

Permalink
Raise error when peaks overlapping in merge_peaks (#927)
Browse files Browse the repository at this point in the history
* Simplify the required buffer length

* Add a check of peaks overlapping
  • Loading branch information
dachengx authored Nov 17, 2024
1 parent dd62b13 commit 739ad30
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion strax/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
RUN_DEFAULTS_KEY = "strax_defaults"
TEMP_DATA_TYPE_PREFIX = "_temp_"

# use tqdm as loaded in utils (from tqdm.notebook when in a juypyter env)
# use tqdm as loaded in utils (from tqdm.notebook when in a jupyter env)
tqdm = strax.utils.tqdm


Expand Down
33 changes: 7 additions & 26 deletions strax/processing/peak_merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def merge_peaks(
"""
assert len(start_merge_at) == len(end_merge_at)
if np.min(peaks["time"][1:] - strax.endtime(peaks)[:-1]) < 0:
raise ValueError("Peaks not disjoint! You have to rewrite this function to handle this.")
new_peaks = np.zeros(len(start_merge_at), dtype=peaks.dtype)

# Do the merging. Could numbafy this to optimize, probably...
Expand All @@ -45,32 +47,11 @@ def merge_peaks(

# re-zero relevant part of buffers (overkill? not sure if
# this saves much time)
buffer[
: min(
int(
(
last_peak["time"]
- first_peak["time"]
+ (last_peak["length"] * old_peaks["dt"].max())
)
/ common_dt
),
len(buffer),
)
] = 0
buffer_top[
: min(
int(
(
last_peak["time"]
- first_peak["time"]
+ (last_peak["length"] * old_peaks["dt"].max())
)
/ common_dt
),
len(buffer_top),
)
] = 0
bl = last_peak["time"] - first_peak["time"]
bl += last_peak["length"] * old_peaks["dt"].max()
bl = min(int(bl / common_dt), max_buffer)
buffer[:bl] = 0
buffer_top[:bl] = 0

for p in old_peaks:
# Upsample the sum and top/bottom array waveforms into their buffers
Expand Down
2 changes: 1 addition & 1 deletion strax/run_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import strax
from strax import stable_argsort

# use tqdm as loaded in utils (from tqdm.notebook when in a juypyter env)
# use tqdm as loaded in utils (from tqdm.notebook when in a jupyter env)
tqdm = strax.utils.tqdm

export, __all__ = strax.exporter()
Expand Down

0 comments on commit 739ad30

Please sign in to comment.