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


Python Raw.pick_channels方法代码示例

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


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

示例1: test_bad_proj

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_bad_proj():
    """Test dealing with bad projection application
    """
    raw = Raw(raw_fname, preload=True)
    events = read_events(event_fname)
    picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
                       eog=False, exclude='bads')
    picks = picks[2:9:3]
    _check_warnings(raw, events, picks)
    # still bad
    raw.pick_channels([raw.ch_names[ii] for ii in picks])
    _check_warnings(raw, events, np.arange(len(raw.ch_names)))
    # "fixed"
    raw.info.normalize_proj()  # avoid projection warnings
    _check_warnings(raw, events, np.arange(len(raw.ch_names)), count=0)
开发者ID:Pablo-Arias,项目名称:mne-python,代码行数:17,代码来源:test_proj.py

示例2: test_compute_covariance_auto_reg

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_compute_covariance_auto_reg():
    """Test automated regularization"""

    raw = Raw(raw_fname, preload=True)
    raw.resample(100, npad='auto')  # much faster estimation
    events = find_events(raw, stim_channel='STI 014')
    event_ids = [1, 2, 3, 4]
    reject = dict(mag=4e-12)

    # cov with merged events and keep_sample_mean=True
    events_merged = merge_events(events, event_ids, 1234)
    # we need a few channels for numerical reasons in PCA/FA
    picks = pick_types(raw.info, meg='mag', eeg=False)[:10]
    raw.pick_channels([raw.ch_names[pick] for pick in picks])
    raw.info.normalize_proj()
    epochs = Epochs(
        raw, events_merged, 1234, tmin=-0.2, tmax=0,
        baseline=(-0.2, -0.1), proj=True, reject=reject, preload=True)
    epochs = epochs.crop(None, 0)[:10]

    method_params = dict(factor_analysis=dict(iter_n_components=[3]),
                         pca=dict(iter_n_components=[3]))

    covs = compute_covariance(epochs, method='auto',
                              method_params=method_params,
                              projs=True,
                              return_estimators=True)

    logliks = [c['loglik'] for c in covs]
    assert_true(np.diff(logliks).max() <= 0)  # descending order

    methods = ['empirical',
               'factor_analysis',
               'ledoit_wolf',
               'pca']
    cov3 = compute_covariance(epochs, method=methods,
                              method_params=method_params, projs=None,
                              return_estimators=True)

    assert_equal(set([c['method'] for c in cov3]),
                 set(methods))

    # invalid prespecified method
    assert_raises(ValueError, compute_covariance, epochs, method='pizza')

    # invalid scalings
    assert_raises(ValueError, compute_covariance, epochs, method='shrunk',
                  scalings=dict(misc=123))
开发者ID:MartinBaBer,项目名称:mne-python,代码行数:50,代码来源:test_cov.py

