Coverage for emd/tests/test_utils.py: 100%
30 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-09 10:07 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-09 10:07 +0000
1"""Tests for general utility functions."""
3import unittest
5import numpy as np
8class TestAmplitudeNormalise(unittest.TestCase):
9 """Ensure amplitude normalise is working."""
11 def setUp(self):
12 """Initialise cycles for testing."""
13 # Create core signal
14 seconds = 5.1
15 sample_rate = 2000
16 f1 = 2
17 f2 = 18
18 time_vect = np.linspace(0, seconds, int(seconds * sample_rate))
19 am = np.sin(2*np.pi*f1*time_vect) + 1
21 self.x = am * np.cos(2.3 * np.pi * f2 * time_vect)
23 def test_amplitude_normalise(self):
24 """Ensure amplitude normalise is working."""
25 from ..imftools import amplitude_normalise
27 amp_norm = amplitude_normalise(self.x[:, np.newaxis])
29 # start signal should range between +/- 2
30 assert(2 - np.max(self.x) < 1e-2)
31 assert(2 + np.min(self.x) < 1e-2)
33 # norm signal should range between +/-
34 assert(1 - np.max(amp_norm) < 1e-2)
35 assert(1 + np.min(amp_norm) < 1e-2)
38class TestEpochs(unittest.TestCase):
39 """Ensure epoching is working."""
41 def setUp(self):
42 """Initialise data for testing."""
43 # Create core signal
44 seconds = 5
45 sample_rate = 2000
46 f2 = 5
47 time_vect = np.linspace(0, seconds, int(seconds * sample_rate))
49 self.x = np.cos(2 * np.pi * f2 * time_vect + np.pi/2)
51 def test_find_extrema_locked_epochs(self):
52 """Ensure extrema-epoching is working."""
53 from ..imftools import find_extrema_locked_epochs
55 trls = find_extrema_locked_epochs(self.x, 40)
57 assert(trls.shape[0] == 25)
58 assert(np.all(np.unique(np.diff(trls)) == 40))