Skip to content

Commit a6ace30

Browse files
authored
Clip center_time to be within the time and endtime (#973)
* Clip `center_time` to be within the `time` `endtime` * Fix a corner case where the area is 0
1 parent 165b533 commit a6ace30

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ psutil = "*"
4141
pymongo = "*"
4242
scipy = "*"
4343
tqdm = ">=4.46.0"
44-
zarr = "*"
44+
zarr = "<3.0.0"
4545
zstd = "*"
4646
sphinx = { version = "*", optional = true }
4747
sphinx_rtd_theme = { version = "*", optional = true }

strax/processing/peak_properties.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,14 @@ def compute_center_time(peaks):
108108
center_time = np.zeros(len(peaks), dtype=np.int64)
109109
for p_i, p in enumerate(peaks):
110110
data = p["data"][: p["length"]]
111-
if data.sum() <= 0:
112-
# Negative or zero-area peaks have centertime at startime
111+
if data.sum() == 0.0:
112+
# Zero-area peaks have centertime at startime
113113
center_time[p_i] = p["time"]
114-
else:
115-
t = np.average(np.arange(p["length"]), weights=data)
116-
center_time[p_i] = (t + 1 / 2) * p["dt"]
117-
center_time[p_i] += p["time"] # converting from float to int, implicit floor
114+
continue
115+
t = np.average(np.arange(p["length"]), weights=data)
116+
center_time[p_i] = (t + 1 / 2) * p["dt"]
117+
center_time[p_i] += p["time"] # converting from float to int, implicit floor
118+
center_time = np.clip(center_time, peaks["time"], strax.endtime(peaks))
118119
return center_time
119120

120121

tests/test_peak_properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get_filled_peaks(peak_length, data_length, n_widths):
2828

2929
# Fill the peaks with random length data
3030
for p in peaks:
31-
length = np.random.randint(0, data_length)
31+
length = np.random.randint(1, data_length)
3232
p["length"] = length
3333
wf = np.random.random(size=length)
3434
p["data"][:length] = wf

0 commit comments

Comments
 (0)