

def _interpolate_bads_eeg(inst):
    'Interpolate bad EEG channels\n\n    Operates in place.\n\n    Parameters\n    ----------\n    inst : mne.io.Raw, mne.Epochs or mne.Evoked\n        The data to interpolate. Must be preloaded.\n    '
    bads_idx = np.zeros(len(inst.ch_names), dtype=np.bool)
    goods_idx = np.zeros(len(inst.ch_names), dtype=np.bool)
    picks = pick_types(inst.info, meg=False, eeg=True, exclude=[])
    inst.info._check_consistency()
    bads_idx[picks] = [(inst.ch_names[ch] in inst.info['bads']) for ch in picks]
    if ((len(picks) == 0) or (len(bads_idx) == 0)):
        return
    goods_idx[picks] = True
    goods_idx[bads_idx] = False
    pos = inst._get_channel_positions(picks)
    bads_idx_pos = bads_idx[picks]
    goods_idx_pos = goods_idx[picks]
    pos_good = pos[goods_idx_pos]
    pos_bad = pos[bads_idx_pos]
    (radius, center) = _fit_sphere(pos_good)
    distance = np.sqrt(np.sum(((pos_good - center) ** 2), 1))
    distance = np.mean((distance / radius))
    if (np.abs((1.0 - distance)) > 0.1):
        warn('Your spherical fit is poor, interpolation results are likely to be inaccurate.')
    logger.info('Computing interpolation matrix from {0} sensor positions'.format(len(pos_good)))
    interpolation = _make_interpolation_matrix(pos_good, pos_bad)
    logger.info('Interpolating {0} sensors'.format(len(pos_bad)))
    _do_interp_dots(inst, interpolation, goods_idx, bads_idx)

dataset/ETHPy150Open mne-tools/mne-python/mne/channels/interpolation.py _interpolate_bads_eeg/original