First Steps¶

Installation¶

To install use pip:

pip install hrv

Or clone the repo:

git clone https://github.com/rhenanbartels/hrv.git
python setup.py install

Basic Usage¶

Create an RRi instance

Once you create an RRi object you will have the power of a native Python iterable object. This means, that you can loop through it using a for loop, get a just a part of the series using native slicing and much more. Let us try it:

from hrv.rri import RRi

rri_list = [800, 810, 815, 750, 753, 905]
rri = RRi(rri_list)

print(rri)
RRi array([800., 810., 815., 750., 753., 905.])

Slicing

print(rri)
800.0

print(type(rri))
numpy.float64

print(rri[::2])
RRi array([800., 815., 753.])

Logical Indexing

from hrv.rri import RRi

rri = RRi([800, 810, 815, 750, 753, 905])
rri_ge = rri[rri >= 800]

rri_ge
RRi array([800., 810., 815., 905.])

Loop

for rri_value in rri:
print(rri_value)

800.0
810.0
815.0
750.0
753.0
905.0

Note: When time information is not provided, time array will be created using the cumulative sum of successive RRi. After cumulative sum, the time array is subtracted from the value at t to make it start from 0s

RRi object and time information

from hrv.rri import RRi

rri_list = [800, 810, 815, 750, 753, 905]
rri = RRi(rri_list)

print(rri.time)
array([0.   , 0.81 , 1.625, 2.375, 3.128, 4.033]) # Cumsum of rri values minus t

rri = RRi(rri_list, time=[0, 1, 2, 3, 4, 5])
print(rri.time)
[0. 1. 2. 3. 4. 5.]

Note: Some validations are made in the time list/array provided to the RRi class, for instance:

• RRi and time list/array must have the same length;
• Time list/array can not have negative values;
• Time list/array must be monotonic increasing.

Basic math operations

With RRi objects you can make math operatins just like a numpy array:

rri
RRi array([800., 810., 815., 750., 753., 905.])

rri * 10
RRi array([8000., 8100., 8150., 7500., 7530., 9050.])

rri + 200
RRi array([1000., 1010., 1015.,  950.,  953., 1105.])

Works with Numpy functions

import numpy as np

rri = RRi([800, 810, 815, 750, 753, 905])

sum_rri = np.sum(rri)
print(sum_rri)
4833.0

mean_rri = np.mean(rri)
print(mean_rri)
805.5

std_rri = np.std(rri)
print(std_rri)
51.44171459039833