# -** coding: utf-8 -*-
from warnings import warn
import numpy as np
from ..epochs.eventrelated_utils import (_eventrelated_addinfo,
_eventrelated_sanitizeinput,
_eventrelated_sanitizeoutput)
from ..misc import NeuroKitWarning
# =============================================================================
# Internals
# =============================================================================
def _eda_eventrelated_eda(epoch, output={}):
# Sanitize input
if "EDA_Phasic" not in epoch:
warn(
"Input does not have an `EDA_Phasic` column."
" Will skip computation of maximum amplitude of phasic EDA component.",
category=NeuroKitWarning
)
return output
output["EDA_Peak_Amplitude"] = epoch["EDA_Phasic"].max()
return output
def _eda_eventrelated_scr(epoch, output={}):
# Sanitize input
if "SCR_Amplitude" not in epoch:
warn(
"Input does not have an `SCR_Amplitude` column."
" Will skip computation of SCR peak amplitude.",
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
)
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
)
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
# 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
else:
output["SCR_RecoveryTime"] = np.nan
return output