@testing.requires_testing_data
def test_as_meg_type_evoked():
    'Test interpolation of data on to virtual channels.'
    raw = read_raw_fif(raw_fname)
    events = mne.find_events(raw)
    picks = pick_types(raw.info, meg=True, eeg=True, stim=True, ecg=True, eog=True, include=['STI 014'], exclude='bads')
    epochs = mne.Epochs(raw, events, picks=picks)
    evoked = epochs.average()
    with pytest.raises(ValueError, match="Invalid value for the 'ch_type'"):
        evoked.as_type('meg')
    with pytest.raises(ValueError, match="Invalid value for the 'ch_type'"):
        evoked.copy().pick_types(meg='grad').as_type('meg')
    ch_names = evoked.info['ch_names']
    virt_evoked = evoked.copy().pick_channels(ch_names=ch_names[:10:1])
    virt_evoked.info.normalize_proj()
    virt_evoked = virt_evoked.as_type('mag')
    assert all((ch.endswith('_v') for ch in virt_evoked.info['ch_names']))
    evoked_from = evoked.copy().pick_channels(ch_names=ch_names[2:10:3])
    evoked_to = evoked.copy().pick_channels(ch_names=ch_names[0:10:3])
    (info_from, info_to) = (evoked_from.info, evoked_to.info)
    (args1, args2) = (_setup_args(info_from), _setup_args(info_to))
    args1.update(coils2=args2['coils1'])
    args2.update(coils2=args1['coils1'])
    cross_dots1 = _do_cross_dots(**args1)
    cross_dots2 = _do_cross_dots(**args2)
    assert_array_almost_equal(cross_dots1, cross_dots2.T)
    evoked = evoked.pick_channels(ch_names=ch_names[:10]).copy()
    data1 = evoked.pick_types(meg='grad').data.ravel()
    data2 = evoked.as_type('grad').data.ravel()
    assert (np.corrcoef(data1, data2)[(0, 1)] > 0.95)
    virt_epochs = epochs.copy().load_data().pick_channels(ch_names=ch_names[:10:1])
    virt_epochs.info.normalize_proj()
    virt_epochs = virt_epochs.as_type('mag')
    assert all((ch.endswith('_v') for ch in virt_epochs.info['ch_names']))
    assert_allclose(virt_epochs.get_data().mean(0), virt_evoked.data)
Test interpolation of data on to virtual channels.
@testing.requires_testing_data
def test_as_meg_type_evoked():
    
    raw = read_raw_fif(raw_fname)
    events = mne.find_events(raw)
    picks = pick_types(raw.info, meg=True, eeg=True, stim=True, ecg=True, eog=True, include=['STI 014'], exclude='bads')
    epochs = mne.Epochs(raw, events, picks=picks)
    evoked = epochs.average()
    with pytest.raises(ValueError, match="Invalid value for the 'ch_type'"):
        evoked.as_type('meg')
    with pytest.raises(ValueError, match="Invalid value for the 'ch_type'"):
        evoked.copy().pick_types(meg='grad').as_type('meg')
    ch_names = evoked.info['ch_names']
    virt_evoked = evoked.copy().pick_channels(ch_names=ch_names[:10:1])
    virt_evoked.info.normalize_proj()
    virt_evoked = virt_evoked.as_type('mag')
    assert all((ch.endswith('_v') for ch in virt_evoked.info['ch_names']))
    evoked_from = evoked.copy().pick_channels(ch_names=ch_names[2:10:3])
    evoked_to = evoked.copy().pick_channels(ch_names=ch_names[0:10:3])
    (info_from, info_to) = (evoked_from.info, evoked_to.info)
    (args1, args2) = (_setup_args(info_from), _setup_args(info_to))
    args1.update(coils2=args2['coils1'])
    args2.update(coils2=args1['coils1'])
    cross_dots1 = _do_cross_dots(**args1)
    cross_dots2 = _do_cross_dots(**args2)
    assert_array_almost_equal(cross_dots1, cross_dots2.T)
    evoked = evoked.pick_channels(ch_names=ch_names[:10]).copy()
    data1 = evoked.pick_types(meg='grad').data.ravel()
    data2 = evoked.as_type('grad').data.ravel()
    assert (np.corrcoef(data1, data2)[(0, 1)] > 0.95)
    virt_epochs = epochs.copy().load_data().pick_channels(ch_names=ch_names[:10:1])
    virt_epochs.info.normalize_proj()
    virt_epochs = virt_epochs.as_type('mag')
    assert all((ch.endswith('_v') for ch in virt_epochs.info['ch_names']))
    assert_allclose(virt_epochs.get_data().mean(0), virt_evoked.data)