Skip to content

Commit c31064b

Browse files
author
Nicolas Marc Simon Legrand
committed
Test functions
1 parent e5dd45d commit c31064b

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

systole/tests/test_hrv.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import matplotlib
55
import unittest
66
from unittest import TestCase
7-
from systole.hrv import nnX, pnnX, rmssd, time_domain, hrv_psd,\
7+
from systole.hrv import nnX, pnnX, rmssd, time_domain,\
88
frequency_domain, nonlinear
99
from systole import import_rr
1010

@@ -34,13 +34,6 @@ def test_time_domain(self):
3434
assert isinstance(stats, pd.DataFrame)
3535
assert stats.size == 24
3636

37-
def test_hrv_psd(self):
38-
"""Test hrv_psd function"""
39-
ax = hrv_psd(rr)
40-
assert isinstance(ax, matplotlib.axes.Axes)
41-
freq, psd = hrv_psd(rr, show=False)
42-
assert len(freq) == len(psd)
43-
4437
def test_frequency_domain(self):
4538
"""Test frequency_domain function"""
4639
stats = frequency_domain(rr)

systole/tests/test_plotting.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import matplotlib
77
from unittest import TestCase
88

9-
from systole import import_rr
109
from systole.plotting import plot_hr, plot_events, plot_oximeter,\
11-
plot_subspaces, circular, plot_circular, plot_subspaces
10+
plot_subspaces, circular, plot_circular, plot_psd
1211
from systole import import_ppg, import_rr
1312
from systole.recording import Oximeter
1413
from systole.detection import hrv_subspaces
@@ -38,6 +37,10 @@ class TestPlotting(TestCase):
3837
def test_plot_hr(self):
3938
ax = plot_hr(oxi)
4039
assert isinstance(ax, matplotlib.axes.Axes)
40+
ax = plot_hr(oxi.peaks)
41+
assert isinstance(ax, matplotlib.axes.Axes)
42+
ax = plot_hr(np.asarray(oxi.peaks))
43+
assert isinstance(ax, matplotlib.axes.Axes)
4144

4245
def test_plot_events(self):
4346
ax = plot_events(oxi)
@@ -47,13 +50,21 @@ def test_plot_oximeter(self):
4750
ax = plot_oximeter(oxi)
4851
assert isinstance(ax, matplotlib.axes.Axes)
4952

50-
def plot_subspaces(self):
53+
def test_plot_subspaces(self):
5154
rr = import_rr()
5255
s1, s2, s3 = hrv_subspaces(rr)
5356
ax = plot_subspaces(s1, s2, s3)
5457
assert isinstance(ax[0], matplotlib.axes.Axes)
5558
assert isinstance(ax[1], matplotlib.axes.Axes)
5659

60+
def test_plot_psd(self):
61+
"""Test plot_psd function"""
62+
rr = import_rr().rr.values
63+
ax = plot_psd(rr)
64+
assert isinstance(ax, matplotlib.axes.Axes)
65+
freq, psd = plot_psd(rr, show=False)
66+
assert len(freq) == len(psd)
67+
5768
def test_circular(self):
5869
"""Tests _circular function"""
5970
ax = circular(x)

systole/tests/test_recording.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
# Author: Nicolas Legrand <nicolas.legrand@cfin.au.dk>
22

33
import unittest
4-
import time
54
import matplotlib
65
import numpy as np
76
from unittest import TestCase
8-
from systole import import_ppg, serialSim
7+
from systole import serialSim
98
from systole.recording import Oximeter
109

1110

@@ -17,7 +16,7 @@ class TestRecording(TestCase):
1716

1817
def test_oximeter(self):
1918
oxi.setup()
20-
oxi.read(5)
19+
oxi.read(10)
2120
oxi.find_peaks()
2221

2322
# Simulate events in recording

systole/utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,10 @@ def heart_rate(x, sfreq=1000, unit='rr', kind='cubic'):
105105
before the first peak anf after the last peak will be filled with the
106106
adjacent heartrate.
107107
"""
108-
if np.any((np.abs(np.diff(x)) > 1)):
108+
if not ((x == 1) | (x == 0)).all():
109109
raise ValueError('Input vector should only contain 0 and 1')
110+
if isinstance(x, list):
111+
x = np.asarray(x)
110112

111113
# Find peak indexes
112114
peaks_idx = np.where(x)[0]
@@ -128,7 +130,7 @@ def heart_rate(x, sfreq=1000, unit='rr', kind='cubic'):
128130
if kind is not None:
129131
# Interpolate
130132
f = interp1d(time, heartrate, kind=kind, bounds_error=False,
131-
fill_value=(heartrate[0], heartrate[-1]))
133+
fill_value=(np.nan, np.nan))
132134
heartrate = f(new_time)
133135

134136
return heartrate, new_time

0 commit comments

Comments
 (0)