Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions mne_qt_browser/_pg_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2588,19 +2588,28 @@ def __init__(self, mne, weakmain, annot, ch_name):
self.annot = annot
self.ch_name = ch_name

ypos = np.where(self.mne.ch_names[self.mne.ch_order] == self.ch_name)[0] + 1
self.ypos = ypos + np.array([-0.5, 0.5])
# We have a choice here: some channel-specific annotations will have
# channels that are not plotted (e.g., with raw.plot(..., order=[0, 1])).
# Here we choose to add them as invisible plot items so that if you for example
# remove all *visible* channels from the annot it won't suddenly become an
# all-channel annotation. It will instead disappear from the plot, but still
# live in raw.annotations. We could emit a warning, but it would probably
# become annoying. At some point we could add a warning
# *when you delete the last visible channel* to let people know that the
# annot still exists but can no longer be modified, or something similar.
# It would be good to have this be driven by an actual use case / experience.
idx = np.where(self.mne.ch_names[self.mne.ch_order] == self.ch_name)[0]
if len(idx) == 1: # should be 1 or 0 (if channel not plotted at all)
self.ypos = idx + np.array([0.5, 1.5])
else:
self.ypos = np.full(2, np.nan)

# self.lower = PlotCurveItem()
# self.upper = PlotCurveItem()
self.upper = PlotDataItem()
self.lower = PlotDataItem()

# init
super().__init__(self.lower, self.upper)

# self.setCurves(self.lower, self.upper)

self.update_plot_curves()

color_string = self.mne.annotation_segment_colors[self.annot.description]
Expand Down
10 changes: 6 additions & 4 deletions mne_qt_browser/tests/test_pg_specific.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,23 @@ def test_ch_specific_annot(raw_orig, pg_backend):
annots = Annotations([annot_onset], [annot_dur], "some_chs", ch_names=[ch_names])
raw_orig.set_annotations(annots)

fig = raw_orig.plot()
ch_names.pop(-1) # don't plot the last one!
fig = raw_orig.plot(picks=ch_names) # omit the first one
fig_ch_names = list(fig.mne.ch_names[fig.mne.ch_order])
fig.test_mode = True
annot_dock = fig.mne.fig_annotation

# one FillBetweenItem for each channel in a channel specific annot
annot = fig.mne.regions[0]
assert (
len(annot.single_channel_annots) == 4
len(annot.single_channel_annots) == 4 # we still make them even for invisible
) # 4 channels in annots[0].single_channel_annots

# check that a channel specific annot is plotted at the correct ypos
single_channel_annot = annot.single_channel_annots["MEG 0423"]
which_name = raw_orig.annotations.ch_names[0][-2]
single_channel_annot = annot.single_channel_annots[which_name]
# 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
want_index = fig_ch_names.index(which_name) + 1
got_index = np.mean(single_channel_annot.ypos).astype(int)
assert got_index == want_index # should be 28

Expand Down
Loading