Test annotation class.
()
| 78 | |
| 79 | |
| 80 | def test_basics(): |
| 81 | """Test annotation class.""" |
| 82 | raw = read_raw_fif(fif_fname) |
| 83 | assert raw.annotations is not None |
| 84 | assert len(raw.annotations.onset) == 0 |
| 85 | pytest.raises(OSError, read_annotations, fif_fname) |
| 86 | onset = np.array(range(10)) |
| 87 | duration = np.ones(10) |
| 88 | description = np.repeat("test", 10) |
| 89 | dt = raw.info["meas_date"] |
| 90 | assert isinstance(dt, datetime) |
| 91 | stamp = _dt_to_stamp(dt) |
| 92 | # Test time shifts. |
| 93 | for orig_time in [None, dt, stamp[0], stamp]: |
| 94 | annot = Annotations(onset, duration, description, orig_time) |
| 95 | if orig_time is None: |
| 96 | assert annot.orig_time is None |
| 97 | else: |
| 98 | assert isinstance(annot.orig_time, datetime) |
| 99 | assert annot.orig_time.tzinfo is timezone.utc |
| 100 | |
| 101 | pytest.raises(ValueError, Annotations, onset, duration, description[:9]) |
| 102 | pytest.raises(ValueError, Annotations, [onset, 1], duration, description) |
| 103 | pytest.raises(ValueError, Annotations, onset, [duration, 1], description) |
| 104 | |
| 105 | # Test combining annotations with concatenate_raws |
| 106 | raw2 = raw.copy() |
| 107 | delta = raw.times[-1] + 1.0 / raw.info["sfreq"] |
| 108 | orig_time = stamp[0] + stamp[1] * 1e-6 + raw2._first_time |
| 109 | offset = _dt_to_stamp(_handle_meas_date(raw2.info["meas_date"])) |
| 110 | offset = offset[0] + offset[1] * 1e-6 |
| 111 | offset = orig_time - offset |
| 112 | assert_allclose(offset, raw._first_time) |
| 113 | annot = Annotations(onset, duration, description, orig_time) |
| 114 | assert annot.orig_time is not None |
| 115 | assert " segments" in repr(annot) |
| 116 | raw2.set_annotations(annot) |
| 117 | assert_allclose(raw2.annotations.onset, onset + offset) |
| 118 | assert raw2.annotations is not annot |
| 119 | assert raw2.annotations.orig_time is not None |
| 120 | concatenate_raws([raw, raw2]) |
| 121 | assert_and_remove_boundary_annot(raw) |
| 122 | assert_allclose(onset + offset + delta, raw.annotations.onset, rtol=1e-5) |
| 123 | assert_array_equal(annot.duration, raw.annotations.duration) |
| 124 | assert_array_equal(raw.annotations.description, np.repeat("test", 10)) |
| 125 | |
| 126 | |
| 127 | def test_annot_sanitizing(tmp_path): |
nothing calls this directly
no test coverage detected