|
| 1 | +import logging |
| 2 | + |
1 | 3 | import numpy as np
|
2 | 4 | import pytest
|
3 | 5 | from pyxdf.pyxdf import _clock_sync
|
4 | 6 |
|
5 | 7 | from mock_data_stream import MockStreamData
|
6 | 8 |
|
7 |
| - |
8 | 9 | # No clock resets
|
9 | 10 |
|
10 | 11 |
|
@@ -172,6 +173,86 @@ def test_sync_no_resets_bounds_jitter(
|
172 | 173 | np.testing.assert_equal(streams[1].clock_segments, [(0, len(time_stamps) - 1)])
|
173 | 174 |
|
174 | 175 |
|
| 176 | +# Invalid clock offsets: LinAlgError |
| 177 | + |
| 178 | + |
| 179 | +def test_clock_sync_error_keep_segment(caplog): |
| 180 | + caplog.set_level(logging.WARNING) |
| 181 | + expected = [0, 1, 2, 3, 4] + [15, 16, 17, 18, 19] |
| 182 | + time_stamps = np.arange(0, len(expected)) |
| 183 | + # Clock offsets (0, 1) are unusable: LinAlgError |
| 184 | + clock_times = [0, 0] + [10, 15] |
| 185 | + clock_values = [0, 0] + [10, 10] |
| 186 | + streams = { |
| 187 | + 1: MockStreamData( |
| 188 | + time_stamps=time_stamps, |
| 189 | + clock_times=clock_times, |
| 190 | + clock_values=clock_values, |
| 191 | + ) |
| 192 | + } |
| 193 | + _clock_sync( |
| 194 | + streams, |
| 195 | + reset_threshold_stds=0, |
| 196 | + reset_threshold_seconds=4, |
| 197 | + reset_threshold_offset_stds=0, |
| 198 | + reset_threshold_offset_seconds=9, |
| 199 | + ) |
| 200 | + assert "Clock offsets (0, 1) cannot be used for synchronization" in caplog.text |
| 201 | + np.testing.assert_allclose( |
| 202 | + streams[1].time_stamps, |
| 203 | + expected, |
| 204 | + ) |
| 205 | + np.testing.assert_equal(streams[1].time_series[:, 0], time_stamps) |
| 206 | + np.testing.assert_equal(streams[1].clock_times, clock_times) |
| 207 | + np.testing.assert_equal(streams[1].clock_values, clock_values) |
| 208 | + np.testing.assert_equal( |
| 209 | + streams[1].clock_segments, |
| 210 | + [ |
| 211 | + (0, 4), |
| 212 | + (5, 9), |
| 213 | + ], |
| 214 | + ) |
| 215 | + |
| 216 | + |
| 217 | +def test_clock_sync_error_skip_segment(caplog): |
| 218 | + caplog.set_level(logging.WARNING) |
| 219 | + expected = [15, 16, 17, 18, 19, 20, 21, 22, 23, 24] |
| 220 | + # All time-stamps should be synchronized by clock offsets (2, 3) |
| 221 | + time_stamps = np.arange(5, 5 + len(expected)) |
| 222 | + # Clock offsets (0, 1) are unusable: LinAlgError |
| 223 | + clock_times = [0, 0] + [10, 15] |
| 224 | + clock_values = [0, 0] + [10, 10] |
| 225 | + streams = { |
| 226 | + 1: MockStreamData( |
| 227 | + time_stamps=time_stamps, |
| 228 | + clock_times=clock_times, |
| 229 | + clock_values=clock_values, |
| 230 | + ) |
| 231 | + } |
| 232 | + _clock_sync( |
| 233 | + streams, |
| 234 | + reset_threshold_stds=0, |
| 235 | + reset_threshold_seconds=4, |
| 236 | + reset_threshold_offset_stds=0, |
| 237 | + reset_threshold_offset_seconds=9, |
| 238 | + ) |
| 239 | + assert "Clock offsets (0, 1) cannot be used for synchronization" in caplog.text |
| 240 | + assert "No samples in clock offsets (0, 1), skipping..." in caplog.text |
| 241 | + np.testing.assert_allclose( |
| 242 | + streams[1].time_stamps, |
| 243 | + expected, |
| 244 | + ) |
| 245 | + np.testing.assert_equal(streams[1].time_series[:, 0], time_stamps) |
| 246 | + np.testing.assert_equal(streams[1].clock_times, clock_times) |
| 247 | + np.testing.assert_equal(streams[1].clock_values, clock_values) |
| 248 | + np.testing.assert_equal( |
| 249 | + streams[1].clock_segments, |
| 250 | + [ |
| 251 | + (0, 9), |
| 252 | + ], |
| 253 | + ) |
| 254 | + |
| 255 | + |
175 | 256 | # Clock resets
|
176 | 257 |
|
177 | 258 |
|
|
0 commit comments