From 442044c6110ce220cb908e35bdb4e24149fc5711 Mon Sep 17 00:00:00 2001 From: toni-neurosc <10654467+toni-neurosc@users.noreply.github.com> Date: Fri, 26 Jan 2024 10:24:13 +0100 Subject: [PATCH] Sharpwaves performance fix --- py_neuromodulation/nm_sharpwaves.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/py_neuromodulation/nm_sharpwaves.py b/py_neuromodulation/nm_sharpwaves.py index 2122d14d..36c86df2 100644 --- a/py_neuromodulation/nm_sharpwaves.py +++ b/py_neuromodulation/nm_sharpwaves.py @@ -257,21 +257,22 @@ def analyze_waveform(self) -> None: distance=self.sw_settings["detect_troughs"]["distance_troughs_ms"], )[0] + peak_idx = 0 for trough_idx in troughs: - try: - ( - peak_idx_left, - peak_idx_right, - peak_left, - peak_right, - ) = self._get_peaks_around( - trough_idx, peaks, self.data_process_sw - ) - except NoValidTroughException: - # in this case there are no adjacent two peaks around this trough - # str(e) could print the exception error message - # print(str(e)) + + while peak_idx < peaks.size and peaks[peak_idx] < trough_idx: + peak_idx += 1 + + if peak_idx - 1 < 0: continue + peak_idx_left = peaks[peak_idx - 1] + + if peak_idx >= peaks.size: + continue + peak_idx_right = peaks[peak_idx] + + peak_left = self.data_process_sw[peak_idx_left] + peak_right = self.data_process_sw[peak_idx_right] trough = self.data_process_sw[trough_idx] self.trough.append(trough)