示例3: test_set_bipolar_reference

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_set_bipolar_reference():
    """Test bipolar referencing"""
    raw = Raw(fif_fname, preload=True)
    reref = set_bipolar_reference(
        raw, "EEG 001", "EEG 002", "bipolar", {"kind": FIFF.FIFFV_EOG_CH, "extra": "some extra value"}
    )
    assert_true(reref.info["custom_ref_applied"])

    # Compare result to a manual calculation
    a = raw.pick_channels(["EEG 001", "EEG 002"], copy=True)
    a = a._data[0, :] - a._data[1, :]
    b = reref.pick_channels(["bipolar"], copy=True)._data[0, :]
    assert_allclose(a, b)

    # Original channels should be replaced by a virtual one
    assert_true("EEG 001" not in reref.ch_names)
    assert_true("EEG 002" not in reref.ch_names)
    assert_true("bipolar" in reref.ch_names)

    # Check channel information
    bp_info = reref.info["chs"][reref.ch_names.index("bipolar")]
    an_info = reref.info["chs"][raw.ch_names.index("EEG 001")]
    for key in bp_info:
        if key == "loc":
            assert_array_equal(bp_info[key], 0)
        elif key == "coil_type":
            assert_equal(bp_info[key], FIFF.FIFFV_COIL_EEG_BIPOLAR)
        elif key == "kind":
            assert_equal(bp_info[key], FIFF.FIFFV_EOG_CH)
        else:
            assert_equal(bp_info[key], an_info[key])
    assert_equal(bp_info["extra"], "some extra value")

    # Minimalist call
    reref = set_bipolar_reference(raw, "EEG 001", "EEG 002")
    assert_true("EEG 001-EEG 002" in reref.ch_names)

    # Test creating a bipolar reference that doesn't involve EEG channels:
    # it should not set the custom_ref_applied flag
    reref = set_bipolar_reference(raw, "MEG 0111", "MEG 0112", ch_info={"kind": FIFF.FIFFV_MEG_CH})
    assert_true(not reref.info["custom_ref_applied"])
    assert_true("MEG 0111-MEG 0112" in reref.ch_names)

    # Test a battery of invalid inputs
    assert_raises(ValueError, set_bipolar_reference, raw, "EEG 001", ["EEG 002", "EEG 003"], "bipolar")
    assert_raises(ValueError, set_bipolar_reference, raw, ["EEG 001", "EEG 002"], "EEG 003", "bipolar")
    assert_raises(ValueError, set_bipolar_reference, raw, "EEG 001", "EEG 002", ["bipolar1", "bipolar2"])
    assert_raises(
        ValueError,
        set_bipolar_reference,
        raw,
        "EEG 001",
        "EEG 002",
        "bipolar",
        ch_info=[{"foo": "bar"}, {"foo": "bar"}],
    )
    assert_raises(ValueError, set_bipolar_reference, raw, "EEG 001", "EEG 002", ch_name="EEG 003")
开发者ID:jasmainak,项目名称:mne-python,代码行数:59,代码来源:test_reference.py

示例4: test_set_bipolar_reference

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_set_bipolar_reference():
    """Test bipolar referencing"""
    raw = Raw(fif_fname, preload=True)
    reref = set_bipolar_reference(raw, 'EEG 001', 'EEG 002', 'bipolar',
                                  {'kind': FIFF.FIFFV_EOG_CH,
                                   'extra': 'some extra value'})
    assert_true(reref.info['custom_ref_applied'])

    # Compare result to a manual calculation
    a = raw.pick_channels(['EEG 001', 'EEG 002'], copy=True)
    a = a._data[0, :] - a._data[1, :]
    b = reref.pick_channels(['bipolar'], copy=True)._data[0, :]
    assert_allclose(a, b)

    # Original channels should be replaced by a virtual one
    assert_true('EEG 001' not in reref.ch_names)
    assert_true('EEG 002' not in reref.ch_names)
    assert_true('bipolar' in reref.ch_names)

    # Check channel information
    bp_info = reref.info['chs'][reref.ch_names.index('bipolar')]
    an_info = reref.info['chs'][raw.ch_names.index('EEG 001')]
    for key in bp_info:
        if key == 'loc':
            assert_array_equal(bp_info[key], 0)
        elif key == 'coil_type':
            assert_equal(bp_info[key], FIFF.FIFFV_COIL_EEG_BIPOLAR)
        elif key == 'kind':
            assert_equal(bp_info[key], FIFF.FIFFV_EOG_CH)
        else:
            assert_equal(bp_info[key], an_info[key])
    assert_equal(bp_info['extra'], 'some extra value')

    # Minimalist call
    reref = set_bipolar_reference(raw, 'EEG 001', 'EEG 002')
    assert_true('EEG 001-EEG 002' in reref.ch_names)

    # Test creating a bipolar reference that doesn't involve EEG channels:
    # it should not set the custom_ref_applied flag
    reref = set_bipolar_reference(raw, 'MEG 0111', 'MEG 0112',
                                  ch_info={'kind': FIFF.FIFFV_MEG_CH})
    assert_true(not reref.info['custom_ref_applied'])
    assert_true('MEG 0111-MEG 0112' in reref.ch_names)

    # Test a battery of invalid inputs
    assert_raises(ValueError, set_bipolar_reference, raw,
                  'EEG 001', ['EEG 002', 'EEG 003'], 'bipolar')
    assert_raises(ValueError, set_bipolar_reference, raw,
                  ['EEG 001', 'EEG 002'], 'EEG 003', 'bipolar')
    assert_raises(ValueError, set_bipolar_reference, raw,
                  'EEG 001', 'EEG 002', ['bipolar1', 'bipolar2'])
    assert_raises(ValueError, set_bipolar_reference, raw,
                  'EEG 001', 'EEG 002', 'bipolar',
                  ch_info=[{'foo': 'bar'}, {'foo': 'bar'}])
    assert_raises(ValueError, set_bipolar_reference, raw,
                  'EEG 001', 'EEG 002', ch_name='EEG 003')
