当前位置: 首页>>代码示例>>Python>>正文


Python RawArray.info['bads']方法代码示例

本文整理汇总了Python中mne.io.RawArray.info['bads']方法的典型用法代码示例。如果您正苦于以下问题:Python RawArray.info['bads']方法的具体用法?Python RawArray.info['bads']怎么用?Python RawArray.info['bads']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mne.io.RawArray的用法示例。


在下文中一共展示了RawArray.info['bads']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_mark_flat

# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import info['bads'] [as 别名]
def test_mark_flat(first_samp):
    """Test marking flat segments."""
    # Test if ECG analysis will work on data that is not preloaded
    n_ch, n_times = 11, 1000
    data = np.random.RandomState(0).randn(n_ch, n_times)
    assert not (np.diff(data, axis=-1) == 0).any()  # nothing flat at first
    info = create_info(n_ch, 1000., 'eeg')
    info['meas_date'] = (1, 2)
    # test first_samp != for gh-6295
    raw = RawArray(data, info, first_samp=first_samp)
    raw.info['bads'] = [raw.ch_names[-1]]

    #
    # First make a channel flat the whole time
    #
    raw_0 = raw.copy()
    raw_0._data[0] = 0.
    for kwargs, bads, want_times in [
            # Anything < 1 will mark spatially
            (dict(bad_percent=100.), [], 0),
            (dict(bad_percent=99.9), [raw.ch_names[0]], n_times),
            (dict(), [raw.ch_names[0]], n_times)]:  # default (1)
        raw_time = mark_flat(raw_0.copy(), verbose='debug', **kwargs)
        want_bads = raw.info['bads'] + bads
        assert raw_time.info['bads'] == want_bads
        n_good_times = raw_time.get_data(reject_by_annotation='omit').shape[1]
        assert n_good_times == want_times

    #
    # Now make a channel flat for 20% of the time points
    #
    raw_0 = raw.copy()
    n_good_times = int(round(0.8 * n_times))
    raw_0._data[0, n_good_times:] = 0.
    threshold = 100 * (n_times - n_good_times) / n_times
    for kwargs, bads, want_times in [
            # Should change behavior at bad_percent=20
            (dict(bad_percent=100), [], n_good_times),
            (dict(bad_percent=threshold), [], n_good_times),
            (dict(bad_percent=threshold - 1e-5), [raw.ch_names[0]], n_times),
            (dict(), [raw.ch_names[0]], n_times)]:
        raw_time = mark_flat(raw_0.copy(), verbose='debug', **kwargs)
        want_bads = raw.info['bads'] + bads
        assert raw_time.info['bads'] == want_bads
        n_good_times = raw_time.get_data(reject_by_annotation='omit').shape[1]
        assert n_good_times == want_times

    with pytest.raises(TypeError, match='must be an instance of BaseRaw'):
        mark_flat(0.)
    with pytest.raises(ValueError, match='not convert string to float'):
        mark_flat(raw, 'x')
开发者ID:adykstra,项目名称:mne-python,代码行数:53,代码来源:test_flat.py


注:本文中的mne.io.RawArray.info['bads']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。