Source code for neurokit2.emg.emg_intervalrelated
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
# =============================================================================
# Internals
# =============================================================================
def _emg_intervalrelated_formatinput(interval, output={}):
"""Format input for dictionary."""
# Sanitize input
colnames = interval.columns.values
if len([i for i in colnames if "EMG_Onsets" in i]) == 0:
raise ValueError(
"NeuroKit error: emg_intervalrelated(): Wrong"
"input, we couldn't extract activity bursts."
"Please make sure your DataFrame"
"contains an `EMG_Onsets` column."
)
activity_cols = ["EMG_Amplitude", "EMG_Activity"]
if len([i in colnames for i in activity_cols]) != 2:
raise ValueError(
"NeuroKit error: emg_intervalrelated(): Wrong"
"input, we couldn't extract EMG amplitudes."
"Please make sure your DataFrame contains both"
"`EMG_Amplitude` and `EMG_Activity` columns."
)
bursts = interval["EMG_Onsets"].values
data_bursts = interval.loc[interval["EMG_Activity"] == 1]
output["EMG_Activation_N"] = np.sum(bursts)
output["EMG_Amplitude_Mean"] = data_bursts["EMG_Amplitude"].values.mean()
return output