def _test_reference(raw, reref, ref_data, ref_from):
 picks_eeg = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
 picks_other = pick_types(raw.info, meg=True, eeg=False, eog=True, stim=True, exclude='bads')
 picks_ref = [raw.ch_names.index(ch) for ch in ref_from]
 if isinstance(raw, Evoked):
  _data = raw.data
  _reref = reref.data
 else:
  _data = raw._data
  _reref = reref._data
 assert_array_equal(ref_data, _data[..., picks_ref, :].mean((-2)))
 raw_eeg_data = _data[..., picks_eeg, :]
 raw_other_data = _data[..., picks_other, :]
 reref_eeg_data = _reref[..., picks_eeg, :]
 reref_other_data = _reref[..., picks_other, :]
 if isinstance(raw, BaseEpochs):
  unref_eeg_data = (reref_eeg_data + ref_data[:, np.newaxis, :])
 else:
  unref_eeg_data = (reref_eeg_data + ref_data)
 assert_allclose(raw_eeg_data, unref_eeg_data, 1e-06, atol=1e-15)
 assert_allclose(raw_other_data, reref_other_data, 1e-06, atol=1e-15)

def _test_reference ( raw , reref , ref_data , ref_from ) : picks_eeg = pick_types ( raw . info , meg = False , eeg = True , exclude = 'bads' ) picks_other = pick_types ( raw . info , meg = True , eeg = False , eog = True , stim = True , exclude = 'bads' ) picks_ref = [ raw . ch_names . index ( ch ) for ch in ref_from ] if isinstance ( raw , Evoked ) : _data = raw . data _reref = reref . data else : _data = raw . _data _reref = reref . _data assert_array_equal ( ref_data , _data [ ... , picks_ref , : ] . mean ( ( - 2 ) ) ) raw_eeg_data = _data [ ... , picks_eeg , : ] raw_other_data = _data [ ... , picks_other , : ] reref_eeg_data = _reref [ ... , picks_eeg , : ] reref_other_data = _reref [ ... , picks_other , : ] if isinstance ( raw , BaseEpochs ) : unref_eeg_data = ( reref_eeg_data + ref_data [ : , np . newaxis , : ] ) else : unref_eeg_data = ( reref_eeg_data + ref_data ) assert_allclose ( raw_eeg_data , unref_eeg_data , 1e-06 , atol = 1e-15 ) assert_allclose ( raw_other_data , reref_other_data , 1e-06 , atol = 1e-15 )
test whether a reference has been correctly applied .