CFT Example

This example illustrates how to process data collected when conducting the Cold Face Test (CFT) procedure, i.e., how to compute parameters quantifying the reaction to the CFT and how to create specialized CFT plots.

Setup and Helper Functions

[1]:
from pathlib import Path

import re

import pandas as pd
import numpy as np

from fau_colors import cmaps

import biopsykit as bp
from biopsykit.protocols import CFT

import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline
%load_ext autoreload
%autoreload 2
[2]:
plt.close("all")

palette = sns.color_palette(cmaps.faculties)
sns.set_theme(context="notebook", style="ticks", font="sans-serif", palette=palette)

plt.rcParams["figure.figsize"] = (8, 4)
plt.rcParams["pdf.fonttype"] = 42
plt.rcParams["mathtext.default"] = "regular"

palette
[2]:

Create CFT Object

The CFT is a protocol and thus part of the Protocol API of BioPsyKit.

[3]:
cft = CFT()
cft
[3]:
CFT
        Structure: {'Baseline': 60, 'CFT': 120, 'Recovery': 60}

Load Data

[4]:
hr_dict = bp.example_data.get_mist_hr_example()

# Alternatively: Use your own data
# hr_dict = bp.io.ecg.load_hr_phase_dict("<path-to-heart-rate-data-dictionary>")
df_hr = hr_dict["MIST3"]

df_hr.head()
[4]:
Heart_Rate
time
2019-10-22 11:53:08.977000+02:00 101.721854
2019-10-22 11:53:10.164000+02:00 100.392157
2019-10-22 11:53:10.762000+02:00 99.740260
2019-10-22 11:53:11.363000+02:00 101.052632
2019-10-22 11:53:11.957000+02:00 102.400000

Plot Course of Heart Rate

[5]:
fig, ax = plt.subplots()
bp.signals.ecg.plotting.hr_plot(df_hr, ax=ax)
fig.tight_layout()
../../_images/examples__notebooks_CFT_Example_11_0.svg

Note: See plotting.hr_plot() for further information!

Compute CFT Parameter

Extract CFT Interval, i.e., the interval of the data where the Cold Face stimulus was actually applied (corresponds to the duration of the “CFT” phase specified in the CFT object) and compute baseline heart rate (the mean heart rate during the “Baseline” phase specified in the CFT object).

Note: See CFT.extract_cft_interval() and CFT.compute_cft_parameter() for further information!

[6]:
df_cft = cft.extract_cft_interval(df_hr)
bl = cft.baseline_hr(df_hr)

print("Baseline Heart Rate: {:.2f}".format(bl))
df_cft.head()
Baseline Heart Rate: 86.57
[6]:
Heart_Rate
time
2019-10-22 11:54:09.547000+02:00 93.090909
2019-10-22 11:54:10.191000+02:00 91.428571
2019-10-22 11:54:10.848000+02:00 94.814815
2019-10-22 11:54:11.480000+02:00 97.215190
2019-10-22 11:54:12.098000+02:00 97.834395
[7]:
cft.compute_cft_parameter(df_hr)
[7]:
baseline_hr cft_start_idx onset onset_latency onset_idx onset_hr onset_hr_percent onset_slope peak_brady peak_brady_latency peak_brady_idx peak_brady_bpm peak_brady_percent peak_brady_slope mean_hr_bpm mean_brady_bpm mean_brady_percent poly_fit_a0 poly_fit_a1 poly_fit_a2
0 86.57039 86 2019-10-22 11:54:16.852000+02:00 7.305 11 80.0 7.589651 -0.899437 2019-10-22 11:54:36.980000+02:00 27.433 38 -14.457714 -16.70053 -0.527019 82.25004 -4.32035 -4.990563 86.823415 -0.230385 0.001917

Plot CFT Data

[8]:
fig, ax = plt.subplots()

cft.cft_plot(data=df_hr, ax=ax)
fig.tight_layout()
../../_images/examples__notebooks_CFT_Example_18_0.svg

Note: See CFT.cft_plot() for further information!

[ ]:

Download Notebook
(Right-Click -> Save Link As...)