From 3ecc9118f62f7842cc7f04d4fe9eb9538a8879fb Mon Sep 17 00:00:00 2001 From: Scott Huberty Date: Thu, 28 Sep 2023 14:26:54 -0400 Subject: [PATCH] TST: Test that a channel specific annot is plotted at the correct ypos --- mne_qt_browser/tests/test_pg_specific.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/mne_qt_browser/tests/test_pg_specific.py b/mne_qt_browser/tests/test_pg_specific.py index 1a74ba89..8d032b16 100644 --- a/mne_qt_browser/tests/test_pg_specific.py +++ b/mne_qt_browser/tests/test_pg_specific.py @@ -84,7 +84,7 @@ def test_annotations_interactions(raw_orig, pg_backend): fig.msg_box.close() -def test_ch_specific_annot(raw_orig): +def test_ch_specific_annot(raw_orig, pg_backend): """Test plotting channel specific annotations.""" from mne import Annotations from pyqtgraph.graphicsItems.FillBetweenItem import FillBetweenItem @@ -92,11 +92,24 @@ def test_ch_specific_annot(raw_orig): ch_names = ["MEG 0133", "MEG 0142", "MEG 0143", "MEG 0423"] annots = Annotations([1], [2], "some_chs", ch_names=[ch_names]) raw_orig.set_annotations(annots) + fig = raw_orig.plot() + fig_ch_names = list(fig.mne.ch_names[fig.mne.ch_order]) fig.test_mode = True + # one item for each channel in a channel specific annot - rects = [item for item in fig.mne.plt.items if isinstance(item, FillBetweenItem)] - assert len(rects) == 4 + fill_betweens = [ + item for item in fig.mne.plt.items if isinstance(item, FillBetweenItem)] + assert len(fill_betweens) == 4 # 4 channels in annots[0].ch_names + + # check that a channel specific annot is plotted at the correct ypos + last_fill_between = fill_betweens[-1].curves[0] + # "MEG 0423" should be the 28th channel in the plot. + # the +1 is needed because ypos indexing of the traces starts at 1, not 0 + want_index = fig_ch_names.index(raw_orig.annotations.ch_names[0][-1]) + 1 + # The round basically just rounds 27.5 up to 28 + got_index = np.round(last_fill_between.yData[0],).astype(int) + assert got_index == want_index # should be 28 fig.close()