1111from mne import read_events , pick_types , Annotations
1212from mne .io import read_raw_fif
1313from mne .utils import requires_version , run_tests_if_main
14- from mne .viz .utils import _fake_click
14+ from mne .viz .utils import _fake_click , _annotation_radio_clicked
1515from mne .viz import plot_raw , plot_sensors
1616
1717# Set our plotters to test mode
@@ -41,7 +41,6 @@ def _get_events():
4141 return read_events (event_name )
4242
4343
44- @requires_version ('matplotlib' , '1.2' )
4544def test_plot_raw ():
4645 """Test plotting of raw data."""
4746 import matplotlib .pyplot as plt
@@ -53,7 +52,8 @@ def test_plot_raw():
5352 # test mouse clicks
5453 x = fig .get_axes ()[0 ].lines [1 ].get_xdata ().mean ()
5554 y = fig .get_axes ()[0 ].lines [1 ].get_ydata ().mean ()
56- data_ax = fig .get_axes ()[0 ]
55+ data_ax = fig .axes [0 ]
56+
5757 _fake_click (fig , data_ax , [x , y ], xform = 'data' ) # mark a bad channel
5858 _fake_click (fig , data_ax , [x , y ], xform = 'data' ) # unmark a bad channel
5959 _fake_click (fig , data_ax , [0.5 , 0.999 ]) # click elsewhere in 1st axes
@@ -75,22 +75,9 @@ def test_plot_raw():
7575 # _fake_click(ssp_fig, ssp_fig.get_axes()[0], pos, xform='data') # off
7676 # _fake_click(ssp_fig, ssp_fig.get_axes()[0], pos, xform='data') # on
7777 # test keypresses
78- fig .canvas .key_press_event ('escape' )
79- fig .canvas .key_press_event ('down' )
80- fig .canvas .key_press_event ('up' )
81- fig .canvas .key_press_event ('right' )
82- fig .canvas .key_press_event ('left' )
83- fig .canvas .key_press_event ('o' )
84- fig .canvas .key_press_event ('-' )
85- fig .canvas .key_press_event ('+' )
86- fig .canvas .key_press_event ('=' )
87- fig .canvas .key_press_event ('pageup' )
88- fig .canvas .key_press_event ('pagedown' )
89- fig .canvas .key_press_event ('home' )
90- fig .canvas .key_press_event ('end' )
91- fig .canvas .key_press_event ('?' )
92- fig .canvas .key_press_event ('f11' )
93- fig .canvas .key_press_event ('escape' )
78+ for key in ['down' , 'up' , 'right' , 'left' , 'o' , '-' , '+' , '=' ,
79+ 'pageup' , 'pagedown' , 'home' , 'end' , '?' , 'f11' , 'escape' ]:
80+ fig .canvas .key_press_event (key )
9481 # Color setting
9582 assert_raises (KeyError , raw .plot , event_color = {0 : 'r' })
9683 assert_raises (TypeError , raw .plot , event_color = {'foo' : 'r' })
@@ -134,6 +121,61 @@ def test_plot_raw():
134121 plt .close ('all' )
135122
136123
124+ def test_plot_annotations ():
125+ """Test annotation mode of the plotter."""
126+ import matplotlib .pyplot as plt
127+ raw = _get_raw ()
128+ fig = raw .plot ()
129+ data_ax = fig .axes [0 ]
130+ fig .canvas .key_press_event ('a' ) # annotation mode
131+ # modify description
132+ ann_fig = plt .gcf ()
133+ for key in ' test' :
134+ ann_fig .canvas .key_press_event (key )
135+ ann_fig .canvas .key_press_event ('enter' )
136+
137+ ann_fig = plt .gcf ()
138+ # XXX: _fake_click raises an error on Agg backend
139+ _annotation_radio_clicked ('' , ann_fig .radio , data_ax .selector )
140+
141+ # draw annotation
142+ _fake_click (fig , data_ax , [1. , 1. ], xform = 'data' , button = 1 , kind = 'press' )
143+ _fake_click (fig , data_ax , [5. , 1. ], xform = 'data' , button = 1 , kind = 'motion' )
144+ _fake_click (fig , data_ax , [5. , 1. ], xform = 'data' , button = 1 , kind = 'release' )
145+ # hover event
146+ _fake_click (fig , data_ax , [4.5 , 1. ], xform = 'data' , button = None ,
147+ kind = 'motion' )
148+ _fake_click (fig , data_ax , [4.7 , 1. ], xform = 'data' , button = None ,
149+ kind = 'motion' )
150+ # modify annotation from end
151+ _fake_click (fig , data_ax , [5. , 1. ], xform = 'data' , button = 1 , kind = 'press' )
152+ _fake_click (fig , data_ax , [2.5 , 1. ], xform = 'data' , button = 1 , kind = 'motion' )
153+ _fake_click (fig , data_ax , [2.5 , 1. ], xform = 'data' , button = 1 ,
154+ kind = 'release' )
155+ # modify annotation from beginning
156+ _fake_click (fig , data_ax , [1. , 1. ], xform = 'data' , button = 1 , kind = 'press' )
157+ _fake_click (fig , data_ax , [1.1 , 1. ], xform = 'data' , button = 1 , kind = 'motion' )
158+ _fake_click (fig , data_ax , [1.1 , 1. ], xform = 'data' , button = 1 ,
159+ kind = 'release' )
160+ assert_equal (len (raw .annotations .onset ), 1 )
161+ assert_equal (len (raw .annotations .duration ), 1 )
162+ assert_equal (len (raw .annotations .description ), 1 )
163+ assert_equal (raw .annotations .description [0 ], 'BAD test' )
164+
165+ # draw another annotation merging the two
166+ _fake_click (fig , data_ax , [5.5 , 1. ], xform = 'data' , button = 1 , kind = 'press' )
167+ _fake_click (fig , data_ax , [2. , 1. ], xform = 'data' , button = 1 , kind = 'motion' )
168+ _fake_click (fig , data_ax , [2. , 1. ], xform = 'data' , button = 1 , kind = 'release' )
169+ # delete the annotation
170+ _fake_click (fig , data_ax , [1.5 , 1. ], xform = 'data' , button = 3 , kind = 'press' )
171+ fig .canvas .key_press_event ('a' ) # exit annotation mode
172+ plt .close ('all' )
173+
174+ assert_equal (len (raw .annotations .onset ), 0 )
175+ assert_equal (len (raw .annotations .duration ), 0 )
176+ assert_equal (len (raw .annotations .description ), 0 )
177+
178+
137179@requires_version ('scipy' , '0.10' )
138180def test_plot_raw_filtered ():
139181 """Test filtering of raw plots."""
@@ -187,7 +229,6 @@ def test_plot_raw_psd():
187229 assert_raises (ValueError , raw .plot_psd )
188230
189231
190- @requires_version ('matplotlib' , '1.2' )
191232def test_plot_sensors ():
192233 """Test plotting of sensor array."""
193234 import matplotlib .pyplot as plt
0 commit comments