API¶
Physiological data¶
-
class
peakdet.
Physio
(data, fs=None, history=None, metadata=None)[source]¶ Class to hold physiological data and relevant information
Parameters: - data (array_like) – Input data array
- fs (float, optional) – Sampling rate of data (Hz). Default: None
- history (list of tuples, optional) – Functions performed on data. Default: None
- metadata (dict, optional) – Metadata associated with data. Default: None
-
data
¶ Physiological waveform
Type: numpy.ndarray
-
fs
¶ Sampling rate of data in Hz
Type: float
-
history
¶ History of functions that have been performed on data, with relevant parameters provided to functions.
Type: list of tuples
-
peaks
¶ Indices of peaks in data
Type: numpy.ndarray
-
troughs
¶ Indices of troughs in data
Type: numpy.ndarray
Loading data¶
-
peakdet.
load_physio
(data, *, fs=None, dtype=None, history=None, allow_pickle=False)[source]¶ Returns Physio object with provided data
Parameters: - data (str or array_like or Physio_like) – Input physiological data. If array_like, should be one-dimensional
- fs (float, optional) – Sampling rate of data. Default: None
- dtype (data_type, optional) – Data type to convert data to, if conversion needed. Default: None
- history (list of tuples, optional) – Functions that have been performed on data. Default: None
- allow_pickle (bool, optional) – Whether to allow loading if data contains pickled objects. Default: False
Returns: data – Loaded physiological data
Return type: Raises: TypeError
– If provided data is unable to be loaded
-
peakdet.
load_history
(file, verbose=False)[source]¶ Loads history from file and replays it, creating new Physio instance
Parameters: - file (str) – Path to input JSON file
- verbose (bool, optional) – Whether to print messages as history is being replayed. Default: False
Returns: file – Full filepath to saved output
Return type: str
-
peakdet.
load_rtpeaks
(fname, channel, fs)[source]¶ Loads data file as obtained from the
rtpeaks
Python moduleData file fname should have a single, comma-delimited header of format:
time,channel#,channel#,…,channel#Raw data should be stored in columnar format, also comma-delimited, beneath this header. All data should be stored as integers. For more information, see the
rtpeaks
homepage: https://github.com/rmarkello/rtpeaks.Parameters: - fname (str) – Path to data file to be loaded
- channel (int) – Integer corresponding to the channel number in fname from which data should be loaded
- fs (float) – Sampling rate at which fname was acquired
Returns: data – Loaded physiological data
Return type:
Processing data¶
Functions for processing and interpreting physiological data
-
peakdet.operations.
interpolate_physio
(data, target_fs, *, kind='cubic')[source]¶ Interpolates data to desired sampling rate target_fs
Parameters: - data (Physio_like) – Input physiological data to be interpolated
- target_fs (float) – Desired sampling rate for data
- kind (str or int, optional) – Type of interpolation to perform. Must be one of available kinds in
scipy.interpolate.interp1d()
. Default: ‘cubic’
Returns: interp – Interpolated input data
Return type:
-
peakdet.operations.
filter_physio
(data, cutoffs, method, *, order=3)[source]¶ Applies an order-order digital method Butterworth filter to data
Parameters: - data (Physio_like) – Input physiological data to be filtered
- cutoffs (int or list) – If method is ‘lowpass’ or ‘highpass’, an integer specifying the lower or upper bound of the filter (in Hz). If method is ‘bandpass’ or ‘bandstop’, a list specifying the lower and upper bound of the filter (in Hz).
- method ({'lowpass', 'highpass', 'bandpass', 'bandstop'}) – The type of filter to apply to data
- order (int, optional) – Order of filter to be applied. Default: 3
Returns: filtered – Filtered input data
Return type:
-
peakdet.operations.
peakfind_physio
(data, *, thresh=0.2, dist=None)[source]¶ Performs peak and trough detection on data
Parameters: - data (Physio_like) – Input data in which to find peaks
- thresh (float [0,1], optional) – Relative height threshold a data point must surpass to be classified as a peak. Default: 0.2
- dist (int, optional) – Distance in indices that peaks must be separated by in data. If None, this is estimated. Default: None
Returns: peaks – Input data with detected peaks and troughs
Return type:
-
peakdet.operations.
plot_physio
(data, *, ax=None)[source]¶ Plots data and associated peaks / troughs
Parameters: - data (Physio_like) – Physiological data to plot
- ax (
matplotlib.axes.Axes
, optional) – Axis on which to plot data. If None, a new axis is created. Default: None
Returns: ax – Axis with plotted data
Return type:
-
peakdet.operations.
edit_physio
(data)[source]¶ Opens interactive plot with data to permit manual editing of time series
Parameters: data (Physio_like) – Physiological data to be edited Returns: edited – Input data with manual edits Return type: peakdet.Physio
Saving data¶
-
peakdet.
save_physio
(fname, data)[source]¶ Saves data to fname
Parameters: - fname (str) – Path to output file; .phys will be appended if necessary
- data (Physio_like) – Data to be saved to file
Returns: fname – Full filepath to saved output
Return type: str
-
peakdet.
save_history
(file, data)[source]¶ Saves history of physiological data to file
Saved file can be replayed with peakdet.load_history
Parameters: - file (str) – Path to output file; .json will be appended if necessary
- data (Physio_like) – Data with history to be saved to file
Returns: file – Full filepath to saved output
Return type: str
Derived metrics¶
-
class
peakdet.
HRV
(data)[source]¶ Class for calculating various HRV statistics
Parameters: data (Physio_like) – Physiological data object with detected peaks and troughs -
rrint
¶ R-R intervals derived from data (sometimes referred to as N-N intervals in derived metrics)
Type: numpy.ndarray
-
rrtime
¶ Time stamps of rrint
Type: numpy.ndarray
-
avgnn
¶ Average heart rate (N-N interval)
Type: float
-
sdnn
¶ Standard deviation of heart rate (N-N intervals)
Type: float
-
rmssd
¶ Root mean square of successive differences
Type: float
-
sdsd
¶ Standard deviation of successive differences
Type: float
-
nn50
¶ Number of N-N intervals greater than 50ms
Type: float
-
pnn50
¶ Percent of N-N intervals greater than 50ms
Type: float
-
nn20
¶ Number of N-N intervals greater than 20ms
Type: float
-
pnn20
¶ Percent of N-N intervals greater than 20ms
Type: float
-
hf
¶ High-frequency power of R-R intervals, summed across 0.15-0.40 Hz
Type: float
-
hf_log
¶ Log of hf
Type: float
-
lf
¶ Low-frequency power of R-R intervals, summed across 0.04-0.15 Hz
Type: float
-
lf_log
¶ Log of lf
Type: float
-
vlf
¶ Very low frequency power of R-R intervals, summed across 0-0.04 Hz
Type: float
-
vlf_log
¶ Log of vlf
Type: float
-
lftohf
¶ Ratio of lf over hf
Type: float
-
hf_peak
¶ Peak frequency in hf band (0.15-0.40 Hz)
Type: float
-
lf_peak
¶ Peak frequency in lf band (0.04-0.15 Hz)
Type: float
Notes
Uses scipy.signal.welch for calculation of frequency-based statistics
-