Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _eda_findpeaks_neurokit(eda_phasic, amplitude_min=0.1):
peaks = signal_findpeaks(eda_phasic, relative_height_min=amplitude_min, relative_max=True)
info = {"SCR_Onsets": peaks["Onsets"], "SCR_Peaks": peaks["Peaks"], "SCR_Height": eda_phasic[peaks["Peaks"]]}
return info
def _ecg_delineator_derivative_S(rpeak, heartbeat, R):
segment = heartbeat[0:] # Select right hand side
S = signal_findpeaks(-segment["Signal"],
height_min=0.05 * (segment["Signal"].max() - segment["Signal"].min()))
if len(S["Peaks"]) == 0:
return np.nan, None
S = S["Peaks"][0] # Select most left-hand side
return rpeak + S, S
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_gamboa, **kwargs)
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_ssf, **kwargs)
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_engzee, **kwargs)
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_elgendi, **kwargs)
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_kalidas, **kwargs)
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_WT, **kwargs)
x = _ecg_findpeaks_promac_addmethod(signal, sampling_rate, x, _ecg_findpeaks_rodrigues, **kwargs)
# Rescale
x = x / np.max(x)
convoluted = x.copy()
# Remove below threshold
x[x < threshold] = 0
# Find peaks
peaks = signal_findpeaks(x, height_min=threshold)["Peaks"]
if show is True:
signal_plot([signal, convoluted], standardize=True)
[plt.axvline(x=peak, color="red", linestyle="--") for peak in peaks] # pylint: disable=W0106
return peaks
def _ecg_delineator_peak_P(rpeak, heartbeat, R, Q):
if Q is None:
return np.nan, None
segment = heartbeat.iloc[:Q] # Select left of Q wave
P = signal_findpeaks(segment["Signal"], height_min=0.05 * (segment["Signal"].max() - segment["Signal"].min()))
if len(P["Peaks"]) == 0:
return np.nan, None
P = P["Peaks"][np.argmax(P["Height"])] # Select heighest
from_R = R - P # Relative to R
return rpeak - from_R, P
def _ecg_delineator_peak_Q(rpeak, heartbeat, R):
segment = heartbeat[:0] # Select left hand side
Q = signal_findpeaks(-1 * segment["Signal"], height_min=0.05 * (segment["Signal"].max() - segment["Signal"].min()))
if len(Q["Peaks"]) == 0:
return np.nan, None
Q = Q["Peaks"][-1] # Select most right-hand side
from_R = R - Q # Relative to R
return rpeak - from_R, Q
Indices of the SRC peaks.
amplitudes : array
SCR pulse amplitudes.
References
----------
- van Halem, S., Van Roekel, E., Kroencke, L., Kuper, N., & Denissen, J. (2020).
Moments That Matter? On the Complexity of Using Triggers Based on Skin Conductance to Sample
Arousing Events Within an Experience Sampling Framework. European Journal of Personality.
"""
# smooth
eda_phasic = signal_filter(
eda_phasic, sampling_rate=sampling_rate, lowcut=None, highcut=None, method="savgol", window_size=501
)
info = signal_findpeaks(eda_phasic)
peaks = info["Peaks"]
threshold = 0.5 * sampling_rate
# Define each peak as a consistent increase of 0.5s
peaks = peaks[info["Width"] > threshold]
idx = np.where(peaks[:, None] == info["Peaks"][None, :])[1]
# Check if each peak is followed by consistent decrease of 0.5s
decrease = info["Offsets"][idx] - peaks
if any(np.isnan(decrease)):
decrease[np.isnan(decrease)] = False
if any(decrease < threshold):
keep = np.where(decrease > threshold)[0]
idx = idx[keep] # Update index
def _ecg_delineator_derivative_T(rpeak, heartbeat, R, S):
if S is None:
return np.nan, None
segment = heartbeat.iloc[R + S:] # Select right of S wave
T = signal_findpeaks(segment["Signal"],
height_min=0.05 * (segment["Signal"].max() - segment["Signal"].min()))
if len(T["Peaks"]) == 0:
return np.nan, None
T = S + T["Peaks"][0] # Select most left-hand side
return rpeak + T, T
def _ecg_delineator_peak_T(rpeak, heartbeat, R, S):
if S is None:
return np.nan, None
segment = heartbeat.iloc[R + S :] # Select right of S wave
T = signal_findpeaks(segment["Signal"], height_min=0.05 * (segment["Signal"].max() - segment["Signal"].min()))
if len(T["Peaks"]) == 0:
return np.nan, None
T = S + T["Peaks"][np.argmax(T["Height"])] # Select heighest
return rpeak + T, T