<s> import os . path as op <EOL> import os <EOL> from nose . tools import assert_true , assert_raises <EOL> import numpy as np <EOL> from numpy . testing import ( assert_array_almost_equal , assert_array_equal , <EOL> assert_equal ) <EOL> import warnings <EOL> from mne import ( read_events , write_events , make_fixed_length_events , <EOL> find_events , pick_events , find_stim_steps , io , pick_channels ) <EOL> from mne . tests . common import assert_naming <EOL> from mne . utils import _TempDir , run_tests_if_main <EOL> from mne . event import define_target_events , merge_events <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> base_dir = op . join ( op . dirname ( __file__ ) , '<STR_LIT:..>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:data>' ) <EOL> fname = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname_gz = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname_1 = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname_txt = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname_txt_1 = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname_txt_mpr = op . join ( base_dir , '<STR_LIT>' ) <EOL> fname_old_txt = op . join ( base_dir , '<STR_LIT>' ) <EOL> raw_fname = op . join ( base_dir , '<STR_LIT>' ) <EOL> def test_fix_stim ( ) : <EOL> """<STR_LIT>""" <EOL> raw = io . read_raw_fif ( raw_fname , preload = True ) <EOL> raw . _data [ raw . ch_names . index ( '<STR_LIT>' ) , : <NUM_LIT:3> ] = [ <NUM_LIT:0> , - <NUM_LIT> , <NUM_LIT:0> ] <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> events = find_events ( raw , '<STR_LIT>' ) <EOL> assert_true ( len ( w ) >= <NUM_LIT:1> ) <EOL> assert_true ( any ( '<STR_LIT>' in str ( ww . message ) for ww in w ) ) <EOL> assert_array_equal ( events [ <NUM_LIT:0> ] , [ raw . first_samp + <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> events = find_events ( raw , '<STR_LIT>' , uint_cast = True ) <EOL> assert_array_equal ( events [ <NUM_LIT:0> ] , [ raw . first_samp + <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ] ) <EOL> def test_add_events ( ) : <EOL> """<STR_LIT>""" <EOL> raw = io . read_raw_fif ( raw_fname , preload = False ) <EOL> events = np . array ( [ [ raw . first_samp , <NUM_LIT:0> , <NUM_LIT:1> ] ] ) <EOL> assert_raises ( RuntimeError , raw . add_events , events , '<STR_LIT>' ) <EOL> raw = io . read_raw_fif ( raw_fname , preload = True ) <EOL> orig_events = find_events ( raw , '<STR_LIT>' ) <EOL> events = np . array ( [ raw . first_samp , <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> assert_raises ( ValueError , raw . add_events , events , '<STR_LIT>' ) <EOL> events [ <NUM_LIT:0> ] = raw . first_samp + raw . n_times + <NUM_LIT:1> <EOL> events = events [ np . newaxis , : ] <EOL> assert_raises ( ValueError , raw . add_events , events , '<STR_LIT>' ) <EOL> events [ <NUM_LIT:0> , <NUM_LIT:0> ] = raw . first_samp - <NUM_LIT:1> <EOL> assert_raises ( ValueError , raw . add_events , events , '<STR_LIT>' ) <EOL> events [ <NUM_LIT:0> , <NUM_LIT:0> ] = raw . first_samp + <NUM_LIT:1> <EOL> assert_raises ( ValueError , raw . add_events , events , '<STR_LIT>' ) <EOL> raw . add_events ( events , '<STR_LIT>' ) <EOL> new_events = find_events ( raw , '<STR_LIT>' ) <EOL> assert_array_equal ( new_events , np . concatenate ( ( events , orig_events ) ) ) <EOL> def test_merge_events ( ) : <EOL> """<STR_LIT>""" <EOL> events_orig = [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:2> ] , [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:3> ] , [ <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:4> ] ] <EOL> events_replacement = [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:12> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:12> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT> ] ] <EOL> events_no_replacement = [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:12> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:12> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:3> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:0> , <NUM_LIT> ] ] <EOL> for replace_events , events_good in [ ( True , events_replacement ) , <EOL> ( False , events_no_replacement ) ] : <EOL> events = merge_events ( events_orig , [ <NUM_LIT:1> , <NUM_LIT:2> ] , <NUM_LIT:12> , replace_events ) <EOL> events = merge_events ( events , [ <NUM_LIT:3> , <NUM_LIT:4> ] , <NUM_LIT> , replace_events ) <EOL> events = merge_events ( events , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <NUM_LIT> , replace_events ) <EOL> assert_array_equal ( events , events_good ) <EOL> def test_io_events ( ) : <EOL> """<STR_LIT>""" <EOL> tempdir = _TempDir ( ) <EOL> events = read_events ( fname ) <EOL> write_events ( op . join ( tempdir , '<STR_LIT>' ) , events ) <EOL> events2 = read_events ( op . join ( tempdir , '<STR_LIT>' ) ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> events2 = read_events ( fname_gz ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> write_events ( op . join ( tempdir , '<STR_LIT>' ) , events2 ) <EOL> events2 = read_events ( op . join ( tempdir , '<STR_LIT>' ) ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> write_events ( op . join ( tempdir , '<STR_LIT>' ) , events ) <EOL> events2 = read_events ( op . join ( tempdir , '<STR_LIT>' ) ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> events2 = read_events ( fname_txt_mpr ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> events2 = read_events ( fname_old_txt ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> write_events ( op . join ( tempdir , '<STR_LIT>' ) , events ) <EOL> events2 = read_events ( op . join ( tempdir , '<STR_LIT>' ) ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> a = read_events ( op . join ( tempdir , '<STR_LIT>' ) , include = <NUM_LIT:1> ) <EOL> b = read_events ( op . join ( tempdir , '<STR_LIT>' ) , include = [ <NUM_LIT:1> ] ) <EOL> c = read_events ( op . join ( tempdir , '<STR_LIT>' ) , <EOL> exclude = [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:32> ] ) <EOL> d = read_events ( op . join ( tempdir , '<STR_LIT>' ) , include = <NUM_LIT:1> , <EOL> exclude = [ <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> assert_array_equal ( a , b ) <EOL> assert_array_equal ( a , c ) <EOL> assert_array_equal ( a , d ) <EOL> events = read_events ( fname_1 ) <EOL> write_events ( op . join ( tempdir , '<STR_LIT>' ) , events ) <EOL> events2 = read_events ( op . join ( tempdir , '<STR_LIT>' ) ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> write_events ( op . join ( tempdir , '<STR_LIT>' ) , events ) <EOL> events2 = read_events ( op . join ( tempdir , '<STR_LIT>' ) ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> with warnings . catch_warnings ( record = True ) as w : <EOL> warnings . simplefilter ( '<STR_LIT>' ) <EOL> fname2 = op . join ( tempdir , '<STR_LIT>' ) <EOL> write_events ( fname2 , events ) <EOL> read_events ( fname2 ) <EOL> assert_naming ( w , '<STR_LIT>' , <NUM_LIT:2> ) <EOL> def test_find_events ( ) : <EOL> """<STR_LIT>""" <EOL> events = read_events ( fname ) <EOL> raw = io . read_raw_fif ( raw_fname , preload = True ) <EOL> extra_ends = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> orig_envs = [ os . getenv ( '<STR_LIT>' % s ) for s in extra_ends ] <EOL> os . environ [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> if '<STR_LIT>' in os . environ : <EOL> del os . environ [ '<STR_LIT>' ] <EOL> events2 = find_events ( raw ) <EOL> assert_array_almost_equal ( events , events2 ) <EOL> events11 = find_events ( raw , mask = <NUM_LIT:3> ) <EOL> events22 = read_events ( fname , mask = <NUM_LIT:3> ) <EOL> assert_array_equal ( events11 , events22 ) <EOL> raw . _first_samps [ <NUM_LIT:0> ] = <NUM_LIT:0> <EOL> raw . info [ '<STR_LIT>' ] = <NUM_LIT:1000> <EOL> raw . _update_times ( ) <EOL> stim_channel = '<STR_LIT>' <EOL> stim_channel_idx = pick_channels ( raw . info [ '<STR_LIT>' ] , <EOL> include = [ stim_channel ] ) <EOL> raw . _data [ stim_channel_idx , : <NUM_LIT:5> ] = np . arange ( <NUM_LIT:5> ) <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:5> : ] = <NUM_LIT:0> <EOL> assert_raises ( TypeError , find_events , raw , mask = "<STR_LIT:0>" ) <EOL> assert_array_equal ( find_events ( raw , shortest_event = <NUM_LIT:1> , mask = <NUM_LIT:1> ) , <EOL> [ [ <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:2> ] , [ <NUM_LIT:4> , <NUM_LIT:2> , <NUM_LIT:4> ] ] ) <EOL> assert_array_equal ( find_events ( raw , shortest_event = <NUM_LIT:1> , mask = <NUM_LIT:2> ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:4> , <NUM_LIT:1> , <NUM_LIT:4> ] ] ) <EOL> assert_array_equal ( find_events ( raw , shortest_event = <NUM_LIT:1> , mask = <NUM_LIT:3> ) , <EOL> [ [ <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:4> ] ] ) <EOL> assert_array_equal ( find_events ( raw , shortest_event = <NUM_LIT:1> , mask = <NUM_LIT:4> ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:2> , <NUM_LIT:3> ] ] ) <EOL> raw . _data [ stim_channel_idx , : ] = <NUM_LIT:0> <EOL> assert_array_equal ( find_events ( raw ) , np . empty ( ( <NUM_LIT:0> , <NUM_LIT:3> ) , dtype = '<STR_LIT>' ) ) <EOL> raw . _data [ stim_channel_idx , : <NUM_LIT:4> ] = <NUM_LIT:1> <EOL> assert_array_equal ( find_events ( raw ) , np . empty ( ( <NUM_LIT:0> , <NUM_LIT:3> ) , dtype = '<STR_LIT>' ) ) <EOL> raw . _data [ stim_channel_idx , - <NUM_LIT:1> : ] = <NUM_LIT:9> <EOL> assert_array_equal ( find_events ( raw ) , [ [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:10> : <NUM_LIT:20> ] = <NUM_LIT:5> <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:20> : <NUM_LIT:30> ] = <NUM_LIT:6> <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:30> : <NUM_LIT:32> ] = <NUM_LIT:5> <EOL> raw . _data [ stim_channel_idx , <NUM_LIT> ] = <NUM_LIT:6> <EOL> assert_array_equal ( find_events ( raw , consecutive = False ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> assert_array_equal ( find_events ( raw , consecutive = True ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT:30> , <NUM_LIT:6> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> assert_array_equal ( find_events ( raw ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> assert_array_equal ( find_events ( raw , output = '<STR_LIT>' , consecutive = False ) , <EOL> [ [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> assert_array_equal ( find_events ( raw , output = '<STR_LIT>' , consecutive = True ) , <EOL> [ [ <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> assert_raises ( ValueError , find_events , raw , output = '<STR_LIT>' , <EOL> consecutive = True ) <EOL> assert_array_equal ( find_events ( raw , output = '<STR_LIT>' , consecutive = True , <EOL> shortest_event = <NUM_LIT:1> ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT:30> , <NUM_LIT:6> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:32> , <NUM_LIT:5> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:0> ] ] ) <EOL> assert_array_equal ( find_events ( raw , output = '<STR_LIT>' ) , <EOL> [ [ <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> ] ] ) <EOL> assert_array_equal ( find_events ( raw , consecutive = False , min_duration = <NUM_LIT> ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] ] ) <EOL> assert_array_equal ( find_events ( raw , consecutive = True , min_duration = <NUM_LIT> ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT:30> , <NUM_LIT:6> , <NUM_LIT:5> ] ] ) <EOL> assert_array_equal ( find_events ( raw , output = '<STR_LIT>' , consecutive = False , <EOL> min_duration = <NUM_LIT> ) , <EOL> [ [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:5> ] ] ) <EOL> assert_array_equal ( find_events ( raw , output = '<STR_LIT>' , consecutive = True , <EOL> min_duration = <NUM_LIT> ) , <EOL> [ [ <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:6> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:5> ] ] ) <EOL> assert_array_equal ( find_events ( raw , consecutive = True , min_duration = <NUM_LIT> ) , <EOL> [ [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:6> ] ] ) <EOL> raw . _data [ stim_channel_idx , : ] = <NUM_LIT:0> <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:10> ] = <NUM_LIT:4> <EOL> raw . _data [ stim_channel_idx , <NUM_LIT:11> : <NUM_LIT:20> ] = <NUM_LIT:5> <EOL> assert_array_equal ( find_stim_steps ( raw , pad_start = <NUM_LIT:0> , merge = <NUM_LIT:0> , <EOL> stim_channel = stim_channel ) , <EOL> [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:11> , <NUM_LIT:4> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:0> ] ] ) <EOL> assert_array_equal ( find_stim_steps ( raw , merge = - <NUM_LIT:1> , <EOL> stim_channel = stim_channel ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:0> ] ] ) <EOL> assert_array_equal ( find_stim_steps ( raw , merge = <NUM_LIT:1> , <EOL> stim_channel = stim_channel ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:5> ] , <EOL> [ <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:0> ] ] ) <EOL> for s , o in zip ( extra_ends , orig_envs ) : <EOL> if o is not None : <EOL> os . environ [ '<STR_LIT>' % s ] = o <EOL> def test_pick_events ( ) : <EOL> """<STR_LIT>""" <EOL> events = np . array ( [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:4> ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:0> ] ] ) <EOL> assert_array_equal ( pick_events ( events , include = [ <NUM_LIT:1> , <NUM_LIT:4> ] , exclude = <NUM_LIT:4> ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:4> ] ] ) <EOL> assert_array_equal ( pick_events ( events , exclude = [ <NUM_LIT:0> , <NUM_LIT:2> ] ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:4> ] ] ) <EOL> assert_array_equal ( pick_events ( events , include = [ <NUM_LIT:1> , <NUM_LIT:2> ] , step = True ) , <EOL> [ [ <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:0> ] ] ) <EOL> def test_make_fixed_length_events ( ) : <EOL> """<STR_LIT>""" <EOL> raw = io . read_raw_fif ( raw_fname ) <EOL> events = make_fixed_length_events ( raw , id = <NUM_LIT:1> ) <EOL> assert_true ( events . shape [ <NUM_LIT:1> ] , <NUM_LIT:3> ) <EOL> events_zero = make_fixed_length_events ( raw , <NUM_LIT:1> , first_samp = False ) <EOL> assert_equal ( events_zero [ <NUM_LIT:0> , <NUM_LIT:0> ] , <NUM_LIT:0> ) <EOL> assert_array_equal ( events_zero [ : , <NUM_LIT:0> ] , events [ : , <NUM_LIT:0> ] - raw . first_samp ) <EOL> tmin , tmax = raw . times [ [ <NUM_LIT:0> , - <NUM_LIT:1> ] ] <EOL> duration = tmax - tmin <EOL> events = make_fixed_length_events ( raw , <NUM_LIT:1> , tmin , tmax , duration ) <EOL> assert_equal ( events . shape [ <NUM_LIT:0> ] , <NUM_LIT:1> ) <EOL> assert_raises ( ValueError , make_fixed_length_events , raw , <NUM_LIT:1> , <EOL> tmin , tmax - <NUM_LIT> , duration ) <EOL> def test_define_events ( ) : <EOL> """<STR_LIT>""" <EOL> events = read_events ( fname ) <EOL> raw = io . read_raw_fif ( raw_fname ) <EOL> events_ , _ = define_target_events ( events , <NUM_LIT:5> , <NUM_LIT:32> , raw . info [ '<STR_LIT>' ] , <EOL> <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> n_target = events [ events [ : , <NUM_LIT:2> ] == <NUM_LIT:5> ] . shape [ <NUM_LIT:0> ] <EOL> n_miss = events_ [ events_ [ : , <NUM_LIT:2> ] == <NUM_LIT> ] . shape [ <NUM_LIT:0> ] <EOL> n_target_ = events_ [ events_ [ : , <NUM_LIT:2> ] == <NUM_LIT> ] . shape [ <NUM_LIT:0> ] <EOL> assert_true ( n_target_ == ( n_target - n_miss ) ) <EOL> events = np . array ( [ [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:3> ] , <EOL> [ <NUM_LIT:1000> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:3> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:2> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:1> ] , <EOL> [ <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:2> ] ] ) <EOL> true_lag_nofill = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> true_lag_fill = [ <NUM_LIT> , np . nan , np . nan , <NUM_LIT> , <NUM_LIT> ] <EOL> n , lag_nofill = define_target_events ( events , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) <EOL> n , lag_fill = define_target_events ( events , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> ) <EOL> assert_array_equal ( true_lag_fill , lag_fill ) <EOL> assert_array_equal ( true_lag_nofill , lag_nofill ) <EOL> run_tests_if_main ( ) </s>
