Source code for neurokit2.ecg.ecg_eventrelated
# -*- coding: utf-8 -*-
from warnings import warn
from ..epochs.eventrelated_utils import (
_eventrelated_addinfo,
_eventrelated_rate,
_eventrelated_sanitizeinput,
_eventrelated_sanitizeoutput,
)
from ..misc import NeuroKitWarning
# =============================================================================
# Internals
# =============================================================================
def _ecg_eventrelated_phase(epoch, output={}):
# Sanitize input
if "ECG_Phase_Atrial" not in epoch or "ECG_Phase_Ventricular" not in epoch:
warn(
"Input does not have an `ECG_Phase_Artrial` or `ECG_Phase_Ventricular` column."
" Will not indicate whether event onset concurs with cardiac phase.",
category=NeuroKitWarning,
)
return output
# Indication of atrial systole
output["ECG_Phase_Atrial"] = epoch["ECG_Phase_Atrial"][epoch.index > 0].iloc[0]
output["ECG_Phase_Completion_Atrial"] = epoch["ECG_Phase_Completion_Atrial"][
epoch.index > 0
].iloc[0]
# Indication of ventricular systole
output["ECG_Phase_Ventricular"] = epoch["ECG_Phase_Ventricular"][epoch.index > 0].iloc[0]
output["ECG_Phase_Completion_Ventricular"] = epoch["ECG_Phase_Completion_Ventricular"][
epoch.index > 0
].iloc[0]
return output
def _ecg_eventrelated_quality(epoch, output={}):
# Sanitize input
colnames = epoch.columns.values
if len([i for i in colnames if "ECG_Quality" in i]) == 0:
warn(
"Input does not have an `ECG_Quality` column."
" Quality of the signal is not computed.",
category=NeuroKitWarning,
)
return output
# Average signal quality over epochs
output["ECG_Quality_Mean"] = epoch["ECG_Quality"].mean()
return output