开发者ID:Famguy,项目名称:mne-python,代码行数:58,代码来源:test_reference.py

示例5: test_pick_channels_mixin

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_pick_channels_mixin():
    """Test channel-picking functionality
    """
    # preload is True
    raw = Raw(fif_fname, preload=True)
    ch_names = raw.ch_names[:3]

    ch_names_orig = raw.ch_names
    dummy = raw.pick_channels(ch_names, copy=True) # copy is True
    assert_equal(ch_names, dummy.ch_names)
    assert_equal(ch_names_orig, raw.ch_names)
    assert_equal(len(ch_names_orig), raw._data.shape[0])

    raw.pick_channels(ch_names, copy=False) # copy is False
    assert_equal(ch_names, raw.ch_names)
    assert_equal(len(ch_names), len(raw.cals))
    assert_equal(len(ch_names), raw._data.shape[0])

    # preload is False
    raw = Raw(fif_fname, preload=False)
    ch_names = raw.ch_names[:3]

    ch_names_orig = raw.ch_names
    dummy = raw.pick_channels(ch_names, copy=True) # copy is True
    assert_equal(ch_names, dummy.ch_names)
    assert_equal(ch_names_orig, raw.ch_names)

    raw.pick_channels(ch_names, copy=False) # copy is False
    assert_equal(ch_names, raw.ch_names)
    assert_equal(len(ch_names), len(raw.cals))
开发者ID:pombredanne,项目名称:mne-python,代码行数:32,代码来源:test_raw.py

示例6: test_pick_channels_mixin

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_pick_channels_mixin():
    """Test channel-picking functionality
    """
    # preload is True

    raw = Raw(fif_fname, preload=True)
    ch_names = raw.ch_names[:3]

    ch_names_orig = raw.ch_names
    dummy = raw.copy().pick_channels(ch_names)
    assert_equal(ch_names, dummy.ch_names)
    assert_equal(ch_names_orig, raw.ch_names)
    assert_equal(len(ch_names_orig), raw._data.shape[0])

    raw.pick_channels(ch_names)  # copy is False
    assert_equal(ch_names, raw.ch_names)
    assert_equal(len(ch_names), len(raw._cals))
    assert_equal(len(ch_names), raw._data.shape[0])
    assert_raises(ValueError, raw.pick_channels, ch_names[0])

    raw = Raw(fif_fname, preload=False)
    assert_raises(RuntimeError, raw.pick_channels, ch_names)
    assert_raises(RuntimeError, raw.drop_channels, ch_names)
开发者ID:octomike,项目名称:mne-python,代码行数:25,代码来源:test_raw_fiff.py

示例7: _get_data

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def _get_data():
    """Helper to get some starting data"""
    # raw with ECG channel
    raw = Raw(raw_fname).crop(0.0, 5.0).load_data()
    data_picks = pick_types(raw.info, meg=True, eeg=True)
    other_picks = pick_types(raw.info, meg=False, stim=True, eog=True)
    picks = np.sort(np.concatenate((data_picks[::16], other_picks)))
    raw = raw.pick_channels([raw.ch_names[p] for p in picks])
    ecg = RawArray(np.zeros((1, len(raw.times))), create_info(["ECG 063"], raw.info["sfreq"], "ecg"))
    for key in ("dev_head_t", "buffer_size_sec", "highpass", "lowpass", "filename", "dig"):
        ecg.info[key] = raw.info[key]
    raw.add_channels([ecg])

    src = read_source_spaces(src_fname)
    trans = read_trans(trans_fname)
    sphere = make_sphere_model("auto", "auto", raw.info)
    stc = _make_stc(raw, src)
    return raw, src, stc, trans, sphere
