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


Python Epochs.resample方法代码示例

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


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

示例1: test_resample

# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import resample [as 别名]
def test_resample():
    """Test of resample of epochs
    """
    epochs = Epochs(raw, events[:5], event_id, tmin, tmax, picks=picks,
                    baseline=(None, 0), preload=True,
                    reject=reject, flat=flat)
    data_normal = cp.deepcopy(epochs.get_data())
    times_normal = cp.deepcopy(epochs.times)
    sfreq_normal = epochs.info['sfreq']
    # upsample by 2
    epochs.resample(sfreq_normal * 2)
    data_up = cp.deepcopy(epochs.get_data())
    times_up = cp.deepcopy(epochs.times)
    sfreq_up = epochs.info['sfreq']
    # downsamply by 2, which should match
    epochs.resample(sfreq_normal)
    data_new = cp.deepcopy(epochs.get_data())
    times_new = cp.deepcopy(epochs.times)
    sfreq_new = epochs.info['sfreq']

    assert_true(data_up.shape[2] == 2 * data_normal.shape[2])
    assert_true(sfreq_up == 2 * sfreq_normal)
    assert_true(sfreq_new == sfreq_normal)
    assert_true(len(times_up) == 2 * len(times_normal))
    assert_array_almost_equal(times_new, times_normal, 10)
    assert_true(data_up.shape[2] == 2 * data_normal.shape[2])
    assert_array_almost_equal(data_new, data_normal, 2)
开发者ID:starzynski,项目名称:mne-python,代码行数:29,代码来源:test_epochs.py

示例2: test_resample

# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import resample [as 别名]
def test_resample():
    """Test of resample of epochs
    """
    epochs = Epochs(
        raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True, reject=reject, flat=flat
    )
    data_normal = cp.deepcopy(epochs.get_data())
    times_normal = cp.deepcopy(epochs.times)
    sfreq_normal = epochs.info["sfreq"]
    # upsample by 2
    epochs.resample(sfreq_normal * 2, npad=0)
    data_up = cp.deepcopy(epochs.get_data())
    times_up = cp.deepcopy(epochs.times)
    sfreq_up = epochs.info["sfreq"]
    # downsamply by 2, which should match
    epochs.resample(sfreq_normal, npad=0)
    data_new = cp.deepcopy(epochs.get_data())
    times_new = cp.deepcopy(epochs.times)
    sfreq_new = epochs.info["sfreq"]
    assert_true(data_up.shape[2] == 2 * data_normal.shape[2])
    assert_true(sfreq_up == 2 * sfreq_normal)
    assert_true(sfreq_new == sfreq_normal)
    assert_true(len(times_up) == 2 * len(times_normal))
    assert_array_almost_equal(times_new, times_normal, 10)
    assert_true(data_up.shape[2] == 2 * data_normal.shape[2])
    assert_array_almost_equal(data_new, data_normal, 5)

    # use parallel
    epochs = Epochs(
        raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True, reject=reject, flat=flat
    )
    epochs.resample(sfreq_normal * 2, n_jobs=2, npad=0)
    assert_true(np.allclose(data_up, epochs._data, rtol=1e-8, atol=1e-16))
开发者ID:rgoj,项目名称:mne-python,代码行数:35,代码来源:test_epochs.py

示例3: fix_triggers

# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import resample [as 别名]
for event_type in event_types:
    events_behavior_type = fix_triggers(events_meg, events_behavior,
                                        event_type='trigg' + event_type)

    # Epoch raw data
    epochs_list = list()
    for run in range(1, n_runs):
        fname_raw = op.join(path_data, subject, 'run%02i.fif' % run)
        raw = Raw(fname_raw, preload=True)
        raw.filter(.75, h_freq=30.0)
        sel = events_behavior_type['meg_file'] == run
        time_sample = events_behavior_type['meg_event_tsample'][sel]
        trigger_value = events_behavior_type['meg_event_value'][sel]
        events_meg = np.vstack((time_sample.astype(int),
                                np.zeros_like(time_sample, int),
                                trigger_value.astype(int))).T
        event_id = {'ttl_%i' % ii: ii for ii in np.unique(events_meg[:, 2])}
        epochs = Epochs(raw, events_meg, event_id=event_id,
                        tmin=-1.0, tmax=.500, preload=True)
        # epochs.resample(128)  # XXX BUG MNE when concatenate afterwards
        epochs_list.append(epochs)
    epochs = concatenate_epochs(epochs_list)
    epochs.resample(128)

    # Save data
    fname = op.join(path_data, subject, 'epochs_%s.fif' % event_type)
    epochs.save(fname)
    fname = op.join(path_data,  subject, 'behavior_%s.pkl' % event_type)
    with open(fname, 'wb') as f:
        pickle.dump(events_behavior_type, f)
开发者ID:romquentin,项目名称:romain_wm,代码行数:32,代码来源:concate_runs.py


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