API Reference¶
Data Pre-Processing¶
ECG¶
- class heartview.pipeline.ECG.BeatDetectors(fs, preprocessed=True)[source]¶
A class for detecting beats in electrocardiogram (ECG) signals using popular algorithms.
Parameters/Attributes¶
- fsint
The sampling rate of the ECG signal.
- preprocessedbool, optional
Whether the ECG signal is preprocessed or not; by default, True.
Notes
Both unfiltered and filtered ECG data may be passed as inputs to the beat detection functions. If unfiltered data is passed, the preprocessed parameter should be set to False, and the beat detection functions will pre-process the signal using the algorithm’s original pre-processing procedures.
- engzee(signal)[source]¶
- Extracts QRS complex locations from an ECG signal with the Engelse
and Zeelenberg (1979) algorithm, modified by Lourenço et al. (2011).
- Parameters:
signal (array-like) – An array containing the ECG signal.
- Returns:
ecg_beats – An array containing the indices of detected R peaks.
- Return type:
array-like
References
Engelse, W. A. H., & Zeelenberg, C. (1979). A single scan algorithm for QRS detection and feature extraction. IEEE Computers in Cardiology, 6, 37-42.
Lourenço, A., Fred, A., & Ribeiro, B. (2012). Real time electrocardiogram segmentation for finger based ECG biometrics. In Proceedings of the 2012 Eighth International Conference on Intelligent Information Hiding and Multimedia Signal Processing (IIH-MSP) (pp. 21-24). IEEE.
- manikandan(signal, adaptive_threshold=True, window=0.44)[source]¶
Extracts R peak locations from an ECG signal with the Manikandan and Soman (2012) algorithm.
- Parameters:
signal (array-like) – An array containing the ECG signal.
adaptive_threshold (boolean, optional) – Whether to refine beat detection using adaptive thresholding; by default, True.
window (float, optional) – The size (in seconds) of the sliding search window for the adaptive threshold; by default, 0.44 seconds (440 milliseconds).
- Returns:
ecg_beats – An array containing the indices of detected R peaks.
- Return type:
array-like
References
Manikandan, R., & Soman, K. P. (2012). A novel method for detecting R-peaks in electrocardiogram (ECG) signal. Biomedical Signal Processing and Control, 7(2), 118-128.
- nabian(signal)[source]¶
Extracts R peak locations from an ECG signal with the Nabian et al. (2018) algorithm.
- Parameters:
signal (array-like) – An array containing the ECG signal.
- Returns:
ecg_beats – An array containing the indices of detected R peaks.
- Return type:
array-like
References
Nabian, M., et al. (2018). An open-source feature extraction tool for the analysis of peripheral physiological data. IEEE Journal of Translational Engineering in Health and Medicine, 6, 1-11.
- pantompkins(signal)[source]¶
Extracts QRS complex locations from an ECG signal with the Pan & Tompkins (1985) algorithm.
- Parameters:
signal (array-like) – An array containing the ECG signal.
- Returns:
ecg_beats – An array containing the indices of detected beats.
- Return type:
array-like
References
Pan, S. J., & Tompkins, W. J. (1985). A real-time QRS detection algorithm. IEEE Transactions on Biomedical Engineering, 32(3), 230-236.
- class heartview.pipeline.ECG.Filters(fs, powerline_freq=60)[source]¶
A class for filtering raw electrocardiogram (ECG) signals.
Parameters/Attributes¶
- fsint
The sampling rate of the ECG signal.
- powerline_freqint
The powerline interference frequency. This value must be either 50 or 60 (by default, 60). The 50 Hz power grid is prevalent in many European, Asian, and African countries.
- baseline_wander(signal, cutoff=0.05, order=2)[source]¶
Apply a high-pass filter to remove baseline wander from ECG data.
- Parameters:
signal (array_like) – An array containing the noisy signal data.
cutoff (float) – The cut-off frequency at which frequencies below this value in the signal are attenuated; by default, 0.05 Hz.
order (int) – The filter order, i.e., the number of samples required to produce the desired filtered output; by default, 2.
- Returns:
filtered – An array containing the filtered signal data.
- Return type:
array_like
- filter_signal(signal, lowcut=1, highcut=15, rs=0.15, rp=80, order=2)[source]¶
Filter out artifact from ECG data due to powerline interference, baseline wander, movement, and muscle noise using an elliptic bandpass filter.
- Parameters:
signal (array-like) – An array containing the ECG data to be filtered.
- Returns:
filtered – An array containing the filtered ECG signal.
- Return type:
array-like
- muscle_noise(signal, lowcut=30, highcut=100, order=2)[source]¶
Apply a bandstop filter to remove muscle (EMG) noise from ECG data.
- Parameters:
signal (array-like) – An array containing the noisy signal data.
lowcut (float, optional) – The lower cutoff frequency of the bandstop filter; by default, 30.
highcut (float, optional) – The upper cutoff frequency of the bandstop filter; by default, 100
order (int, optional) – The filter order, i.e., the number of samples required to produce the desired filtered output; by default, 2.
- Returns:
filtered – The filtered signal with muscle/EMG noise removed.
- Return type:
array-like
- powerline_interference(signal, q=30)[source]¶
Filter out powerline interference at a specified frequency.
- Parameters:
signal (array_like) – An array containing the noisy signal data.
q (float) – The quality factor, i.e., how narrow or wide the stopband is for a notch filter (by default, 30). A higher quality factor indicates a narrower bandpass.
- Returns:
filtered – An array containing the filtered signal data.
- Return type:
array_like
PPG¶
- class heartview.pipeline.PPG.BeatDetectors(fs, preprocessed=True)[source]¶
A class for detecting beats in photoplethysmography (PPG) signals using popular algorithms.
Parameters/Attributes¶
- fsint
The sampling rate of the PPG signal.
- preprocessedbool, optional
Whether the input PPG data is pre-processed or not; by default, True. If False, the beat detection methods will pre-process the input data according to the original algorithms.
Notes
Both unfiltered and filtered PPG data may be passed as inputs to the beat detection functions. If unfiltered data is passed, the preprocessed parameter should be set to False, and the beat detection functions will pre-process the signal using the algorithm’s original pre-processing procedures.
- adaptive_threshold(signal, ma_perc=20)[source]¶
Extract beat locations from PPG data with the adaptive thresholding algorithm by van Gent al. (2018).
- Parameters:
signal (array_like) – An array containing the PPG signal.
ma_perc (float, optional) – The percentage with which to raise the moving average, used for fitting detection solutions to the data; by default, 20.
- Returns:
ppg_beats – An array containing indices of PPG pulse onsets.
- Return type:
array_like
Notes
The original source code can be found in the HeartPy package at: https://github.com/paulvangentcom/heartrate_analysis_python.
References
Van Gent, P., Farah, H., Van Nes, N., & Van Arem, B. (2019). HeartPy: A novel heart rate algorithm for the analysis of noisy signals. Transportation Research Part F: Traffic Psychology and Behaviour, 66, 368-378.
- erma(signal, W1=0.111, W2=0.667, offset=0.02, refractory=0.3)[source]¶
Extract beat locations from PPG data based on the Elgendi et al. (2013) algorithm using event-related moving averages and dynamic thresholding.
- Parameters:
signal (array_like) – An array containing the PPG signal.
W1 (float, optional) – The window size for peak detection in seconds; by default 111 ms.
W2 (float, optional) – The window size for beat detection in seconds; by default, 667 ms.
offset (float, optional) – Offset duration adjustment; by default, 20 ms.
refractory (float, optional) – Refractory period to avoid double detection of the same beat (i.e., the minimum delay between consecutive systolic peaks); by default, 300 ms.
- Returns:
ppg_beats – An array containing indices of PPG pulse onsets.
- Return type:
array_like
References
Elgendi, M., Norton, I., Brearley, M., Abbott, D., & Schuurmans, D. (2013). Systolic peak detection in acceleration photoplethysmograms measured from emergency responders in tropical conditions. PLoS ONE, 8(10), e76585.
- class heartview.pipeline.PPG.Filters(fs)[source]¶
A class for filtering raw photoplethysmography (PPG) data.
Parameters/Attributes¶
- fsint
The sampling rate of the PPG signal.
- baseline_wander(signal, cutoff=0.5, order=2)[source]¶
Apply a high-pass filter to remove baseline wander from PPG data.
- Parameters:
signal (array_like) – An array containing the input PPG signal to be filtered.
cutoff (float) – The cut-off frequency at which frequencies below this value in the PPG signal are attenuated; by default, 0.5 Hz.
order (int) – The filter order, i.e., the number of samples required to produce the desired filtered output; by default, 2.
- filter_signal(signal, lowcut=0.5, highcut=10, order=4, window_len=0.5)[source]¶
Filter out baseline drift, motion artifact, and powerline interference from PPG data and smooth out the signal for further processing. This function uses a 4th-order Chebyshev Type II filter according to results of the study by Liang et al. (2018) and a moving average filter using convolution.
- Parameters:
signal (array_like) – An array containing the input PPG signal to be filtered.
lowcut (int, float) – The cut-off frequency at which frequencies below this value in the signal are attenuated; by default, 0.5 Hz.
highcut (int, float) – The cut-off frequency at which frequencies above this value in the signal are attenuated; by default, 10 Hz.
order (int) – The filter order, i.e., the number of samples required to produce the desired filtered output; by default, 4.
window_len (int) – The size of the moving average window, in seconds.
- Returns:
filtered – An array containing the filtered PPG data.
- Return type:
array_like
References
Liang, Y., Elgendi, M., Chen, Z., et al. (2018). An optimal filter for short photoplethysmogram signals. Scientific Data, 5, 180076.
- moving_average(signal, window_len)[source]¶
Smooth a PPG signal using a moving average filter.
- Parameters:
signal (array_like) – An array containing the input PPG signal to be filtered.
window_len (int) – The size of the moving average window, in seconds.
- Returns:
filtered – An array containing the filtered PPG signal.
- Return type:
array_like
ACC¶
- heartview.pipeline.ACC.compute_auc(df, signal, fs, seg_size=60, ts_col=None, norm=None, rolling_window=None, rolling_step=15)[source]¶
Compute the area-under-the-curve of acceleration magnitude across a given window size using Riemann sums.
- Parameters:
df (pandas.DataFrame) – The DataFrame containing acceleration magnitude values.
signal (str) – The name of the column containing the acceleration magnitude.
fs (int, float) – The sampling rate.
seg_size (int) – The segment size (in seconds) by which the areas are computed; by default, 60.
ts_col (str, optional) – The name of the column containing timestamps.
norm (str, optional) – The method with which to normalize the magnitude values; by default, None. Possible options include: ‘minmax’ or ‘zscore’.
rolling_window (int, optional) – The size, in seconds, of the sliding window across which to compute the AUC values; by default, None.
rolling_step (int, optional) – The step size, in seconds, of the sliding windows; by default, 15.
- Returns:
auc – A DataFrame containing the AUC, its normalized value of the acceleration magnitude, and corresponding timestamp for each window.
- Return type:
pandas.DataFrame
Notes
If a value is given in the rolling_window parameter, the rolling window approach will override the segmented approach, ignoring any seg_size value.
- heartview.pipeline.ACC.compute_magnitude(x, y, z)[source]¶
Compute the magnitude of a 3-axis accelerometer signal.
- Parameters:
x (array_like) – An array containing the x-axis accelerometer data.
y (array_like) – An array containing the y-axis accelerometer data.
z (array_like) – An array containing the z-axis accelerometer data.
- Returns:
magnitude – A series of acceleration magnitude values.
- Return type:
pandas.Series
- heartview.pipeline.ACC.convert_acc(signal, sensitivity, fs)[source]¶
Convert an acceleration signal from G-force to units of m/s^2.
- Parameters:
signal (array_like) – An array containing the acceleration signal.
sensitivity (int) – The G-force sensitivity level of the accelerometer (e.g., 2 for ± 2g).
fs (int) – The sampling rate of the accelerometer recording.
- Returns:
ms2 – An array containing the converted acceleration signal.
- Return type:
array_like
Signal Quality Assessment¶
- class heartview.pipeline.SQA.Cardio(fs)[source]¶
A class for signal quality assessment on cardiovascular data, including electrocardiograph (ECG) or photoplethysmograph (PPG) data.
Parameters/Attributes¶
- fsint
The sampling rate of the cardiovascular data.
- compute_metrics(data, beats_ix, artifacts_ix, ts_col=None, seg_size=60, min_hr=40, rolling_window=None, rolling_step=15, show_progress=True)[source]¶
Compute all SQA metrics for cardiovascular data by segment or moving window. Metrics per segment or moving window include numbers of detected, expected, missing, and artifactual beats and percentages of missing and artifactual beats.
- Parameters:
data (pandas.DataFrame) – A DataFrame containing pre-processed ECG or PPG data.
beats_ix (array_like) – An array containing the indices of detected beats.
artifacts_ix (array_like) – An array containing the indices of artifactual beats.
seg_size (int) – The segment size in seconds; by default, 60.
min_hr (int, float) – The minimum acceptable heart rate against which the number of beats in the last partial segment will be compared; by default, 40.
ts_col (str, optional) – The name of the column containing timestamps; by default, None. If a string value is given, the output will contain a timestamps column.
rolling_window (int, optional) – The size, in seconds, of the sliding window across which to compute the SQA metrics; by default, None.
rolling_step (int, optional) – The step size, in seconds, of the sliding windows; by default, 15.
show_progress (bool, optional) – Whether to display a progress bar while the function runs; by default, True.
- Returns:
metrics – A DataFrame with all computed SQA metrics per segment.
- Return type:
pandas.DataFrame
Notes
If a value is given in the rolling_window parameter, the rolling window approach will override the segmented approach, ignoring any seg_size value.
Examples
>>> from heartview.pipeline import SQA >>> sqa = SQA.Cardio(fs = 1000) >>> artifacts_ix = sqa.identify_artifacts(beats_ix, method = 'both') >>> cardio_qa = sqa.compute_metrics(ecg, beats_ix, artifacts_ix, ... ts_col = 'Timestamp', ... seg_size = 60, min_hr = 40)
- display_summary_table(sqa_df)[source]¶
Display the SQA summary table.
- Parameters:
sqa_df (pandas.DataFrame) – The DataFrame containing the SQA metrics per segment.
- Returns:
table – Summary table for SQA metrics.
- Return type:
dash_bootstrap_components.Table
- get_artifacts(data, beats_ix, artifacts_ix, seg_size=60, ts_col=None)[source]¶
Summarize the number and proportion of artifactual beats per segment.
- Parameters:
data (pandas.DataFrame) – A DataFrame containing the pre-processed ECG or PPG data.
beats_ix (array_like) – An array containing the indices of detected beats.
artifacts_ix (array_like) – An array containing the indices of artifactual beats. This is outputted from SQA.Cardio.identify_artifacts().
seg_size (int) – The size of the segment in seconds; by default, 60.
ts_col (str, optional) – The name of the column containing timestamps; by default, None. If a string value is given, the output will contain a timestamps column.
- Returns:
artifacts – A DataFrame with the number and proportion of artifactual beats per segment.
- Return type:
pandas.DataFrame
See also
SQA.Cardio.identify_artifactsIdentify artifactual beats using both or either of the methods.
- get_missing(data, beats_ix, seg_size=60, min_hr=40, ts_col=None, show_progress=True)[source]¶
Summarize the number and proportion of missing beats per segment.
- Parameters:
data (pandas.DataFrame) – The DataFrame containing the pre-processed ECG or PPG data.
beats_ix (array-like) – An array containing the indices of detected beats.
seg_size (int) – The size of the segment in seconds; by default, 60.
min_hr (int, float) – The minimum acceptable heart rate against which the number of beats in the last partial segment will be compared; by default, 40.
ts_col (str, optional) – The name of the column containing timestamps; by default, None. If a string value is given, the output will contain a timestamps column.
show_progress (bool, optional) – Whether to display a progress by while the function runs; by default, True.
- Returns:
missing – A DataFrame with detected, expected, and missing numbers of beats per segment.
- Return type:
pandas.DataFrame
- get_seconds(data, beats_ix, ts_col=None, show_progress=True)[source]¶
Get second-by-second HR, IBI, and beat counts from ECG or PPG data according to the approach by Graham (1978).
- Parameters:
data (pd.DataFrame) – The DataFrame containing the pre-processed ECG or PPG data.
beats_ix (array-like) – An array containing the indices of detected beats.
ts_col (str, optional) – The name of the column containing timestamps; by default, None. If a string value is given, the output will contain a timestamps column.
show_progress (bool, optional) – Whether to display a progress bar while the function runs; by default, True.
- Returns:
interval_data – A DataFrame containing second-by-second HR and IBI values.
- Return type:
pd.DataFrame
Notes
Rows with NaN values in the resulting DataFrame interval_data denote seconds during which no beats in the data were detected.
References
Graham, F. K. (1978). Constraints on measuring heart rate and period sequentially through real and cardiac time. Psychophysiology, 15(5), 492–495.
- identify_artifacts(beats_ix, method, initial_hr=None, prev_n=None, neighbors=None, tol=None)[source]¶
Identify locations of artifactual beats in cardiovascular data based on the criterion beat difference approach by Berntson et al. (1990), the Hegarty-Craver et al. (2018) approach, or both.
- Parameters:
beats_ix (array_like) – An array containing the indices of detected beats.
method (str) – The artifact identification method for identifying artifacts. This must be ‘hegarty’, ‘cbd’, or ‘both’.
initial_hr (int, float, or 'auto', optional) – The heart rate value for the first interbeat interval (IBI) to be validated against; by default, ‘auto’ for automatic calculation using the mean heart rate value obtained from six consecutive IBIs with the smallest average successive difference. Required for the ‘hegarty’ method.
prev_n (int, optional) – The number of preceding IBIs to validate against; by default, 6. Required for ‘hegarty’ method.
neighbors (int, optional) – The number of surrounding IBIs with which to derive the criterion beat difference score; by default, 5. Required for ‘cbd’ method.
tol (float, optional) – A configurable hyperparameter used to fine-tune the stringency of the criterion beat difference test; by default, 1. Required for ‘cbd’ method.
- Returns:
artifacts_ix – An array containing the indices of identified artifact beats.
- Return type:
array_like
Notes
The source code for the criterion beat difference test is from work by Hoemann et al. (2020).
References
Berntson, G., Quigley, K., Jang, J., Boysen, S. (1990). An approach to artifact identification: Application to heart period data. Psychophysiology, 27(5), 586–598.
Hegarty-Craver, M. et al. (2018). Automated respiratory sinus arrhythmia measurement: Demonstration using executive function assessment. Behavioral Research Methods, 50, 1816–1823.
Hoemann, K. et al. (2020). Context-aware experience sampling reveals the scale of variation in affective experience. Scientific Reports, 10(1), 1–16.
- plot_artifact(df, invalid_thresh=30, title=None)[source]¶
Plot detected and artifact beat counts.
- Parameters:
df (pandas.DataFrame()) – The DataFrame containing SQA metrics per segment.
invalid_thresh (int, float) – The minimum number of beats detected for a segment to be considered valid; by default, 30.
title (str, optional)
- plot_missing(df, invalid_thresh=30, title=None)[source]¶
Plot detected and missing beat counts.
- Parameters:
df (pandas.DataFrame()) – The DataFrame containing SQA metrics per segment.
invalid_thresh (int, float) – The minimum number of beats detected for a segment to be considered valid; by default, 30.
title (str, optional)
- class heartview.pipeline.SQA.EDA(fs, eda_min=0.2, eda_max=40, eda_max_slope=5, temp_min=20, temp_max=40, invalid_spread_dur=2)[source]¶
A class for signal quality assessment on electrodermal activity (EDA) data.
Parameters/Attributes¶
- fsint
The sampling rate of the EDA data.
- eda_minfloat, optional
The minimum acceptable value for EDA data in microsiemens; by default, 0.05 uS.
- eda_maxfloat, optional
The maximum acceptable value for EDA data in microsiemens; by default, 60 uS.
- eda_max_slopefloat, optional
The maximum slope of EDA data in microsiemens per second; by default, 5 uS/sec.
- temp_minfloat, optional
The minimum acceptable temperature in degrees Celsius; by default, 20.
- temp_maxfloat, optional
The maximum acceptable temperature in degrees Celsius; by default, 40.
- invalid_spread_durfloat, optional
The transition radius for artifacts in seconds; by default, 2.
- assess_eda_quality(signal, temp=None, preprocessed=True, seg_size=60, rolling_window=None, rolling_step=15)[source]¶
Identifies valid and invalid data points in electrodermal activity using the automated quality assessment procedure by Kleckner et al. (2017) by segment or across sliding windows.
- Parameters:
signal (array_like) – An array containing the EDA signal in microsiemens.
temp (array_like) – An array containing temperature data in Celsius; by default, None.
preprocessed (boolean, optional) – Whether filtered EDA data is being inputted; by default, True.
seg_size (int) – The segment size in seconds; by default, 60.
rolling_window (int, optional) – The size, in seconds, of the sliding window across which to compute the EDA SQA metrics; by default, None.
rolling_step (int, optional) – The step size, in seconds, of the sliding windows; by default, 15.
- Returns:
edaqa – A dictionary containing key-value pairs of segment or rolling window numbers and their corresponding dictionaries of valid and invalid EDA indices and lengths. Keys of nested dictionaries are ‘valid’, ‘invalid’, and ‘length’.
- Return type:
dict
References
Kleckner, I. R., Jones, R. M., Wilder-Smith, O., Wormwood, J. B., Akcakaya, M., Quigley, K. S., … & Goodwin, M. S. (2017). Simple, transparent, and flexible automated quality assessment procedures for ambulatory electrodermal activity data. IEEE Transactions on Biomedical Engineering, 65(7), 1460-1467.
- compute_metrics(signal, temp, timestamps=None, preprocessed=True, seg_size=60, rolling_window=None, rolling_step=None)[source]¶
Summarize the number and proportion of valid and invalid data points in an electrodermal activity (EDA) signal per segment or across sliding windows.
- Parameters:
signal (array_like) – An array containing the EDA signal in microsiemens.
temp (array_like, optional) – An array containing temperature data in Celsius; by default, None.
timestamps (array_like, optional) – An array containing timestamps corresponding to the EDA data points; by default, None.
preprocessed (boolean, optional) – Whether filtered EDA data is being inputted; by default, True.
seg_size (int) – The segment size in seconds; by default, 60.
rolling_window (int, optional) – The size, in seconds, of the sliding window across which to compute the EDA SQA metrics; by default, None.
rolling_step (int, optional) – The step size, in seconds, of the sliding windows; by default, 15.
- Returns:
metrics – A DataFrame containing quality assessment metrics per segment.
- Return type:
pandas.DataFrame
Notes
If a value is given in the rolling_window parameter, the rolling window approach will override the segmented approach, ignoring any seg_size value.
See also
SQA.EDA.assess_eda_qualityIdentify locations of invalid and valid EDA data points.
- plot_edaqa(metrics, title=None)[source]¶
Plot percentages of valid and invalid EDA data.
- Parameters:
metrics (pandas.DataFrame()) – The DataFrame outputted from SQA.EDA.compute_metrics() that contains EDA QA metrics per segment or sliding window.
title (str, optional)
- Returns:
fig – A figure containing a bar chart of percentages of invalid and valid EDA data points by segment or sliding window.
- Return type:
plotly.graph_objects.Figure
See also
SQA.EDA.compute_metricsSummarize EDA QA metrics by segment or sliding window.
Devices¶
Actiwave Cardio¶
- class heartview.heartview.Actiwave(file)[source]¶
A class for convenient pre-processing of data from the Actiwave Cardio device.
Parameters/Attributes¶
- filestr
The path of the Actiwave Cardio device file saved in European Data Format (.edf).
- get_acc_fs()[source]¶
Get the sampling rate of accelerometer data from an Actiwave Cardio device.
- Returns:
fs – The sampling rate of the accelerometer recording.
- Return type:
int, float
- get_ecg_fs()[source]¶
Get the sampling rate of ECG data from an Actiwave Cardio device.
- Returns:
fs – The sampling rate of the ECG recording.
- Return type:
int, float
- preprocess(time_aligned=False)[source]¶
Pre-process electrocardiograph (ECG) and acceleration data from an Actiwave Cardio file.
- Parameters:
time_aligned (bool, optional) – Whether to time-align ECG and acceleration data based on the sampling rate of the ECG data; by default, False.
- Returns:
If time_aligned is False, returns a tuple (ecg, acc), where ecg is a DataFrame containing the pre-processed ECG data and acc is a DataFrame containing the pre-processed X-, Y-, and Z-axis acceleration data. If time_aligned is True, returns a single DataFrame containing time-synced ECG and acceleration data according to the ECG data’s timestamps.
- Return type:
tuple or pandas.DataFrame
Empatica E4¶
- class heartview.heartview.Empatica(file)[source]¶
A class to conveniently pre-process and assess quality of PPG and EDA data from Empatica E4 devices.
- file¶
The path of the Empatica archive file with a ‘.zip’ extension.
- Type:
str
- get_acc()[source]¶
Get the pre-processed acceleration data and its start time and sampling rate from the Empatica E4.
- Returns:
acc_data – An Empatica.Data object with the following attributes and corresponding accelerometer data variables:
- accpandas.DataFrame
A DataFrame containing the pre-processed BVP data with corresponding timestamps.
- startfloat
The Unix-formatted start time of the BVP recording.
- fsint
The sampling rate of the BVP data.
- Return type:
Empatica.Data object
- get_bvp()[source]¶
Get the raw blood volume pulse (BVP) data and its start time and sampling rate from the Empatica E4.
- Returns:
bvp_data – An Empatica.Data object with the following attributes and corresponding BVP data variables:
- bvppandas.DataFrame
A DataFrame containing the pre-processed BVP data with corresponding timestamps.
- startfloat
The Unix-formatted start time of the BVP recording.
- fsint
The sampling rate of the BVP data.
- Return type:
Empatica.Data object
- get_e4_beats(bvp_data, ibi_data, start_time, show_progress=True)[source]¶
Get locations of beats from Empatica E4 interbeat interval (IBI) data relative to its blood volume pulse (BVP) data.
- Parameters:
bvp_data (pandas.DataFrame) – A DataFrame containing the Empatica E4 BVP data, outputted from Empatica.preprocess().
ibi_data (pandas.DataFrame) – A DataFrame containing the Empatica E4 IBI data, outputted from Empatica.preprocess().
start_time (int) – The Unix timestamp of the recording start time.
show_progress (bool, optional) – Whether to display a progress bar while the function runs; by default, True.
- Returns:
e4_beats – A list containing the indices of beats extracted from IBI data of the Empatica E4.
- Return type:
list
- get_eda()[source]¶
Get the raw electrodermal activity (EDA) data and its recording start time and sampling rate from the Empatica E4.
- Returns:
eda_data – An Empatica.Data object with the following attributes and corresponding EDA data variables:
- edapandas.DataFrame
A DataFrame containing the pre-processed EDA data with corresponding timestamps.
- startfloat
The Unix-formatted start time of the EDA recording.
- fsint
The sampling rate of the EDA data.
- Return type:
Empatica.Data object
- get_hr()[source]¶
Get the pre-processed heart rate (HR) data, start time of the first HR measurement, and sampling rate from the Empatica E4.
- Returns:
hr_data – An Empatica.Data object with the following attributes and corresponding HR data variables:
- hrpandas.DataFrame
A DataFrame containing the pre-processed HR data with corresponding timestamps.
- startfloat
The Unix-formatted start time of the HR measurements.
- fsint
The sampling rate of the BVP data.
- Return type:
Empatica.Data object
- get_ibi()[source]¶
Get the pre-processed interbeat interval (IBI) data and the start time of the first interval from the Empatica E4.
- Returns:
ibi_data – An Empatica.Data object with the following attributes and corresponding IBI data variables:
- ibipandas.DataFrame
A DataFrame containing the pre-processed IBI data with corresponding timestamps.
- startint
The Unix-formatted start time of the IBI data.
- Return type:
Empatica.Data object
- get_temp()[source]¶
Get the raw skin temperature data and its recording start time and sampling rate from the Empatica E4.
- Returns:
temp_data – An Empatica.Data object with the following attributes and corresponding temperature data variables:
- temppandas.DataFrame
A DataFrame containing the pre-processed temperature data with corresponding timestamps.
- startfloat
The Unix-formatted start time of the temperature recording.
- fsint
The sampling rate of the temperature data.
- Return type:
Empatica.Data object
- plot_signals(segment=1, seg_size=60, interactive=True)[source]¶
Display a plot of a segment of signals recorded with the Empatica E4 device.
- Parameters:
segment (int, optional) – The number of the position of the segment to plot; by default, 1.
seg_size (int, optional) – The segment size in seconds; by default, 60.
interactive (bool, optional) – Whether to plot an interactive visualization; by default, True.
- Returns:
fig – If interactive is True, displays and returns an interactive Plotly figure containing the plotted signals. If interactive is False, displays a static figure and returns None.
- Return type:
plotly.graph_objects.Figure or None
- preprocess(time_aligned=False)[source]¶
Pre-process all data from the Empatica E4.
- Parameters:
time_aligned (bool, optional) – Whether to time-align all data based on the signal with the highest sampling rate (i.e. blood volume pulse); by default, False.
- Returns:
data – An Empatica.Data object with the following attributes and corresponding pre-processed data:
- If time_aligned is False:
- accpandas.DataFrame
A DataFrame containing the pre-processed ACC data with corresponding timestamps.
- bvppandas.DataFrame
A DataFrame containing the pre-processed BVP data with corresponding timestamps.
- edapandas.DataFrame
A DataFrame containing the pre-processed EDA data with corresponding timestamps.
- hrpandas.DataFrame
A DataFrame containing the pre-processed HR data with corresponding timestamps.
- ibipandas.DataFrame
A DataFrame containing the pre-processed IBI data with corresponding timestamps and seconds elapsed since the start time of the IBI recording.
- temppandas.DataFrame
A DataFrame containing the pre-processed temperature data with corresponding timestamps.
- start_timefloat
The Unix-formatted start time of the E4 recording.
- bvp_fsfloat
The sampling rate of the BVP recording.
- eda_fsfloat
The sampling rate of the EDA recording.
- If time_aligned is True:
- hrvpandas.DataFrame
A DataFrame containing time-synced BVP, HR, IBI, and acceleration data.
- edapandas.DataFrame
A DataFrame containing time-synced EDA, temperature, and acceleration data.
- start_timefloat
The Unix-formatted start time of the E4 recording.
- bvp_fsfloat
The sampling rate of the BVP recording.
- eda_fsfloat
The sampling rate of the EDA recording.
- Return type:
Empatica.Data object
Examples
>>> from heartview import heartview >>> e4_archive = 'Sample_E4_Data.zip' >>> E4 = heartview.Empatica(e4_archive) >>> ALL_E4_DATA = E4.preprocess()
Beat Editor¶
- heartview.heartview.write_beat_editor_file(data, fs, signal_col, beats_col, ts_col=None, filename=None)[source]¶
Create a JSON file for input to the Beat Editor.
- Parameters:
data (pd.DataFrame) –
A DataFrame containing the cardiac data. Must contain at least the following columns:
Cardiac signal
Beat occurrences labeled as 1
- Optionally, data can include:
A timestamp column (specified by ts_col). If not provided, sample indices are used.
An “Artifact” column, where artifact occurrences are labeled as 1. This allows the Beat Editor to visualize artifactual beat locations.
fs (int) – The sampling frequency of the signal.
signal_col (str) – The name of the column in data containing the cardiac signal.
beats_col (str) – The name of the column in data containing beat occurrences.
ts_col (str, optional) – The name of the column in data containing the timestamps. If not provided, timestamps are assumed to correspond to the DataFrame index.
filename (str, optional) – The name of the JSON file to write. If no filename is provided, the default filename ‘heartview_edit.json’ is used.
- Return type:
None
- heartview.heartview.process_beat_edits(orig_data, edits)[source]¶
Apply manual corrections from the Beat Editor output to original data. Edits are aligned either by sample index or timestamp, depending on the structure of orig_data.
- Parameters:
orig_data (pd.DataFrame) – A DataFrame containing the original cardiac data inputted to the Beat Editor. Must contain a ‘Beat’ column and either: - ‘Timestamp’ column (datetime), or - ‘Sample’ column (integer sample indices)
edits (pd.DataFrame) –
A DataFrame of edit instructions parsed from a Beat Editor _edited.json file. Must contain the following columns: - ‘x’: the location of each edit, in the same unit as either
orig_data[‘Timestamp’] (datetime) or orig_data[‘Sample’] (integer)
’editType’: type of edit, with values ‘ADD’ or ‘DELETE’
- Returns:
processed – A copy of orig_data with the following additional columns: - ‘Deletion’: 1 where beats were deleted, otherwise NaN - ‘Addition’: 1 where beats were added, otherwise NaN - ‘Unusable’: 1 where segments are marked unusable, otherwise NaN - ‘Edited’: 1 where all final beats are, otherwise NaN
- Return type:
pd.DataFrame