开发者ID:GrantRVD,项目名称:mne-python,代码行数:20,代码来源:test_raw.py

示例8: test_cov_estimation_on_raw

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def test_cov_estimation_on_raw():
    """Test estimation from raw (typically empty room)"""
    tempdir = _TempDir()
    raw = Raw(raw_fname, preload=True)
    cov_mne = read_cov(erm_cov_fname)

    # The pure-string uses the more efficient numpy-based method, the
    # the list gets triaged to compute_covariance (should be equivalent
    # but use more memory)
    for method in ('empirical', ['empirical']):
        cov = compute_raw_covariance(raw, tstep=None, method=method)
        assert_equal(cov.ch_names, cov_mne.ch_names)
        assert_equal(cov.nfree, cov_mne.nfree)
        assert_snr(cov.data, cov_mne.data, 1e4)

        cov = compute_raw_covariance(raw, method=method)  # tstep=0.2 (default)
        assert_equal(cov.nfree, cov_mne.nfree - 119)  # cutoff some samples
        assert_snr(cov.data, cov_mne.data, 1e2)

        # test IO when computation done in Python
        cov.save(op.join(tempdir, 'test-cov.fif'))  # test saving
        cov_read = read_cov(op.join(tempdir, 'test-cov.fif'))
        assert_true(cov_read.ch_names == cov.ch_names)
        assert_true(cov_read.nfree == cov.nfree)
        assert_array_almost_equal(cov.data, cov_read.data)

        # test with a subset of channels
        picks = pick_channels(raw.ch_names, include=raw.ch_names[:5])
        raw_pick = raw.pick_channels([raw.ch_names[pick] for pick in picks],
                                     copy=True)
        raw_pick.info.normalize_proj()
        cov = compute_raw_covariance(raw_pick, picks=picks, tstep=None,
                                     method=method)
        assert_true(cov_mne.ch_names[:5] == cov.ch_names)
        assert_snr(cov.data, cov_mne.data[picks][:, picks], 1e4)
        cov = compute_raw_covariance(raw_pick, picks=picks, method=method)
        assert_snr(cov.data, cov_mne.data[picks][:, picks], 90)  # cutoff samps
        # make sure we get a warning with too short a segment
        raw_2 = Raw(raw_fname).crop(0, 1)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter('always')
            cov = compute_raw_covariance(raw_2, method=method)
        assert_true(any('Too few samples' in str(ww.message) for ww in w))
开发者ID:Pablo-Arias,项目名称:mne-python,代码行数:45,代码来源:test_cov.py

示例9: _get_data

# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import pick_channels [as 别名]
def _get_data():
    """Helper to get some starting data"""
    # raw with ECG channel
    raw = Raw(raw_fname).crop(0., 5.0, copy=False).load_data()
    data_picks = pick_types(raw.info, meg=True, eeg=True)
    other_picks = pick_types(raw.info, meg=False, stim=True, eog=True)
    picks = np.sort(np.concatenate((data_picks[::16], other_picks)))
    raw = raw.pick_channels([raw.ch_names[p] for p in picks])
    ecg = RawArray(np.zeros((1, len(raw.times))),
                   create_info(['ECG 063'], raw.info['sfreq'], 'ecg'))
    for key in ('dev_head_t', 'buffer_size_sec', 'highpass', 'lowpass',
                'filename', 'dig'):
        ecg.info[key] = raw.info[key]
    raw.add_channels([ecg])

    src = read_source_spaces(src_fname)
    trans = read_trans(trans_fname)
    sphere = make_sphere_model('auto', 'auto', raw.info)
    stc = _make_stc(raw, src)
    return raw, src, stc, trans, sphere
开发者ID:MartinBaBer,项目名称:mne-python,代码行数:22,代码来源:test_raw.py


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