Compute average heart beat interval (HBI) in a sliding window.
Parameters:
card (list or 1D numpy.ndarray) – Timeseries of recorded cardiac signal
peaks (list or 1D numpy.ndarray) – array of peak indexes for card.
samplerate (float) – Sampling rate for card, in Hertz.
window (float, optional) – Size of the sliding window, in seconds.
Default is 6.
central_measure ("mean","average", "avg", "median", "mdn", string, optional) – Measure of the center used (mean or median).
Default is “mean”.
Returns:
card_met – Heart Beats Interval or Heart Rate Variability timeseries.
The first column is the raw metric, in seconds.
The second column is the metric convolved with the CRF, cut to the length
of the raw metric.
Return type:
2D numpy.ndarray
Notes
Heart beats interval (HBI) definition is taken from [1]_, and consists of the
average of the time interval between two heart beats within a 6-seconds window.
This metric should be convolved with an inverse of the cardiac response function
before being included in a GLM.
IMPORTANT : The unit of measure has meaning, since it is based on seconds.
Hence, zscoring might remove important quantifiable information.
Compute average heart rate (HR) in a sliding window.
We call this function HEART RATE, however note that if using a PPG
recorded signal, it is more accurate to talk about PULSE RATE.
See [2]_ for the differences and similarities between the two measures.
Parameters:
card (list or 1D numpy.ndarray) – Timeseries of recorded cardiac signal
peaks (list or 1D numpy.ndarray) – array of peak indexes for card.
samplerate (float) – Sampling rate for card, in Hertz.
window (float, optional) – Size of the sliding window, in seconds.
Default is 6.
central_measure ("mean","average", "avg", "median", "mdn", string, optional) – Measure of the center used (mean or median).
Default is “mean”.
Returns:
card_met – Heart Beats Interval or Heart Rate Variability timeseries.
The first column is the raw metric, in Hertz.
The second column is the metric convolved with the CRF, cut to the length
of the raw metric.
Return type:
2D numpy.ndarray
Notes
Heart rate (HR) is taken from [1]_, and computed as the amounts of
beats per minute.
However, operationally, it is the average of the inverse of the time interval
between two heart beats.
This metric should be convolved with the cardiac response function
before being included in a GLM.
IMPORTANT : The unit of measure has a meaning, since they it’s based on Hertz.
Hence, zscoring might remove important quantifiable information.
See _cardiac_metrics for full implementation.
References
Annual International Conference of the IEEE Engineering in Medicine and
Biology Society (EMBC), doi: 10.1109/EMBC.2016.7591347.
Compute average heart rate variability (HRV) in a sliding window.
We call this function HEART RATE variability, however note that if using a PPG
recorded signal, it is more accurate to talk about PULSE RATE variability.
See [1]_ for the differences and similarities between the two measures.
Parameters:
card (list or 1D numpy.ndarray) – Timeseries of recorded cardiac signal
peaks (list or 1D numpy.ndarray) – array of peak indexes for card.
samplerate (float) – Sampling rate for card, in Hertz.
window (float, optional) – Size of the sliding window, in seconds.
Default is 6.
central_measure ("mean","average", "avg", "median", "mdn", string, optional) – Measure of the center used (mean or median).
Default is “mean”.
Returns:
card_met – Heart Beats Interval or Heart Rate Variability timeseries.
The first column is the raw metric, in Hertz.
The second column is the metric convolved with the CRF, cut to the length
of the raw metric.
Return type:
2D numpy.ndarray
Notes
Heart rate variability (HRV) is taken from [1]_, and computed as the amounts of
beats per minute.
However, operationally, it is the average of the inverse of the time interval
between two heart beats.
This metric should be convolved with the cardiac response function
before being included in a GLM.
IMPORTANT : The unit of measure has a meaning, since they it’s based on Hertz.
Hence, zscoring might remove important quantifiable information.
See _cardiac_metrics for full implementation.
References
Annual International Conference of the IEEE Engineering in Medicine and
Biology Society (EMBC), doi: 10.1109/EMBC.2016.7591347.
resp ((X,) numpy.ndarray) – A 1D array with the respiratory belt time series.
samplerate (float) – Sampling rate for resp, in Hertz.
window (int, optional) – Size of the sliding window, in seconds.
Default is 6.
Returns:
rv_out – Respiratory variance values.
The first column is raw RV values, after normalization.
The second column is RV values convolved with the RRF, after normalization.
Respiratory variance (RV) was introduced in [1]_, and consists of the
standard deviation of the respiratory trace within a 6-second window.
This metric is often lagged back and/or forward in time and convolved with
a respiratory response function before being included in a GLM.
Regressors also often have mean and linear trends removed and are
standardized prior to regressions.
physio (array_like) – 1D array, whether cardiac or respiratory signal.
If cardiac, the array is a set of peaks in seconds.
If respiratory, the array is the actual respiratory signal.
sample_rate (float) – Physio sample rate, in Hertz.
t_r (float) – Imaging sample rate, in seconds.
n_scans (int) – Number of volumes in the imaging run.
slice_timings (array_like) – Slice times, in seconds.
n_harmonics (int) –
???
card (bool, optional) – Whether the physio data correspond to cardiac or repiratory signal.
resp (bool, optional) – Whether the physio data correspond to cardiac or repiratory signal.
Returns:
retroicor_regressors (list)
phase (array_like) – 2D array of shape (n_scans, n_slices)
Notes
RETROICOR regressors should be regressed from the imaging data before
any other preprocessing, including slice-timing correction and motion correction.
Calculate the cardiac response function using Chang, Cunningham and Glover’s definition.
Parameters:
samplerate (float) – Sampling rate of data, in seconds.
time_length (int, optional) – RRF kernel length, in seconds. Default is 32.
onset (float, optional) – Onset of the response, in seconds. Default is 0.
inverse (bool, optional) – If True, return the additive inverse of the CRF, i.e. the iCRF.
Returns:
crf – Cardiac or “heart” response function
Return type:
array-like
Notes
This cardiac response function was defined in [1]_, Appendix A.
The core code for this function comes from metco2, while several of the
parameters, including time_length, and onset, are modeled on
nistats’ HRF functions.
Calculate the respiratory response function using Chang and Glover’s definition.
Parameters:
samplerate (float) – Sampling rate of data, in seconds..
time_length (int, optional) – RRF kernel length, in seconds. Default is 50.
onset (float, optional) – Onset of the response, in seconds. Default is 0.
Returns:
rrf – respiratory response function
Return type:
array-like
Notes
This respiratory response function was defined in [1]_, Appendix A.
The core code for this function comes from metco2, while several of the
parameters, including time_length, and onset, are modeled on
nistats’ HRF functions.
Apply function f in a sliding window view of an array.
Windows are always considered as centered.
This function can consider incomplete windows, i.e. those windows
at the beginning and at the end of an array, so that the length
of the output is the same as the length of the input. For the same reason,
it will skip the very last window.
This is somewhat equivalent to pandas’ rolling function set with center=True,
except for the incomplete windows.
Parameters:
array (list or numpy.ndarray) – Array to apply function in sliding windows to
func (function) – The bare function to be applied, e.g. np.mean
halfwindow (int) – Half of the window size to be applied
incomplete (bool, optional) – If True, return those windows that are smaller, i.e. at the beginning and
at the end of array. If False, returns only complete windows.
array (list or numpy.ndarray) – Array to be convolved
func (list or numpy.ndarray) – The function to convolve array with
zscore (bool, optional.) – If True, array will be transformed to Zscores before the convolution.
If False, raw array data will be taken to be convolved with the function.
rescale ("demean_rescale", "rescale", "zscore", "demean", or None, optional) – The rescaling operation used on array_combined`
pad (bool, optional) – If True, return a padded non-convolved metric together with the convolved one.
If False, return both metrics at the lenght of input array.
Returns:
array_combined (numpy.ndarray) – One combined array (array and array convolved with func) rescaled or not
array_combined_padd (numpy.ndarray) – One combined array (array and array convolved with func), padded to the
convolved data length, rescaled or not.