|
23 | 23 | SHOW_PROJECTORS = "Show projectors"
|
24 | 24 |
|
25 | 25 |
|
| 26 | +def test_annotations_single_sample(raw_orig, pg_backend): |
| 27 | + """Test anotations with duration of 0 s.""" |
| 28 | + # Crop and resample to avoid failing tests due to rounding in browser |
| 29 | + # Resampling also significantly speeds up the tests |
| 30 | + raw_orig = raw_orig.copy().crop(tmax=20.0).resample(100) |
| 31 | + # Add first annotation to initialize the description "A" |
| 32 | + onset = 2 |
| 33 | + duration = 1 |
| 34 | + description = "A" |
| 35 | + first_time = raw_orig.first_time |
| 36 | + raw_orig.annotations.append(onset + first_time, duration, description) |
| 37 | + fig = raw_orig.plot(duration=raw_orig.duration) |
| 38 | + fig.test_mode = True |
| 39 | + # Activate annotation_mode |
| 40 | + fig._fake_keypress("a") |
| 41 | + |
| 42 | + # Select Annotation |
| 43 | + fig._fake_click((2.5, 1.0), xform="data") |
| 44 | + # Assert that annotation was selected |
| 45 | + annot_dock = fig.mne.fig_annotation |
| 46 | + assert annot_dock.start_bx.value() == 2 |
| 47 | + assert annot_dock.stop_bx.value() == 3 |
| 48 | + |
| 49 | + # Test by setting values with Spinboxes |
| 50 | + # First, test zero duration annotation at recording start. |
| 51 | + annot_dock.start_bx.setValue(0) |
| 52 | + annot_dock.start_bx.editingFinished.emit() |
| 53 | + annot_dock.stop_bx.setValue(0) |
| 54 | + annot_dock.stop_bx.editingFinished.emit() |
| 55 | + # Assert that annotation starts and ends at 0 and duration is 0 |
| 56 | + assert_allclose(raw_orig.annotations.onset[0], 0 + first_time, atol=1e-4) |
| 57 | + assert_allclose(raw_orig.annotations.duration[0], 0, atol=1e-4) |
| 58 | + |
| 59 | + # Now test zero duration annotation at arbitrary time. |
| 60 | + sample_time = raw_orig.times[10] |
| 61 | + annot_dock.stop_bx.setValue(sample_time) |
| 62 | + annot_dock.stop_bx.editingFinished.emit() |
| 63 | + annot_dock.start_bx.setValue(sample_time) |
| 64 | + annot_dock.start_bx.editingFinished.emit() |
| 65 | + # Assert that annotation starts and ends at selected time and duration is 0 |
| 66 | + assert_allclose(raw_orig.annotations.onset[0], sample_time + first_time, atol=1e-4) |
| 67 | + assert_allclose(raw_orig.annotations.duration[0], 0, atol=1e-4) |
| 68 | + |
| 69 | + # Finally, test zero duration annotation at recording end. |
| 70 | + last_time = raw_orig.times[-1] |
| 71 | + annot_dock.stop_bx.setValue(last_time) |
| 72 | + annot_dock.stop_bx.editingFinished.emit() |
| 73 | + annot_dock.start_bx.setValue(last_time) |
| 74 | + annot_dock.start_bx.editingFinished.emit() |
| 75 | + # Assert that annotation starts and ends at last sample and duration is 0 |
| 76 | + assert_allclose(raw_orig.annotations.onset[0], last_time + first_time, atol=1e-4) |
| 77 | + assert_allclose(raw_orig.annotations.duration[0], 0, atol=1e-4) |
| 78 | + |
| 79 | + |
| 80 | +def test_annotations_recording_end(raw_orig, pg_backend): |
| 81 | + """Test anotations at the end of recording.""" |
| 82 | + # Crop and resample to avoid failing tests due to rounding in browser |
| 83 | + # Resampling also significantly speeds up the tests |
| 84 | + raw_orig = raw_orig.copy().crop(tmax=20.0).resample(100) |
| 85 | + # Add first annotation to initialize the description "A" |
| 86 | + onset = 2 |
| 87 | + duration = 1 |
| 88 | + description = "A" |
| 89 | + first_time = raw_orig.first_time |
| 90 | + raw_orig.annotations.append(onset + first_time, duration, description) |
| 91 | + n_anns = len(raw_orig.annotations) |
| 92 | + fig = raw_orig.plot(duration=raw_orig.duration) |
| 93 | + fig.test_mode = True |
| 94 | + # Activate annotation_mode |
| 95 | + fig._fake_keypress("a") |
| 96 | + |
| 97 | + # Draw additional annotation that extends to the end of the current view |
| 98 | + fig._fake_click( |
| 99 | + (0.0, 1.0), |
| 100 | + add_points=[(1.0, 1.0)], |
| 101 | + xform="ax", |
| 102 | + button=1, |
| 103 | + kind="drag", |
| 104 | + ) |
| 105 | + # Assert number of annotations did not change |
| 106 | + assert len(raw_orig.annotations) == n_anns |
| 107 | + new_annot_end = raw_orig.annotations.onset[0] + raw_orig.annotations.duration[0] |
| 108 | + # Assert that the annotation end extends 1 sample above the recording |
| 109 | + assert_allclose( |
| 110 | + new_annot_end, |
| 111 | + raw_orig.times[-1] + first_time + 1 / raw_orig.info["sfreq"], |
| 112 | + atol=1e-4, |
| 113 | + ) |
| 114 | + |
| 115 | + |
26 | 116 | def test_annotations_interactions(raw_orig, pg_backend):
|
27 | 117 | """Test interactions specific to pyqtgraph-backend."""
|
28 | 118 | # Add test-annotations
|
@@ -97,7 +187,7 @@ def test_annotations_interactions(raw_orig, pg_backend):
|
97 | 187 | annot_dock.start_bx.setValue(6)
|
98 | 188 | annot_dock.start_bx.editingFinished.emit()
|
99 | 189 | assert fig.msg_box.isVisible()
|
100 |
| - assert fig.msg_box.informativeText() == "Start can't be bigger or equal to Stop!" |
| 190 | + assert fig.msg_box.informativeText() == "Start can't be bigger than Stop!" |
101 | 191 | fig.msg_box.close()
|
102 | 192 |
|
103 | 193 | # Test that dragging annotation onto the tail of another works
|
|
0 commit comments