def _as_meg_type_evoked(evoked, ch_type='grad', mode='fast'):
    evoked = evoked.copy()

    if ch_type not in ['mag', 'grad']:
        raise ValueError('to_type must be "mag" or "grad", not "%s"'
                         % ch_type)
    # pick the original and destination channels
    pick_from = pick_types(evoked.info, meg=True, eeg=False,
                           ref_meg=False)
    pick_to = pick_types(evoked.info, meg=ch_type, eeg=False,
                         ref_meg=False)

    if len(pick_to) == 0:
        raise ValueError('No channels matching the destination channel type'
                         ' found in info. Please pass an evoked containing'
                         'both the original and destination channels. Only the'
                         ' locations of the destination channels will be used'
                         ' for interpolation.')

    info_from = pick_info(evoked.info, pick_from)
    info_to = pick_info(evoked.info, pick_to)
    mapping = _map_meg_channels(info_from, info_to, mode=mode)

    # compute evoked data by multiplying by the 'gain matrix' from
    # original sensors to virtual sensors
    data = np.dot(mapping, evoked.data[pick_from])

    # keep only the destination channel types
    evoked.pick_types(meg=ch_type, eeg=False, ref_meg=False)
    evoked.data = data

    # change channel names to emphasize they contain interpolated data
    for ch in evoked.info['chs']:
        ch['ch_name'] += '_virtual'
    evoked.info._update_redundant()
    evoked.info._check_consistency()
    return evoked
Compute virtual evoked using interpolated fields in mag/grad channels.
dataset/ETHPy150Open mne-tools/mne-python/mne/forward/_field_interpolation.py/_as_meg_type_evoked