def test_arithmetic():
 ev = read_evokeds(fname, condition=0)
 ev1 = EvokedArray(np.ones_like(ev.data), ev.info, ev.times[0], nave=20)
 ev2 = EvokedArray((- np.ones_like(ev.data)), ev.info, ev.times[0], nave=10)
 ev = combine_evoked([ev1, ev2], weights='nave')
 assert_equal(ev.nave, (ev1.nave + ev2.nave))
 assert_allclose(ev.data, ((1.0 / 3.0) * np.ones_like(ev.data)))
 for weights in ('nave', 'equal', [0.5, 0.5]):
  ev = combine_evoked([ev1, ev1], weights=weights)
  assert_allclose(ev.data, ev1.data)
  assert_equal(ev.nave, (2 * ev1.nave))
  ev = combine_evoked([ev1, (- ev1)], weights=weights)
  assert_allclose(ev.data, 0.0, atol=1e-20)
  assert_equal(ev.nave, (2 * ev1.nave))
 ev = combine_evoked([ev1, (- ev1)], weights='equal')
 assert_allclose(ev.data, 0.0, atol=1e-20)
 assert_equal(ev.nave, (2 * ev1.nave))
 ev = combine_evoked([ev1, (- ev2)], weights='equal')
 expected = int(round((1.0 / ((0.25 / ev1.nave) + (0.25 / ev2.nave)))))
 assert_equal(expected, 27)
 assert_equal(ev.nave, expected)
 old_comment1 = ev1.comment
 old_comment2 = ev2.comment
 ev1.comment = None
 ev = combine_evoked([ev1, (- ev2)], weights=[1, (-1)])
 assert_equal(ev.comment.count('unknown'), 2)
 assert_true(('-unknown' in ev.comment))
 assert_true((' + ' in ev.comment))
 ev1.comment = old_comment1
 ev2.comment = old_comment2
 ev = combine_evoked([ev1, ev2], weights='equal')
 assert_allclose(ev.data, np.zeros_like(ev1.data))
 ev = combine_evoked([ev1, ev2], weights=[1, 0])
 assert_equal(ev.nave, ev1.nave)
 assert_allclose(ev.data, ev1.data)
 ev = combine_evoked([ev1, ev2], weights=[1, (-1)])
 assert_allclose(ev.data, (2 * np.ones_like(ev1.data)))
 assert_raises(ValueError, combine_evoked, [ev1, ev2], weights='foo')
 assert_raises(ValueError, combine_evoked, [ev1, ev2], weights=[1])
 (evoked1, evoked2) = read_evokeds(fname, condition=[0, 1], proj=True)
 ch_names = evoked1.ch_names[2:]
 evoked1.info['bads'] = ['EEG 008']
 evoked1.drop_channels(evoked1.ch_names[:1])
 evoked2.drop_channels(evoked2.ch_names[1:2])
 gave = grand_average([evoked1, evoked2])
 assert_equal(gave.data.shape, [len(ch_names), evoked1.data.shape[1]])
 assert_equal(ch_names, gave.ch_names)
 assert_equal(gave.nave, 2)
 assert_raises(ValueError, grand_average, [1, evoked1])

def test_arithmetic ( ) : ev = read_evokeds ( fname , condition = 0 ) ev1 = EvokedArray ( np . ones_like ( ev . data ) , ev . info , ev . times [ 0 ] , nave = 20 ) ev2 = EvokedArray ( ( - np . ones_like ( ev . data ) ) , ev . info , ev . times [ 0 ] , nave = 10 ) ev = combine_evoked ( [ ev1 , ev2 ] , weights = 'nave' ) assert_equal ( ev . nave , ( ev1 . nave + ev2 . nave ) ) assert_allclose ( ev . data , ( ( 1.0 / 3.0 ) * np . ones_like ( ev . data ) ) ) for weights in ( 'nave' , 'equal' , [ 0.5 , 0.5 ] ) : ev = combine_evoked ( [ ev1 , ev1 ] , weights = weights ) assert_allclose ( ev . data , ev1 . data ) assert_equal ( ev . nave , ( 2 * ev1 . nave ) ) ev = combine_evoked ( [ ev1 , ( - ev1 ) ] , weights = weights ) assert_allclose ( ev . data , 0.0 , atol = 1e-20 ) assert_equal ( ev . nave , ( 2 * ev1 . nave ) ) ev = combine_evoked ( [ ev1 , ( - ev1 ) ] , weights = 'equal' ) assert_allclose ( ev . data , 0.0 , atol = 1e-20 ) assert_equal ( ev . nave , ( 2 * ev1 . nave ) ) ev = combine_evoked ( [ ev1 , ( - ev2 ) ] , weights = 'equal' ) expected = int ( round ( ( 1.0 / ( ( 0.25 / ev1 . nave ) + ( 0.25 / ev2 . nave ) ) ) ) ) assert_equal ( expected , 27 ) assert_equal ( ev . nave , expected ) old_comment1 = ev1 . comment old_comment2 = ev2 . comment ev1 . comment = None ev = combine_evoked ( [ ev1 , ( - ev2 ) ] , weights = [ 1 , ( - 1 ) ] ) assert_equal ( ev . comment . count ( 'unknown' ) , 2 ) assert_true ( ( '-unknown' in ev . comment ) ) assert_true ( ( ' + ' in ev . comment ) ) ev1 . comment = old_comment1 ev2 . comment = old_comment2 ev = combine_evoked ( [ ev1 , ev2 ] , weights = 'equal' ) assert_allclose ( ev . data , np . zeros_like ( ev1 . data ) ) ev = combine_evoked ( [ ev1 , ev2 ] , weights = [ 1 , 0 ] ) assert_equal ( ev . nave , ev1 . nave ) assert_allclose ( ev . data , ev1 . data ) ev = combine_evoked ( [ ev1 , ev2 ] , weights = [ 1 , ( - 1 ) ] ) assert_allclose ( ev . data , ( 2 * np . ones_like ( ev1 . data ) ) ) assert_raises ( ValueError , combine_evoked , [ ev1 , ev2 ] , weights = 'foo' ) assert_raises ( ValueError , combine_evoked , [ ev1 , ev2 ] , weights = [ 1 ] ) ( evoked1 , evoked2 ) = read_evokeds ( fname , condition = [ 0 , 1 ] , proj = True ) ch_names = evoked1 . ch_names [ 2 : ] evoked1 . info [ 'bads' ] = [ 'EEG 008' ] evoked1 . drop_channels ( evoked1 . ch_names [ : 1 ] ) evoked2 . drop_channels ( evoked2 . ch_names [ 1 : 2 ] ) gave = grand_average ( [ evoked1 , evoked2 ] ) assert_equal ( gave . data . shape , [ len ( ch_names ) , evoked1 . data . shape [ 1 ] ] ) assert_equal ( ch_names , gave . ch_names ) assert_equal ( gave . nave , 2 ) assert_raises ( ValueError , grand_average , [ 1 , evoked1 ] )
test general arithmetic operations .