<s> import numpy as np <EOL> import numpy . testing as npt <EOL> import nitime . timeseries as ts <EOL> import nose . tools as nt <EOL> def test_get_time_unit ( ) : <EOL> number = <NUM_LIT:4> <EOL> npt . assert_equal ( ts . get_time_unit ( number ) , None ) <EOL> list_of_numbers = [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> npt . assert_equal ( ts . get_time_unit ( list_of_numbers ) , None ) <EOL> for tu in [ '<STR_LIT>' , '<STR_LIT:s>' , '<STR_LIT:D>' ] : <EOL> time_point = ts . TimeArray ( [ <NUM_LIT:4> ] , time_unit = tu ) <EOL> npt . assert_equal ( ts . get_time_unit ( time_point ) , tu ) <EOL> list_of_time = [ ts . TimeArray ( <NUM_LIT:4> , time_unit = tu ) , ts . TimeArray ( <NUM_LIT:5> , time_unit = tu ) ] <EOL> npt . assert_equal ( ts . get_time_unit ( list_of_time ) , tu ) <EOL> list_of_lists = [ [ ts . TimeArray ( <NUM_LIT:4> , time_unit = tu ) , <EOL> ts . TimeArray ( <NUM_LIT:5> , time_unit = tu ) ] , <EOL> [ ts . TimeArray ( <NUM_LIT:4> , time_unit = tu ) , <EOL> ts . TimeArray ( <NUM_LIT:5> , time_unit = tu ) ] ] <EOL> npt . assert_equal ( ts . get_time_unit ( list_of_lists ) , tu ) <EOL> time_arr = ts . TimeArray ( [ <NUM_LIT:4> , <NUM_LIT:5> ] , time_unit = tu ) <EOL> npt . assert_equal ( ts . get_time_unit ( time_arr ) , tu ) <EOL> def test_TimeArray ( ) : <EOL> time1 = ts . TimeArray ( list ( range ( <NUM_LIT:100> ) ) , time_unit = '<STR_LIT>' ) <EOL> time2 = time1 + time1 <EOL> npt . assert_equal ( time2 . time_unit , '<STR_LIT>' ) <EOL> time1 = ts . TimeArray ( <NUM_LIT:10> ** <NUM_LIT:6> ) <EOL> npt . assert_equal ( time1 . __repr__ ( ) , '<STR_LIT>' ) <EOL> nt . assert_raises ( ValueError , ts . TimeArray , np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> dt = ts . TimeArray ( <NUM_LIT> , time_unit = '<STR_LIT:s>' ) <EOL> tt = ts . TimeArray ( [ dt ] ) <EOL> npt . assert_equal ( dt , tt ) <EOL> t1 = ts . TimeArray ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> t2 = ts . TimeArray ( [ ts . TimeArray ( <NUM_LIT:0> ) , <EOL> ts . TimeArray ( <NUM_LIT:1> ) , <EOL> ts . TimeArray ( <NUM_LIT:2> ) , <EOL> ts . TimeArray ( <NUM_LIT:3> ) ] ) <EOL> npt . assert_equal ( t1 , t2 ) <EOL> def test_TimeArray_math ( ) : <EOL> "<STR_LIT>" <EOL> time1 = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) , time_unit = '<STR_LIT>' ) <EOL> time2 = ts . TimeArray ( list ( range ( <NUM_LIT:1> , <NUM_LIT:11> ) ) , time_unit = '<STR_LIT>' ) <EOL> time3 = time1 + <NUM_LIT:1> <EOL> npt . assert_equal ( time2 , time3 ) <EOL> time4 = time2 - <NUM_LIT:1> <EOL> npt . assert_equal ( time1 , time4 ) <EOL> time3 = time1 + <NUM_LIT:1.0> <EOL> npt . assert_equal ( time2 , time3 ) <EOL> time4 = time2 - <NUM_LIT:1.0> <EOL> npt . assert_equal ( time1 , time4 ) <EOL> time3 = <NUM_LIT:1> + time1 <EOL> npt . assert_equal ( time2 , time3 ) <EOL> time4 = <NUM_LIT:1> - time2 <EOL> npt . assert_equal ( - time1 , time4 ) <EOL> time3 = <NUM_LIT:1.0> + time1 <EOL> npt . assert_equal ( time2 , time3 ) <EOL> time4 = <NUM_LIT:1.0> - time2 <EOL> npt . assert_equal ( - time1 , time4 ) <EOL> timeunits = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) , time_unit = '<STR_LIT:s>' ) <EOL> timeunits . convert_unit ( '<STR_LIT>' ) <EOL> tnew = timeunits + list ( range ( <NUM_LIT:10> ) ) <EOL> npt . assert_equal ( tnew , timeunits + time1 ) <EOL> def test_TimeArray_comparison ( ) : <EOL> "<STR_LIT>" <EOL> time = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) , time_unit = '<STR_LIT>' ) <EOL> npt . assert_equal ( time < <NUM_LIT:5> , [ True ] * <NUM_LIT:5> + [ False ] * <NUM_LIT:5> ) <EOL> npt . assert_equal ( time > <NUM_LIT:5> , [ False ] * <NUM_LIT:6> + [ True ] * <NUM_LIT:4> ) <EOL> npt . assert_equal ( time <= <NUM_LIT:5> , [ True ] * <NUM_LIT:6> + [ False ] * <NUM_LIT:4> ) <EOL> npt . assert_equal ( time >= <NUM_LIT:5> , [ False ] * <NUM_LIT:5> + [ True ] * <NUM_LIT:5> ) <EOL> npt . assert_equal ( time == <NUM_LIT:5> , [ False ] * <NUM_LIT:5> + [ True ] + [ False ] * <NUM_LIT:4> ) <EOL> time . convert_unit ( '<STR_LIT:s>' ) <EOL> npt . assert_equal ( time < <NUM_LIT:5> , [ True ] * <NUM_LIT:10> ) <EOL> npt . assert_equal ( time > <NUM_LIT:5> , [ False ] * <NUM_LIT:10> ) <EOL> npt . assert_equal ( time <= <NUM_LIT:5> , [ True ] * <NUM_LIT:10> ) <EOL> npt . assert_equal ( time >= <NUM_LIT:5> , [ False ] * <NUM_LIT:10> ) <EOL> npt . assert_equal ( time == <NUM_LIT:5> , [ False ] * <NUM_LIT:10> ) <EOL> def test_TimeArray_init_int64 ( ) : <EOL> """<STR_LIT>""" <EOL> time = ts . TimeArray ( np . int64 ( <NUM_LIT:1> ) ) <EOL> npt . assert_equal ( time . __repr__ ( ) , '<STR_LIT>' ) <EOL> pass <EOL> def test_TimeArray_init_list ( ) : <EOL> """<STR_LIT>""" <EOL> for t in [ <NUM_LIT> , ts . TimeArray ( <NUM_LIT> , time_unit = '<STR_LIT:s>' ) ] : <EOL> tl = [ t ] <EOL> ta = ts . TimeArray ( t , time_unit = '<STR_LIT:s>' ) <EOL> tla = ts . TimeArray ( tl , time_unit = '<STR_LIT:s>' ) <EOL> nt . assert_equal ( ta , tla ) <EOL> def test_TimeArray_repr ( ) : <EOL> """<STR_LIT>""" <EOL> def test_TimeArray_copyflag ( ) : <EOL> """<STR_LIT>""" <EOL> t1 = ts . TimeArray ( np . array ( [ <NUM_LIT:1> ] , dtype = np . int64 ) , copy = False ) <EOL> t2 = ts . TimeArray ( <NUM_LIT:1> , time_unit = '<STR_LIT>' ) <EOL> t3 = ts . TimeArray ( t2 , copy = False ) <EOL> npt . assert_equal ( t1 , t2 ) <EOL> npt . assert_equal ( t2 . ctypes . data , t3 . ctypes . data ) <EOL> def test_TimeArray_new ( ) : <EOL> for unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:s>' , None ] : <EOL> for flag , assertion in [ ( True , nt . assert_not_equal ) , <EOL> ( False , nt . assert_equal ) ] : <EOL> time2 = ts . TimeArray ( list ( range ( <NUM_LIT:5> ) ) , time_unit = unit , copy = True ) <EOL> time2f = ts . TimeArray ( np . arange ( <NUM_LIT> ) , time_unit = unit , copy = True ) <EOL> time3 = ts . TimeArray ( time2 , time_unit = unit , copy = flag ) <EOL> time4 = ts . TimeArray ( <NUM_LIT:5> , time_unit = unit , copy = True ) <EOL> time5 = ts . TimeArray ( <NUM_LIT> , time_unit = unit , copy = True ) <EOL> npt . assert_equal ( time2 , time2f ) <EOL> npt . assert_equal ( time2 , time3 ) <EOL> time3 [ <NUM_LIT:0> ] += <NUM_LIT:100> <EOL> assertion ( time2 [ <NUM_LIT:0> ] , time3 [ <NUM_LIT:0> ] ) <EOL> npt . assert_equal ( time2 [ <NUM_LIT:1> : ] , time3 [ <NUM_LIT:1> : ] ) <EOL> npt . assert_equal ( time4 , time5 ) <EOL> def test_TimeArray_bool ( ) : <EOL> time1 = ts . TimeArray ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , time_unit = '<STR_LIT:s>' ) <EOL> time2 = ts . TimeArray ( [ <NUM_LIT:1000> , <NUM_LIT> , <NUM_LIT> ] , time_unit = '<STR_LIT>' ) <EOL> bool_arr = np . ones ( time1 . shape , dtype = bool ) <EOL> npt . assert_equal ( time1 , time2 ) <EOL> npt . assert_equal ( bool_arr , time1 == time2 ) <EOL> nt . assert_not_equal ( type ( time1 == time2 ) , ts . TimeArray ) <EOL> def test_TimeArray_convert_unit ( ) : <EOL> """<STR_LIT>""" <EOL> def test_TimeArray_div ( ) : <EOL> a = <NUM_LIT> <EOL> b = <NUM_LIT> <EOL> time1 = ts . TimeArray ( a , time_unit = '<STR_LIT:s>' ) <EOL> time2 = ts . TimeArray ( b , time_unit = '<STR_LIT:s>' ) <EOL> div1 = a / b <EOL> div2 = time1 / time2 <EOL> npt . assert_equal ( div1 , div2 ) <EOL> a = np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> b = <NUM_LIT> <EOL> time1 = ts . TimeArray ( a , time_unit = '<STR_LIT:s>' ) <EOL> time2 = ts . TimeArray ( b , time_unit = '<STR_LIT:s>' ) <EOL> div1 = a / b <EOL> div2 = time1 / time2 <EOL> npt . assert_equal ( div1 , div2 ) <EOL> a = np . array ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> b = np . array ( [ <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> ] ) . astype ( float ) <EOL> time1 = ts . TimeArray ( a , time_unit = '<STR_LIT:s>' ) <EOL> time2 = ts . TimeArray ( b , time_unit = '<STR_LIT:s>' ) <EOL> div1 = a / b <EOL> div2 = time1 / time2 <EOL> npt . assert_equal ( div1 , div2 ) <EOL> def test_TimeArray_index_at ( ) : <EOL> time1 = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) , time_unit = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:5> ) : <EOL> i_arr = np . array ( i ) <EOL> idx = time1 . index_at ( i ) <EOL> npt . assert_equal ( idx , i_arr ) <EOL> idx_secs = time1 . index_at ( ts . TimeArray ( i / <NUM_LIT> , time_unit = '<STR_LIT:s>' ) ) <EOL> npt . assert_equal ( idx_secs , i_arr ) <EOL> idx = time1 . index_at ( i + <NUM_LIT:0.1> , tol = <NUM_LIT:0.1> ) <EOL> npt . assert_equal ( idx , i_arr ) <EOL> idx = time1 . index_at ( i + <NUM_LIT:0.1> , tol = <NUM_LIT> ) <EOL> npt . assert_equal ( idx , np . array ( [ ] ) ) <EOL> idx = time1 . index_at ( i + <NUM_LIT:0.1> , mode = '<STR_LIT>' ) <EOL> npt . assert_equal ( idx , i_arr ) <EOL> idx = time1 . index_at ( i + <NUM_LIT:0.1> , mode = '<STR_LIT>' ) <EOL> npt . assert_equal ( idx , i_arr + <NUM_LIT:1> ) <EOL> def test_TimeArray_at ( ) : <EOL> time1 = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) , time_unit = '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> this = time1 . at ( i ) <EOL> i_ms = ts . TimeArray ( i / <NUM_LIT> ) <EOL> npt . assert_equal ( this , ts . TimeArray ( i , time_unit = '<STR_LIT>' ) ) <EOL> this_secs = time1 . at ( i_ms ) <EOL> npt . assert_equal ( this_secs , ts . TimeArray ( i , time_unit = '<STR_LIT>' ) ) <EOL> seconds_array = ts . TimeArray ( time1 , time_unit = '<STR_LIT:s>' ) <EOL> this_secs = seconds_array . at ( i / <NUM_LIT> ) <EOL> npt . assert_equal ( this_secs , ts . TimeArray ( i , time_unit = '<STR_LIT>' ) ) <EOL> all = time1 . at ( i_ms , tol = <NUM_LIT:10> ) <EOL> npt . assert_equal ( all , time1 ) <EOL> if i > <NUM_LIT:0> and i < <NUM_LIT:9> : <EOL> this_secs = time1 . at ( i_ms , tol = <NUM_LIT:1> ) <EOL> npt . assert_equal ( this_secs , <EOL> ts . TimeArray ( [ i - <NUM_LIT:1> , i , i + <NUM_LIT:1> ] , time_unit = '<STR_LIT>' ) ) <EOL> def test_TimeArray_at2 ( ) : <EOL> time1 = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) , time_unit = '<STR_LIT>' ) <EOL> for i in [ <NUM_LIT:1> ] : <EOL> i_ms = ts . TimeArray ( i / <NUM_LIT> ) <EOL> this_secs = time1 . at ( i_ms , tol = <NUM_LIT:1> ) <EOL> npt . assert_equal ( this_secs , <EOL> ts . TimeArray ( [ i - <NUM_LIT:1> , i , i + <NUM_LIT:1> ] , time_unit = '<STR_LIT>' ) ) <EOL> def test_UniformTime_index_at ( ) : <EOL> time1 = ts . UniformTime ( t0 = <NUM_LIT:1000> , length = <NUM_LIT:10> , sampling_rate = <NUM_LIT:1000> , time_unit = '<STR_LIT>' ) <EOL> mask = [ False ] * <NUM_LIT:10> <EOL> for i in range ( <NUM_LIT:10> ) : <EOL> idx = time1 . index_at ( ts . TimeArray ( <NUM_LIT:1000> + i , time_unit = '<STR_LIT>' ) ) <EOL> npt . assert_equal ( idx , np . array ( i ) ) <EOL> mask [ i ] = True <EOL> mask_idx = time1 . index_at ( ts . TimeArray ( <NUM_LIT:1000> + i , time_unit = '<STR_LIT>' ) , <EOL> boolean = True ) <EOL> npt . assert_equal ( mask_idx , mask ) <EOL> if i > <NUM_LIT:0> and i < <NUM_LIT:9> : <EOL> mask [ i - <NUM_LIT:1> ] = True <EOL> mask [ i + <NUM_LIT:1> ] = True <EOL> mask_idx = time1 . index_at ( <EOL> ts . TimeArray ( [ <NUM_LIT> + i , <NUM_LIT:1000> + i , <NUM_LIT> + i ] , <EOL> time_unit = '<STR_LIT>' ) , boolean = True ) <EOL> npt . assert_equal ( mask_idx , mask ) <EOL> mask [ i - <NUM_LIT:1> ] = False <EOL> mask [ i + <NUM_LIT:1> ] = False <EOL> mask [ i ] = False <EOL> def test_TimeArray_getset ( ) : <EOL> t1 = ts . TimeSeries ( data = np . random . rand ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ) , sampling_rate = <NUM_LIT:1> ) <EOL> npt . assert_equal ( t1 [ <NUM_LIT:0> ] , t1 . data [ ... , <NUM_LIT:0> ] ) <EOL> def test_UniformTime ( ) : <EOL> tuc = ts . time_unit_conversion <EOL> for unit , duration in zip ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:s>' , None ] , <EOL> [ <NUM_LIT:2> * <NUM_LIT:10> ** <NUM_LIT:9> , <NUM_LIT:2> * <NUM_LIT:10> ** <NUM_LIT:6> , <NUM_LIT:100> , <NUM_LIT:20> ] ) : <EOL> t1 = ts . UniformTime ( duration = duration , sampling_rate = <NUM_LIT:1> , <EOL> time_unit = unit ) <EOL> t2 = ts . UniformTime ( duration = duration , sampling_rate = <NUM_LIT:20> , <EOL> time_unit = unit ) <EOL> a = ts . UniformTime ( duration = <NUM_LIT:10> , sampling_rate = <NUM_LIT:1> ) <EOL> b = ts . UniformTime ( a , time_unit = unit ) <EOL> npt . assert_equal ( a . sampling_interval , b . sampling_interval ) <EOL> npt . assert_equal ( a . sampling_rate , b . sampling_rate ) <EOL> b = ts . UniformTime ( a , duration = <NUM_LIT:2> * duration , time_unit = unit ) <EOL> npt . assert_equal ( a . sampling_interval , b . sampling_interval ) <EOL> npt . assert_equal ( a . sampling_rate , b . sampling_rate ) <EOL> b = ts . UniformTime ( a , length = <NUM_LIT:100> , time_unit = unit ) <EOL> npt . assert_equal ( a . sampling_interval , b . sampling_interval ) <EOL> npt . assert_equal ( a . sampling_rate , b . sampling_rate ) <EOL> b = ts . UniformTime ( a , length = <NUM_LIT:100> , time_unit = unit ) <EOL> npt . assert_equal ( a . sampling_interval , b . sampling_interval ) <EOL> npt . assert_equal ( a . sampling_rate , b . sampling_rate ) <EOL> b = ts . UniformTime ( a , length = <NUM_LIT:100> , duration = duration , time_unit = unit ) <EOL> c = ts . UniformTime ( length = <NUM_LIT:100> , duration = duration , time_unit = unit ) <EOL> npt . assert_equal ( c , b ) <EOL> b = ts . UniformTime ( sampling_interval = <NUM_LIT:1> , duration = <NUM_LIT:10> , time_unit = unit ) <EOL> c = ts . UniformTime ( sampling_rate = tuc [ '<STR_LIT:s>' ] / tuc [ unit ] , <EOL> length = <NUM_LIT:10> , time_unit = unit ) <EOL> npt . assert_equal ( c , b ) <EOL> npt . assert_raises ( ValueError , <EOL> ts . UniformTime , <EOL> dict ( sampling_interval = <NUM_LIT:10> , duration = <NUM_LIT:1> ) ) <EOL> a = ts . UniformTime ( length = <NUM_LIT:1> , sampling_rate = <NUM_LIT:1> ) <EOL> npt . assert_raises ( ValueError , ts . UniformTime , dict ( data = a , <EOL> sampling_rate = <NUM_LIT:10> , sampling_interval = <NUM_LIT> ) ) <EOL> b = ts . UniformTime ( duration = <NUM_LIT:2> * a . sampling_interval , <EOL> sampling_rate = <NUM_LIT:2> * a . sampling_rate ) <EOL> npt . assert_equal ( ts . Frequency ( b . sampling_rate ) , <EOL> ts . Frequency ( <NUM_LIT:2> * a . sampling_rate ) ) <EOL> npt . assert_equal ( b . sampling_interval , <EOL> ts . TimeArray ( <NUM_LIT:0.5> * a . sampling_rate ) ) <EOL> b = ts . UniformTime ( duration = <NUM_LIT:10> , <EOL> sampling_interval = a . sampling_interval ) <EOL> npt . assert_equal ( b . sampling_rate , a . sampling_rate ) <EOL> b = ts . UniformTime ( duration = <NUM_LIT:10> , <EOL> sampling_rate = a . sampling_rate ) <EOL> npt . assert_equal ( b . sampling_interval , a . sampling_interval ) <EOL> a = ts . UniformTime ( length = <NUM_LIT:1> , sampling_rate = <NUM_LIT:1> ) <EOL> b = a . copy ( ) <EOL> npt . assert_equal ( b . duration , a . duration ) <EOL> npt . assert_equal ( b . sampling_rate , a . sampling_rate ) <EOL> npt . assert_equal ( b . sampling_interval , a . sampling_interval ) <EOL> npt . assert_equal ( b . t0 , a . t0 ) <EOL> def test_UniformTime_repr ( ) : <EOL> """<STR_LIT>""" <EOL> def test_Frequency ( ) : <EOL> """<STR_LIT>""" <EOL> tuc = ts . time_unit_conversion <EOL> for unit in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:s>' , None ] : <EOL> f = ts . Frequency ( <NUM_LIT:1> , time_unit = unit ) <EOL> npt . assert_equal ( f . to_period ( ) , tuc [ unit ] ) <EOL> f = ts . Frequency ( <NUM_LIT:1000> , time_unit = unit ) <EOL> npt . assert_equal ( f . to_period ( ) , tuc [ unit ] / <NUM_LIT:1000> ) <EOL> f = ts . Frequency ( <NUM_LIT> , time_unit = unit ) <EOL> npt . assert_equal ( f . to_period ( ) , tuc [ unit ] * <NUM_LIT:1000> ) <EOL> def test_TimeSeries ( ) : <EOL> """<STR_LIT>""" <EOL> tseries1 = ts . TimeSeries ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] , duration = <NUM_LIT:10> ) <EOL> tseries2 = ts . TimeSeries ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] , sampling_interval = <NUM_LIT:1> ) <EOL> npt . assert_equal ( tseries1 . time , tseries2 . time ) <EOL> t1 = ts . UniformTime ( length = <NUM_LIT:8> , sampling_rate = <NUM_LIT:2> ) <EOL> tseries1 = ts . TimeSeries ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , time = t1 , sampling_rate = <NUM_LIT:1> ) <EOL> npt . assert_raises ( ValueError , ts . TimeSeries , dict ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> time = t1 ) ) <EOL> tseries2 = ts . TimeSeries ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , sampling_rate = <NUM_LIT:1> ) <EOL> tseries3 = ts . TimeSeries ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , sampling_rate = <NUM_LIT:1000> , <EOL> time_unit = '<STR_LIT>' ) <EOL> tseries4 = ts . TimeSeries ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , sampling_interval = <NUM_LIT:1> , <EOL> time_unit = '<STR_LIT>' ) <EOL> npt . assert_equal ( tseries4 . time , tseries3 . time ) <EOL> tseries6 = ts . TimeSeries ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> sampling_interval = <NUM_LIT> , <EOL> time_unit = '<STR_LIT:s>' ) <EOL> npt . assert_equal ( tseries6 . time , tseries3 . time ) <EOL> tseries5 = ts . TimeSeries ( data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , <EOL> sampling_interval = ts . TimeArray ( <NUM_LIT> , <EOL> time_unit = '<STR_LIT:s>' ) , <EOL> time_unit = '<STR_LIT>' ) <EOL> npt . assert_equal ( tseries5 . time , tseries3 . time ) <EOL> t = ts . UniformTime ( length = <NUM_LIT:3> , sampling_rate = <NUM_LIT:3> ) <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> tseries7 = ts . TimeSeries ( data = data , time = t ) <EOL> npt . assert_equal ( tseries7 . data , data ) <EOL> data = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] <EOL> npt . assert_raises ( ValueError , <EOL> ts . TimeSeries , dict ( data = data , time = t ) ) <EOL> tseries1 = ts . TimeSeries ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> ] , sampling_rate = <NUM_LIT:1> ) <EOL> tseries2 = tseries1 + <NUM_LIT:1> <EOL> npt . assert_equal ( tseries1 . data + <NUM_LIT:1> , tseries2 . data ) <EOL> npt . assert_equal ( tseries1 . time , tseries2 . time ) <EOL> tseries2 -= <NUM_LIT:1> <EOL> npt . assert_equal ( tseries1 . data , tseries2 . data ) <EOL> npt . assert_equal ( tseries1 . time , tseries2 . time ) <EOL> tseries2 = tseries1 * <NUM_LIT:2> <EOL> npt . assert_equal ( tseries1 . data * <NUM_LIT:2> , tseries2 . data ) <EOL> npt . assert_equal ( tseries1 . time , tseries2 . time ) <EOL> tseries2 = tseries2 / <NUM_LIT:2> <EOL> npt . assert_equal ( tseries1 . data , tseries2 . data ) <EOL> npt . assert_equal ( tseries1 . time , tseries2 . time ) <EOL> tseries_nd1 = ts . TimeSeries ( np . random . randn ( <NUM_LIT:3> , <NUM_LIT:100> ) , sampling_rate = <NUM_LIT:1> ) <EOL> tseries_nd2 = ts . TimeSeries ( np . random . randn ( <NUM_LIT:3> , <NUM_LIT:100> ) , sampling_rate = <NUM_LIT:1> ) <EOL> npt . assert_equal ( ( tseries_nd1 + tseries_nd2 ) . data , <EOL> tseries_nd1 . data + tseries_nd2 . data ) <EOL> npt . assert_equal ( ( tseries_nd1 - tseries_nd2 ) . data , <EOL> tseries_nd1 . data - tseries_nd2 . data ) <EOL> npt . assert_equal ( ( tseries_nd1 * tseries_nd2 ) . data , <EOL> tseries_nd1 . data * tseries_nd2 . data ) <EOL> npt . assert_equal ( ( tseries_nd1 / tseries_nd2 ) . data , <EOL> tseries_nd1 . data / tseries_nd2 . data ) <EOL> def test_TimeSeries_repr ( ) : <EOL> """<STR_LIT>""" <EOL> def test_Epochs ( ) : <EOL> tms = ts . TimeArray ( data = list ( range ( <NUM_LIT:100> ) ) , time_unit = '<STR_LIT>' ) <EOL> tmin = ts . TimeArray ( data = list ( range ( <NUM_LIT:100> ) ) , time_unit = '<STR_LIT:m>' ) <EOL> tsec = ts . TimeArray ( data = list ( range ( <NUM_LIT:100> ) ) , time_unit = '<STR_LIT:s>' ) <EOL> utms = ts . UniformTime ( length = <NUM_LIT:100> , sampling_interval = <NUM_LIT:1> , time_unit = '<STR_LIT>' ) <EOL> utmin = ts . UniformTime ( length = <NUM_LIT:100> , sampling_interval = <NUM_LIT:1> , time_unit = '<STR_LIT:m>' ) <EOL> utsec = ts . UniformTime ( length = <NUM_LIT:100> , sampling_interval = <NUM_LIT:1> , time_unit = '<STR_LIT:s>' ) <EOL> tsms = ts . TimeSeries ( data = list ( range ( <NUM_LIT:100> ) ) , sampling_interval = <NUM_LIT:1> , time_unit = '<STR_LIT>' ) <EOL> tsmin = ts . TimeSeries ( data = list ( range ( <NUM_LIT:100> ) ) , sampling_interval = <NUM_LIT:1> , time_unit = '<STR_LIT:m>' ) <EOL> tssec = ts . TimeSeries ( data = list ( range ( <NUM_LIT:100> ) ) , sampling_interval = <NUM_LIT:1> , time_unit = '<STR_LIT:s>' ) <EOL> e1ms = ts . Epochs ( <NUM_LIT:0> , <NUM_LIT:1> , time_unit = '<STR_LIT>' ) <EOL> e09ms = ts . Epochs ( <NUM_LIT:0.1> , <NUM_LIT:1> , time_unit = '<STR_LIT>' ) <EOL> msg = "<STR_LIT>" <EOL> npt . assert_equal ( e1ms . duration , ts . TimeArray ( <NUM_LIT:1> , time_unit = '<STR_LIT>' ) , msg ) <EOL> e1d = ts . Epochs ( <NUM_LIT:0> , <NUM_LIT:1> , time_unit = '<STR_LIT:D>' ) <EOL> npt . assert_equal ( e1d . duration , ts . TimeArray ( <NUM_LIT:1> , time_unit = '<STR_LIT:D>' ) , msg ) <EOL> e1ms_ar = ts . Epochs ( [ <NUM_LIT:0> , <NUM_LIT:0> ] , [ <NUM_LIT:1> , <NUM_LIT:1> ] , time_unit = '<STR_LIT>' ) <EOL> for t in [ tms , tmin , tsec , utms , utmin , utsec ] : <EOL> npt . assert_equal ( len ( t . during ( e1ms ) ) , <NUM_LIT:1> ) <EOL> npt . assert_equal ( len ( t . during ( e09ms ) ) , <NUM_LIT:0> ) <EOL> npt . assert_equal ( type ( t ) , type ( t . during ( e1ms ) ) ) <EOL> for t in [ tsms , tsmin , tssec ] : <EOL> npt . assert_equal ( len ( t . during ( e1ms ) ) , <NUM_LIT:1> ) <EOL> npt . assert_equal ( type ( t ) , type ( t . during ( e1ms ) ) ) <EOL> e2 = ts . Epochs ( [ <NUM_LIT:0> , <NUM_LIT:10> ] , [ <NUM_LIT:10> , <NUM_LIT:20> ] , time_unit = t . time_unit ) <EOL> npt . assert_equal ( type ( t ) , type ( t . during ( e2 ) ) ) <EOL> npt . assert_equal ( t [ e2 ] . data . shape , ( <NUM_LIT:2> , <NUM_LIT:10> ) ) <EOL> npt . assert_equal ( len ( t . during ( e2 ) ) , <NUM_LIT:10> ) <EOL> npt . assert_equal ( t [ e2 ] . data . ndim , <NUM_LIT:2> ) <EOL> npt . assert_equal ( t [ e2 ] [ <NUM_LIT:0> ] , ( <NUM_LIT:0> , <NUM_LIT:10> ) ) <EOL> npt . assert_equal ( t [ e2 ] [ <NUM_LIT:1> ] , ( <NUM_LIT:1> , <NUM_LIT:11> ) ) <EOL> npt . assert_equal ( t [ e2 ] . data [ <NUM_LIT:0> ] , list ( range ( <NUM_LIT:10> ) ) ) <EOL> npt . assert_equal ( t [ e2 ] . data [ <NUM_LIT:1> ] , list ( range ( <NUM_LIT:10> , <NUM_LIT:20> ) ) ) <EOL> npt . assert_equal ( t [ e2 ] . duration , e2 [ <NUM_LIT:0> ] . duration ) <EOL> ejag = ts . Epochs ( [ <NUM_LIT:0> , <NUM_LIT:10> ] , [ <NUM_LIT:10> , <NUM_LIT> ] , time_unit = t . time_unit ) <EOL> npt . assert_raises ( ValueError , t . __getitem__ , ejag ) <EOL> eshort = ts . Epochs ( <NUM_LIT> , <NUM_LIT> , time_unit = t . time_unit ) <EOL> npt . assert_equal ( len ( t [ eshort ] . data ) , <NUM_LIT:0> ) <EOL> e1ms_outofrange = ts . Epochs ( <NUM_LIT:200> , <NUM_LIT> , time_unit = t . time_unit ) <EOL> npt . assert_raises ( ValueError , t . during , dict ( e = e1ms_outofrange ) ) <EOL> npt . assert_raises ( ValueError , t . during , dict ( e = e1d ) ) <EOL> def test_basic_slicing ( ) : <EOL> t = ts . TimeArray ( list ( range ( <NUM_LIT:4> ) ) ) <EOL> for x in range ( <NUM_LIT:3> ) : <EOL> ep = ts . Epochs ( <NUM_LIT> , x + <NUM_LIT> ) <EOL> npt . assert_equal ( len ( t [ ep ] ) , x ) <EOL> npt . assert_equal ( len ( t [ ts . Epochs ( - <NUM_LIT:1> , <NUM_LIT:3> ) ] ) , len ( t ) - <NUM_LIT:1> ) <EOL> npt . assert_equal ( len ( t [ ts . Epochs ( <NUM_LIT> , <NUM_LIT:5> ) ] ) , len ( t ) - <NUM_LIT:1> ) <EOL> npt . assert_equal ( len ( t [ ts . Epochs ( - <NUM_LIT:1> , <NUM_LIT:100> ) ] ) , len ( t ) ) <EOL> ep = ts . Epochs ( <NUM_LIT:20> , <NUM_LIT:100> ) <EOL> npt . assert_equal ( len ( t [ ep ] ) , <NUM_LIT:0> ) <EOL> def test_Events ( ) : <EOL> nt . assert_raises ( ValueError , ts . Events , np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:2> ) ) ) <EOL> t = ts . TimeArray ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , time_unit = '<STR_LIT>' ) <EOL> x = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> y = [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] <EOL> z = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> i0 = [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> i1 = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> for unit in [ None , '<STR_LIT:s>' , '<STR_LIT>' , '<STR_LIT:D>' ] : <EOL> ev1 = ts . Events ( t , time_unit = unit , i = x , j = y , k = z ) <EOL> ev2 = ts . Events ( t , time_unit = unit , indices = [ i0 , i1 ] ) <EOL> ev3 = ts . Events ( t , time_unit = unit , labels = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> indices = [ i0 , i1 ] ) <EOL> nt . assert_raises ( ValueError , ts . Events , t , time_unit = unit , <EOL> labels = [ '<STR_LIT>' , '<STR_LIT>' ] , indices = [ i0 ] ) <EOL> npt . assert_equal ( ev1 . time , t ) <EOL> npt . assert_equal ( ev2 . time , t ) <EOL> if unit is not None : <EOL> npt . assert_equal ( ev1 . time_unit , unit ) <EOL> npt . assert_equal ( ev2 . time_unit , unit ) <EOL> else : <EOL> npt . assert_equal ( ev1 . time_unit , t . time_unit ) <EOL> npt . assert_equal ( ev2 . time_unit , t . time_unit ) <EOL> npt . assert_equal ( ev1 . data [ '<STR_LIT:i>' ] , x ) <EOL> npt . assert_equal ( ev1 . data [ '<STR_LIT>' ] , y ) <EOL> npt . assert_equal ( ev1 . data [ '<STR_LIT:k>' ] , z ) <EOL> npt . assert_equal ( ev3 . index . trial , i0 ) <EOL> npt . assert_equal ( ev3 . index . other , i1 ) <EOL> npt . assert_equal ( ev2 . index . i0 , i0 ) <EOL> npt . assert_equal ( ev2 . index . i1 , i1 ) <EOL> npt . assert_equal ( ev1 [ <NUM_LIT:0> ] . data [ '<STR_LIT:i>' ] , x [ <NUM_LIT:0> ] ) <EOL> npt . assert_equal ( ev1 [ <NUM_LIT:0> : <NUM_LIT:2> ] . data [ '<STR_LIT:i>' ] , x [ <NUM_LIT:0> : <NUM_LIT:2> ] ) <EOL> npt . assert_equal ( ev1 [ <NUM_LIT:0.> ] . data [ '<STR_LIT:i>' ] , x [ <NUM_LIT:0> ] ) <EOL> ep = ts . Epochs ( start = <NUM_LIT:0> , stop = <NUM_LIT> , time_unit = '<STR_LIT>' ) <EOL> npt . assert_equal ( ev1 [ ep ] . data [ '<STR_LIT:i>' ] , x [ <NUM_LIT:0> ] ) <EOL> npt . assert_equal ( ev1 [ ev3 . index . trial == <NUM_LIT:0> ] . data [ '<STR_LIT>' ] , y [ <NUM_LIT:0> : <NUM_LIT:2> ] ) <EOL> assert len ( t ) == len ( ev1 ) == len ( ev2 ) == len ( ev3 ) <EOL> def test_Events_scalar ( ) : <EOL> t = ts . TimeArray ( <NUM_LIT:1> , time_unit = '<STR_LIT>' ) <EOL> i , j = <NUM_LIT:4> , <NUM_LIT:5> <EOL> ev = ts . Events ( t , i = i , j = j ) <EOL> npt . assert_equal ( ev . data [ '<STR_LIT:i>' ] [ <NUM_LIT:0> ] , i ) <EOL> npt . assert_equal ( ev . data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , j ) <EOL> def test_index_at_20101206 ( ) : <EOL> """<STR_LIT>""" <EOL> A = np . random . standard_normal ( <NUM_LIT> ) <EOL> TS_A = ts . TimeSeries ( A , t0 = - <NUM_LIT:20> , sampling_interval = <NUM_LIT:2> ) <EOL> npt . assert_equal ( TS_A . time . index_at ( TS_A . time ) , np . arange ( <NUM_LIT> ) ) <EOL> TS_A = ts . TimeSeries ( A , t0 = <NUM_LIT:15> , sampling_interval = <NUM_LIT:2> ) <EOL> npt . assert_equal ( TS_A . time . index_at ( TS_A . time ) , np . arange ( <NUM_LIT> ) ) <EOL> TS_A = ts . TimeSeries ( A , sampling_interval = <NUM_LIT:2> ) <EOL> npt . assert_equal ( TS_A . time . index_at ( TS_A . time ) , np . arange ( <NUM_LIT> ) ) <EOL> def test_masked_array_timeseries ( ) : <EOL> masked = np . ma . masked_invalid ( [ <NUM_LIT:0> , np . nan , <NUM_LIT:2> ] ) <EOL> t = ts . TimeSeries ( masked , sampling_interval = <NUM_LIT:1> ) <EOL> npt . assert_equal ( t . data . mask , [ False , True , False ] ) <EOL> notmasked = np . array ( [ <NUM_LIT:0> , np . nan , <NUM_LIT:2> ] ) <EOL> t2 = ts . TimeSeries ( notmasked , sampling_interval = <NUM_LIT:1> ) <EOL> npt . assert_raises ( AttributeError , t2 . data . __getattribute__ , '<STR_LIT>' ) <EOL> def test_masked_array_events ( ) : <EOL> masked = np . ma . masked_invalid ( [ <NUM_LIT:0> , np . nan , <NUM_LIT:2> ] ) <EOL> e = ts . Events ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , d = masked ) <EOL> npt . assert_equal ( e . data [ '<STR_LIT:d>' ] . mask , [ False , True , False ] ) <EOL> notmasked = np . array ( [ <NUM_LIT:0> , np . nan , <NUM_LIT:2> ] ) <EOL> e2 = ts . Events ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , d = notmasked ) <EOL> npt . assert_raises ( AttributeError , e2 . data [ '<STR_LIT:d>' ] . __getattribute__ , '<STR_LIT>' ) <EOL> def test_event_subclass_slicing ( ) : <EOL> "<STR_LIT>" <EOL> class Events_with_X ( ts . Events ) : <EOL> "<STR_LIT>" <EOL> def __getattr__ ( self , k ) : <EOL> return self . data [ k ] <EOL> pass <EOL> time = np . linspace ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:11> ) <EOL> x , y = np . sin ( time ) , np . cos ( time ) <EOL> e = Events_with_X ( time , ** dict ( x = x , y = y ) ) <EOL> npt . assert_equal ( e . x , e . data [ '<STR_LIT:x>' ] ) <EOL> npt . assert_equal ( e . y , e . data [ '<STR_LIT:y>' ] ) <EOL> slice_of_e = e [ : <NUM_LIT:4> ] <EOL> slice_of_e . x <EOL> slice_of_e . y <EOL> npt . assert_equal ( slice_of_e . x , x [ : <NUM_LIT:4> ] ) <EOL> npt . assert_equal ( slice_of_e . y , y [ : <NUM_LIT:4> ] ) <EOL> assert ( slice_of_e . __class__ == Events_with_X ) <EOL> def test_epochs_subclass_slicing ( ) : <EOL> "<STR_LIT>" <EOL> class Epochs_with_X ( ts . Epochs ) : <EOL> "<STR_LIT>" <EOL> def total_duration ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self . stop - self . start ) . sum ( ) <EOL> time_0 = list ( range ( <NUM_LIT:10> ) ) <EOL> e = Epochs_with_X ( time_0 , duration = <NUM_LIT> ) <EOL> npt . assert_equal ( e . total_duration ( ) , ts . TimeArray ( <NUM_LIT> ) ) <EOL> slice_of_e = e [ : <NUM_LIT:5> ] <EOL> npt . assert_equal ( slice_of_e . total_duration ( ) , ts . TimeArray ( <NUM_LIT:1.0> ) ) <EOL> assert ( slice_of_e . __class__ == Epochs_with_X ) <EOL> def test_Epochs_duration_after_slicing ( ) : <EOL> "<STR_LIT>" <EOL> e = ts . Epochs ( list ( range ( <NUM_LIT:10> ) ) , duration = <NUM_LIT> ) <EOL> npt . assert_equal ( len ( e . duration ) , len ( e ) ) <EOL> slice_of_e = e [ : <NUM_LIT:3> ] <EOL> npt . assert_equal ( len ( slice_of_e . duration ) , len ( slice_of_e ) ) <EOL> def test_UniformTime_preserves_uniformity ( ) : <EOL> "<STR_LIT>" <EOL> utime = ts . UniformTime ( t0 = <NUM_LIT:0> , length = <NUM_LIT:10> , sampling_rate = <NUM_LIT:1> ) <EOL> def assign_to_one_element_of ( t ) : t [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> nt . assert_raises ( ValueError , assign_to_one_element_of , utime ) <EOL> utime10 = ts . UniformTime ( t0 = <NUM_LIT:10> , length = <NUM_LIT:10> , sampling_rate = <NUM_LIT:1> ) <EOL> utime += <NUM_LIT:10> <EOL> npt . assert_equal ( utime , utime10 ) <EOL> utime_2 = ts . UniformTime ( t0 = <NUM_LIT:10> , length = <NUM_LIT:10> , sampling_interval = <NUM_LIT:2> ) <EOL> utime += np . arange ( <NUM_LIT:10> ) <EOL> npt . assert_equal ( utime , utime_2 ) <EOL> npt . assert_equal ( utime . sampling_interval , utime_2 . sampling_interval ) <EOL> utime = ts . UniformTime ( t0 = <NUM_LIT:5> , length = <NUM_LIT:10> , sampling_rate = <NUM_LIT:1> ) <EOL> utime *= <NUM_LIT:2> <EOL> npt . assert_equal ( utime . sampling_interval , utime_2 . sampling_interval ) <EOL> npt . assert_equal ( utime . sampling_rate , utime_2 . sampling_rate ) <EOL> nonuniform = np . concatenate ( ( list ( range ( <NUM_LIT:2> ) ) , list ( range ( <NUM_LIT:3> ) ) , list ( range ( <NUM_LIT:5> ) ) ) ) <EOL> def iadd_nonuniform ( t ) : t += nonuniform <EOL> nt . assert_raises ( ValueError , iadd_nonuniform , utime ) <EOL> def test_index_int64 ( ) : <EOL> "<STR_LIT>" <EOL> a = list ( range ( <NUM_LIT:10> ) ) <EOL> b = ts . TimeArray ( a ) <EOL> assert b [ <NUM_LIT:0> ] == b [ np . int64 ( <NUM_LIT:0> ) ] <EOL> assert repr ( b [ <NUM_LIT:0> ] ) == repr ( b [ np . int64 ( <NUM_LIT:0> ) ] ) <EOL> assert b [ <NUM_LIT:0> ] == b [ np . int32 ( <NUM_LIT:0> ) ] <EOL> assert repr ( b [ <NUM_LIT:0> ] ) == repr ( b [ np . int32 ( <NUM_LIT:0> ) ] ) <EOL> def test_timearray_math_functions ( ) : <EOL> "<STR_LIT>" <EOL> a = np . arange ( <NUM_LIT:2> , <NUM_LIT:11> ) <EOL> for f in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> for tu in [ '<STR_LIT:s>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:D>' ] : <EOL> b = ts . TimeArray ( a , time_unit = tu ) <EOL> npt . assert_ ( getattr ( b , f ) ( ) . __class__ == ts . TimeArray ) <EOL> npt . assert_ ( getattr ( b , f ) ( ) . time_unit == b . time_unit ) <EOL> npt . assert_ ( getattr ( b , f ) ( ) == getattr ( a , f ) ( ) ) <EOL> def test_timearray_var_prod ( ) : <EOL> """<STR_LIT>""" <EOL> a = ts . TimeArray ( list ( range ( <NUM_LIT:10> ) ) ) <EOL> npt . assert_raises ( NotImplementedError , a . var ) <EOL> npt . assert_raises ( NotImplementedError , a . prod ) </s>
