|
"""This file contains the ecg feature extraction pipelines and functions used for calculating the features.""" |
|
|
|
import neurokit2 as nk |
|
from .configs import selected_features |
|
|
|
|
|
def get_hrv_features(ecg_signal, fs): |
|
|
|
peaks, info = nk.ecg_peaks(ecg_signal, sampling_rate=fs, method="pantompkins1985") |
|
|
|
|
|
hrv_time_features = nk.hrv_time(peaks, sampling_rate=fs) |
|
|
|
|
|
|
|
|
|
|
|
|
|
hrv_features = hrv_time_features |
|
|
|
|
|
hrv_features = hrv_features[selected_features].to_dict(orient="records") |
|
|
|
return hrv_features |
|
|
|
|
|
def normalize_features(features_df, normalization_method): |
|
if normalization_method == "difference": |
|
baseline_features = features_df[features_df['baseline'] == True].iloc[0] |
|
features_df.loc[features_df['baseline'] == False, features_df.columns.isin(selected_features)] -= baseline_features |
|
elif normalization_method == "relative": |
|
baseline_features = features_df[features_df['baseline'] == True].iloc[0] |
|
features_df.loc[features_df['baseline'] == False, features_df.columns.isin(selected_features)] /= baseline_features |
|
elif (normalization_method == "separate") or (normalization_method is None): |
|
pass |
|
|
|
return features_df |
|
|