# -** 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
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 (from peak to half recovery time)
if any(epoch["SCR_RecoveryTime"][epoch.index > 0] != 0):
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
return output