Skip to content

Commit

Permalink
TST: Test that a channel specific annot is plotted at the correct ypos
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-huberty committed Sep 28, 2023
1 parent 2a7b249 commit 3ecc911
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions mne_qt_browser/tests/test_pg_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,32 @@ 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

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()


Expand Down

0 comments on commit 3ecc911

Please sign in to comment.