Source code for neurokit2.ppg.ppg_intervalrelated
# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
from ..hrv import hrv
# =============================================================================
# Internals
# =============================================================================
def _ppg_intervalrelated_formatinput(data):
# Sanitize input
colnames = data.columns.values
if "PPG_Rate" not in colnames:
raise ValueError(
"NeuroKit error: ppg_intervalrelated(): Wrong input,"
"we couldn't extract heart rate. Please make sure"
"your DataFrame contains a `PPG_Rate` column."
)
signal = data["PPG_Rate"].values
PPG_Rate_Mean = np.mean(signal)
return {"PPG_Rate_Mean": PPG_Rate_Mean}
def _ppg_intervalrelated_hrv(data, sampling_rate):
# Sanitize input
colnames = data.columns.values
if "PPG_Peaks" not in colnames:
raise ValueError(
"NeuroKit error: ppg_intervalrelated(): Wrong input,"
"we couldn't extract peaks. Please make sure"
"your DataFrame contains a `PPG_Peaks` column."
)
# Transform rpeaks from "signal" format to "info" format.
peaks = np.where(data["PPG_Peaks"].values)[0]
peaks = {"PPG_Peaks": peaks}
results = hrv(peaks, sampling_rate=sampling_rate)
return results.astype("float").to_dict("records")