def test_evoked_arithmetic():
    'Test evoked arithmetic\n    '
    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 = (ev1 + ev2)
    assert_equal(ev.nave, (ev1.nave + ev2.nave))
    assert_allclose(ev.data, ((1.0 / 3.0) * np.ones_like(ev.data)))
    ev = (ev1 - ev2)
    assert_equal(ev.nave, (ev1.nave + ev2.nave))
    assert_equal(ev.comment, ((ev1.comment + ' - ') + ev2.comment))
    assert_allclose(ev.data, np.ones_like(ev1.data))
    old_comment1 = ev1.comment
    old_comment2 = ev2.comment
    ev1.comment = None
    with warnings.catch_warnings(record=True):
        warnings.simplefilter('always')
        ev = (ev1 - ev2)
        assert_equal(ev.comment, 'unknown')
    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)
Test evoked arithmetic
def test_evoked_arithmetic():
    '\n    '
    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 = (ev1 + ev2)
    assert_equal(ev.nave, (ev1.nave + ev2.nave))
    assert_allclose(ev.data, ((1.0 / 3.0) * np.ones_like(ev.data)))
    ev = (ev1 - ev2)
    assert_equal(ev.nave, (ev1.nave + ev2.nave))
    assert_equal(ev.comment, ((ev1.comment + ' - ') + ev2.comment))
    assert_allclose(ev.data, np.ones_like(ev1.data))
    old_comment1 = ev1.comment
    old_comment2 = ev2.comment
    ev1.comment = None
    with warnings.catch_warnings(record=True):
        warnings.simplefilter('always')
        ev = (ev1 - ev2)
        assert_equal(ev.comment, 'unknown')
    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)