utils.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:autoreject 作者: autoreject 项目源码 文件源码
def clean_by_interp(inst, picks=None, verbose='progressbar'):
    """Clean epochs/evoked by LOOCV.

    Parameters
    ----------
    inst : instance of mne.Evoked or mne.Epochs
        The evoked or epochs object.
    picks : ndarray, shape(n_channels,) | None
        The channels to be considered for autoreject. If None, defaults
        to data channels {'meg', 'eeg'}.
    verbose : 'tqdm', 'tqdm_notebook', 'progressbar' or False
        The verbosity of progress messages.
        If `'progressbar'`, use `mne.utils.ProgressBar`.
        If `'tqdm'`, use `tqdm.tqdm`.
        If `'tqdm_notebook'`, use `tqdm.tqdm_notebook`.
        If False, suppress all output messages.

    Returns
    -------
    inst_clean : instance of mne.Evoked or mne.Epochs
        Instance after interpolation of bad channels.
    """
    inst_interp = inst.copy()
    mesg = 'Creating augmented epochs'
    picks = _handle_picks(info=inst_interp.info, picks=picks)

    BaseEpochs = _get_epochs_type()
    ch_names = [inst.info['ch_names'][p] for p in picks]
    for ch_idx, (pick, ch) in enumerate(_pbar(list(zip(picks, ch_names)),
                                        desc=mesg, verbose=verbose)):
        inst_clean = inst.copy()
        inst_clean.info['bads'] = [ch]
        interpolate_bads(inst_clean, picks=picks, reset_bads=True, mode='fast')

        pick_interp = mne.pick_channels(inst_clean.info['ch_names'], [ch])[0]

        if isinstance(inst, mne.Evoked):
            inst_interp.data[pick] = inst_clean.data[pick_interp]
        elif isinstance(inst, BaseEpochs):
            inst_interp._data[:, pick] = inst_clean._data[:, pick_interp]
        else:
            raise ValueError('Unrecognized type for inst')
    return inst_interp
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号