#NEWLINE# def test_events( ) : #NEWLINE# #INDENT# 'Test reading and modifying events' #NEWLINE# tempdir = _TempDir ( ) #NEWLINE# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# raw = read_raw_brainvision ( vhdr_path , eog = eog , preload = True ) #NEWLINE# events = raw . _get_brainvision_events ( ) #NEWLINE# assert_array_equal ( events , [ [ 487 , 1 , 253 ] , [ 497 , 1 , 255 ] , [ 1770 , 1 , 254 ] , [ 1780 , 1 , 255 ] , [ 3253 , 1 , 254 ] , [ 3263 , 1 , 255 ] , [ 4936 , 1 , 253 ] , [ 4946 , 1 , 255 ] , [ 6000 , 1 , 255 ] , [ 6620 , 1 , 254 ] , [ 6630 , 1 , 255 ] ] ) #NEWLINE# assert_equal ( len ( w ) , 1 ) #NEWLINE# #UNINDENT# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# raw = read_raw_brainvision ( vhdr_path , eog = eog , preload = True , response_trig_shift = 1000 ) #NEWLINE# events = raw . _get_brainvision_events ( ) #NEWLINE# assert_array_equal ( events , [ [ 487 , 1 , 253 ] , [ 497 , 1 , 255 ] , [ 1770 , 1 , 254 ] , [ 1780 , 1 , 255 ] , [ 3253 , 1 , 254 ] , [ 3263 , 1 , 255 ] , [ 4936 , 1 , 253 ] , [ 4946 , 1 , 255 ] , [ 6000 , 1 , 1255 ] , [ 6620 , 1 , 254 ] , [ 6630 , 1 , 255 ] ] ) #NEWLINE# assert_equal ( len ( w ) , 1 ) #NEWLINE# #UNINDENT# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# raw = read_raw_brainvision ( vhdr_path , eog = eog , preload = True , response_trig_shift = None ) #NEWLINE# events = raw . _get_brainvision_events ( ) #NEWLINE# assert_array_equal ( events , [ [ 487 , 1 , 253 ] , [ 497 , 1 , 255 ] , [ 1770 , 1 , 254 ] , [ 1780 , 1 , 255 ] , [ 3253 , 1 , 254 ] , [ 3263 , 1 , 255 ] , [ 4936 , 1 , 253 ] , [ 4946 , 1 , 255 ] , [ 6620 , 1 , 254 ] , [ 6630 , 1 , 255 ] ] ) #NEWLINE# assert_equal ( len ( w ) , 1 ) #NEWLINE# #UNINDENT# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# raw = read_raw_brainvision ( vhdr_path , eog = eog , preload = True , response_trig_shift = None , event_id = { #NEWLINE# #INDENT# 'Sync On' : 5 , #NEWLINE# #UNINDENT# } ) #NEWLINE# events = raw . _get_brainvision_events ( ) #NEWLINE# assert_array_equal ( events , [ [ 487 , 1 , 253 ] , [ 497 , 1 , 255 ] , [ 1770 , 1 , 254 ] , [ 1780 , 1 , 255 ] , [ 3253 , 1 , 254 ] , [ 3263 , 1 , 255 ] , [ 4936 , 1 , 253 ] , [ 4946 , 1 , 255 ] , [ 6620 , 1 , 254 ] , [ 6630 , 1 , 255 ] , [ 7630 , 1 , 5 ] ] ) #NEWLINE# assert_equal ( len ( w ) , 1 ) #NEWLINE# #UNINDENT# assert_raises ( TypeError , read_raw_brainvision , vhdr_path , eog = eog , preload = True , response_trig_shift = 0.1 ) #NEWLINE# assert_raises ( TypeError , read_raw_brainvision , vhdr_path , eog = eog , preload = True , response_trig_shift = np . nan ) #NEWLINE# with warnings . catch_warnings ( record = True ) as w : #NEWLINE# #INDENT# warnings . simplefilter ( 'always' ) #NEWLINE# read_raw_brainvision ( vhdr_path , eog = eog , preload = False , response_trig_shift = 100 , event_id = { #NEWLINE# #INDENT# 'Sync On' : 5 , #NEWLINE# #UNINDENT# } ) #NEWLINE# mne_events = find_events ( raw , stim_channel = 'STI 014' ) #NEWLINE# assert_array_equal ( events [ : , [ 0 , 2 ] ] , mne_events [ : , [ 0 , 2 ] ] ) #NEWLINE# assert_equal ( len ( w ) , 0 ) #NEWLINE# #UNINDENT# index = ( events [ : , 2 ] == 255 ) #NEWLINE# events = events [ fname ] #NEWLINE# raw . _set_brainvision_events ( events ) #NEWLINE# mne_events = find_events ( raw , stim_channel = 'STI 014' ) #NEWLINE# assert_array_equal ( events [ : , [ 0 , 2 ] ] , mne_events [ : , [ 0 , 2 ] ] ) #NEWLINE# nchan = raw . info [ 'nchan' ] #NEWLINE# ch_name = raw . info [ 'chs' ] [ ( - 2 ) ] [ 'ch_name' ] #NEWLINE# events = np . empty ( ( 0 , 3 ) ) #NEWLINE# raw . _set_brainvision_events ( events ) #NEWLINE# assert_equal ( raw . info [ 'nchan' ] , nchan ) #NEWLINE# assert_equal ( len ( raw . _data ) , nchan ) #NEWLINE# assert_equal ( raw . info [ 'chs' ] [ ( - 2 ) ] [ 'ch_name' ] , ch_name ) #NEWLINE# assert_equal ( len ( find_events ( raw , 'STI 014' ) ) , 0 ) #NEWLINE# assert_allclose ( raw [ ( - 1 ) ] [ 0 ] , 0.0 ) #NEWLINE# fname = op . join ( tempdir , 'evt_raw.fif' ) #NEWLINE# raw . save ( fname ) #NEWLINE# events = [ [ 10 , 1 , 2 ] ] #NEWLINE# raw . _set_brainvision_events ( events ) #NEWLINE# assert_equal ( raw . info [ 'nchan' ] , nchan ) #NEWLINE# assert_equal ( len ( raw . _data ) , nchan ) #NEWLINE# assert_equal ( raw . info [ 'chs' ] [ ( - 1 ) ] [ 'ch_name' ] , 'STI 014' )