From 3eb491445cccbcf80090ce81fefd3ad8fbf70e45 Mon Sep 17 00:00:00 2001 From: toni-neurosc <10654467+toni-neurosc@users.noreply.github.com> Date: Sat, 20 Jan 2024 19:17:52 +0100 Subject: [PATCH 1/2] Branchless get_burst_amplitude_length --- py_neuromodulation/nm_bursts.py | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/py_neuromodulation/nm_bursts.py b/py_neuromodulation/nm_bursts.py index dbd43cb4..3c363dd8 100644 --- a/py_neuromodulation/nm_bursts.py +++ b/py_neuromodulation/nm_bursts.py @@ -167,25 +167,18 @@ def get_burst_amplitude_length( bursts = np.zeros((beta_averp_norm.shape[0] + 1), dtype=bool) bursts[1:] = beta_averp_norm >= burst_thr deriv = np.diff(bursts) - isburst = False burst_length = [] burst_amplitude = [] - burst_start = 0 - for index, burst_state in enumerate(deriv): - if burst_state == True: - if isburst == True: - burst_length.append(index - burst_start) - burst_amplitude.append(beta_averp_norm[burst_start:index]) + burst_states = np.where(deriv==True)[0] - isburst = False - else: - burst_start = index - isburst = True + for i in range(burst_states.size//2): + burst_length.append(burst_states[2 * i + 1] - burst_states[2 * i]) + burst_amplitude.append(beta_averp_norm[burst_states[2 * i] : burst_states[2 * i + 1]]) # the last burst length (in case isburst == True) is omitted, # since the true burst length cannot be estimated - burst_length = np.array(burst_length) / sfreq return burst_amplitude, burst_length + From 11cb64d101cf3dd8522bce6c2e5266be1e40e9fc Mon Sep 17 00:00:00 2001 From: timonmerk Date: Sun, 28 Jan 2024 11:57:32 +0100 Subject: [PATCH 2/2] change burst_state name --- py_neuromodulation/nm_bursts.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/py_neuromodulation/nm_bursts.py b/py_neuromodulation/nm_bursts.py index 3c363dd8..8f8c59e2 100644 --- a/py_neuromodulation/nm_bursts.py +++ b/py_neuromodulation/nm_bursts.py @@ -170,11 +170,11 @@ def get_burst_amplitude_length( burst_length = [] burst_amplitude = [] - burst_states = np.where(deriv==True)[0] + burst_time_points = np.where(deriv==True)[0] - for i in range(burst_states.size//2): - burst_length.append(burst_states[2 * i + 1] - burst_states[2 * i]) - burst_amplitude.append(beta_averp_norm[burst_states[2 * i] : burst_states[2 * i + 1]]) + for i in range(burst_time_points.size//2): + burst_length.append(burst_time_points[2 * i + 1] - burst_time_points[2 * i]) + burst_amplitude.append(beta_averp_norm[burst_time_points[2 * i] : burst_time_points[2 * i + 1]]) # the last burst length (in case isburst == True) is omitted, # since the true burst length cannot be estimated