MCPcopy
hub / github.com/mne-tools/mne-python / _annotation_helper

Function _annotation_helper

mne/viz/tests/test_raw.py:52–202  ·  view source on GitHub ↗

Test interactive annotations.

(raw, browse_backend, events=False)

Source from the content-addressed store, hash-verified

50
51
52def _annotation_helper(raw, browse_backend, events=False):
53 """Test interactive annotations."""
54 from cycler import cycler # dep of matplotlib, should be okay but nest just in case
55
56 ismpl = browse_backend.name == "matplotlib"
57 # Some of our checks here require modern mpl to work properly
58 n_anns = len(raw.annotations)
59 browse_backend._close_all()
60
61 if events:
62 events = np.array([[raw.first_samp + 100, 0, 1], [raw.first_samp + 300, 0, 3]])
63 n_events = len(events)
64 else:
65 events = None
66 n_events = 0
67 # matplotlib 2.0 default cycler
68 default_cycler = cycler(
69 "color",
70 [
71 "#1f77b4",
72 "#ff7f0e",
73 "#2ca02c",
74 "#d62728",
75 "#9467bd",
76 "#8c564b",
77 "#e377c2",
78 "#7f7f7f",
79 "#bcbd22",
80 "#17becf",
81 ],
82 ) # noqa: E501
83 with catch_logging("debug") as log, rc_context({"axes.prop_cycle": default_cycler}):
84 fig = raw.plot(events=events)
85 log = log.getvalue()
86 assert "Removing from color cycle: #d62728" in log
87 assert log.count("Removing from color cycle") == 1
88 if ismpl:
89 assert browse_backend._get_n_figs() == 1
90
91 fig._fake_keypress("a") # annotation mode
92 ann_fig = fig.mne.fig_annotation
93 if ismpl:
94 assert browse_backend._get_n_figs() == 2
95 # +3 from the scale bars
96 n_scale = 3
97 assert len(fig.mne.ax_main.texts) == n_anns + n_events + n_scale
98 else:
99 assert ann_fig.isVisible()
100
101 # modify description to create label "BAD test"
102 # semicolon is ignored
103 if ismpl:
104 for key in ["backspace"] + list(" test;") + ["enter"]:
105 fig._fake_keypress(key, fig=ann_fig)
106 # change annotation label
107 for ix in (-1, 0):
108 xy = _get_button_xy(ann_fig.mne.radio_ax.buttons, ix)
109 fig._fake_click(xy, fig=ann_fig, ax=ann_fig.mne.radio_ax, xform="data")

Callers 1

test_plot_annotationsFunction · 0.85

Calls 8

catch_loggingClass · 0.90
_sync_onsetFunction · 0.90
_get_button_xyFunction · 0.85
getvalueMethod · 0.80
countMethod · 0.80
plotMethod · 0.45
_fake_keypressMethod · 0.45
_fake_clickMethod · 0.45

Tested by

no test coverage detected