Skip to content

Commit

Permalink
Fix EDA recovery time computation (now, in seconds)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominiqueMakowski committed May 23, 2024
1 parent ca9af09 commit 9caba86
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions neurokit2/eda/eda_eventrelated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

import numpy as np

from ..epochs.eventrelated_utils import (_eventrelated_addinfo,
_eventrelated_sanitizeinput,
_eventrelated_sanitizeoutput)
from ..epochs.eventrelated_utils import (
_eventrelated_addinfo,
_eventrelated_sanitizeinput,
_eventrelated_sanitizeoutput,
)
from ..misc import NeuroKitWarning


Expand Down Expand Up @@ -134,7 +136,7 @@ def _eda_eventrelated_eda(epoch, output={}):
warn(
"Input does not have an `EDA_Phasic` column."
" Will skip computation of maximum amplitude of phasic EDA component.",
category=NeuroKitWarning
category=NeuroKitWarning,
)
return output

Expand All @@ -149,39 +151,39 @@ def _eda_eventrelated_scr(epoch, output={}):
warn(
"Input does not have an `SCR_Amplitude` column."
" Will skip computation of SCR peak amplitude.",
category=NeuroKitWarning
category=NeuroKitWarning,
)
return output

if "SCR_RecoveryTime" not in epoch:
warn(
"Input does not have an `SCR_RecoveryTime` column."
" Will skip computation of SCR half-recovery times.",
category=NeuroKitWarning
category=NeuroKitWarning,
)
return output

if "SCR_RiseTime" not in epoch:
warn(
"Input does not have an `SCR_RiseTime` column."
" Will skip computation of SCR rise times.",
category=NeuroKitWarning
category=NeuroKitWarning,
)
return output

# Peak amplitude and Time of peak
first_activation = np.where(epoch["SCR_Amplitude"][epoch.index > 0] != 0)[0][0]
peak_amplitude = epoch["SCR_Amplitude"][epoch.index > 0].iloc[first_activation]
output["SCR_Peak_Amplitude"] = peak_amplitude
output["SCR_Peak_Amplitude_Time"] = epoch["SCR_Amplitude"][epoch.index > 0].index[first_activation]
# Rise Time
rise_time = epoch["SCR_RiseTime"][epoch.index > 0].iloc[first_activation]
output["SCR_RiseTime"] = rise_time
epoch_postevent = epoch[epoch.index > 0]
# Peak amplitude
first_peak = np.where(epoch_postevent["SCR_Amplitude"] != 0)[0][0]
output["SCR_Peak_Amplitude"] = epoch_postevent["SCR_Amplitude"].iloc[first_peak]
# Time of peak (Raw, from epoch onset)
output["SCR_Peak_Amplitude_Time"] = epoch_postevent.index[first_peak]
# Rise Time (From the onset of the peak)
output["SCR_RiseTime"] = epoch_postevent["SCR_RiseTime"].iloc[first_peak]

# Recovery Time
# Recovery Time (from peak to half recovery time)
if any(epoch["SCR_RecoveryTime"][epoch.index > 0] != 0):
recovery_time = np.where(epoch["SCR_RecoveryTime"][epoch.index > 0] != 0)[0][0]
output["SCR_RecoveryTime"] = recovery_time
recov_t = np.where(epoch_postevent["SCR_RecoveryTime"] != 0)[0][0]
output["SCR_RecoveryTime"] = epoch_postevent["SCR_RecoveryTime"].iloc[recov_t]
else:
output["SCR_RecoveryTime"] = np.nan

Expand Down

0 comments on commit 9caba86

Please sign in to comment.