本文整理汇总了Python中mne.io.RawArray.get_data方法的典型用法代码示例。如果您正苦于以下问题:Python RawArray.get_data方法的具体用法?Python RawArray.get_data怎么用?Python RawArray.get_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.RawArray
的用法示例。
在下文中一共展示了RawArray.get_data方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_raw_reject
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import get_data [as 别名]
def test_raw_reject():
"""Test raw data getter with annotation reject."""
info = create_info(['a', 'b', 'c', 'd', 'e'], 100, ch_types='eeg')
raw = RawArray(np.ones((5, 15000)), info)
with warnings.catch_warnings(record=True): # one outside range
raw.annotations = Annotations([2, 100, 105, 148], [2, 8, 5, 8], 'BAD')
data = raw.get_data([0, 1, 3, 4], 100, 11200, 'omit')
assert_array_equal(data.shape, (4, 9900))
# with orig_time and complete overlap
raw = read_raw_fif(fif_fname)
raw.annotations = Annotations([44, 47, 48], [1, 3, 1], 'BAD',
raw.info['meas_date'])
data, times = raw.get_data(range(10), 0, 6000, 'omit', True)
assert_array_equal(data.shape, (10, 4799))
assert_equal(times[-1], raw.times[5999])
assert_array_equal(data[:, -100:], raw[:10, 5900:6000][0])
data, times = raw.get_data(range(10), 0, 6000, 'NaN', True)
assert_array_equal(data.shape, (10, 6000))
assert_equal(times[-1], raw.times[5999])
assert_true(np.isnan(data[:, 313:613]).all()) # 1s -2s
assert_true(not np.isnan(data[:, 614].any()))
assert_array_equal(data[:, -100:], raw[:10, 5900:6000][0])
assert_array_equal(raw.get_data(), raw[:][0])
# Test _sync_onset
times = [10, -88, 190]
onsets = _sync_onset(raw, times)
assert_array_almost_equal(onsets, times - raw.first_samp /
raw.info['sfreq'])
assert_array_almost_equal(times, _sync_onset(raw, onsets, True))
示例2: test_raw_reject
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import get_data [as 别名]
def test_raw_reject():
"""Test raw data getter with annotation reject."""
sfreq = 100.
info = create_info(['a', 'b', 'c', 'd', 'e'], sfreq, ch_types='eeg')
raw = RawArray(np.ones((5, 15000)), info)
with pytest.warns(RuntimeWarning, match='outside the data range'):
raw.set_annotations(Annotations([2, 100, 105, 148],
[2, 8, 5, 8], 'BAD'))
data, times = raw.get_data([0, 1, 3, 4], 100, 11200, # 1-112 sec
'omit', return_times=True)
bad_times = np.concatenate([np.arange(200, 400),
np.arange(10000, 10800),
np.arange(10500, 11000)])
expected_times = np.setdiff1d(np.arange(100, 11200), bad_times) / sfreq
assert_allclose(times, expected_times)
# with orig_time and complete overlap
raw = read_raw_fif(fif_fname)
raw.set_annotations(Annotations(onset=[1, 4, 5] + raw._first_time,
duration=[1, 3, 1],
description='BAD',
orig_time=raw.info['meas_date']))
t_stop = 18.
assert raw.times[-1] > t_stop
n_stop = int(round(t_stop * raw.info['sfreq']))
n_drop = int(round(4 * raw.info['sfreq']))
assert len(raw.times) >= n_stop
data, times = raw.get_data(range(10), 0, n_stop, 'omit', True)
assert data.shape == (10, n_stop - n_drop)
assert times[-1] == raw.times[n_stop - 1]
assert_array_equal(data[:, -100:], raw[:10, n_stop - 100:n_stop][0])
data, times = raw.get_data(range(10), 0, n_stop, 'NaN', True)
assert_array_equal(data.shape, (10, n_stop))
assert times[-1] == raw.times[n_stop - 1]
t_1, t_2 = raw.time_as_index([1, 2], use_rounding=True)
assert np.isnan(data[:, t_1:t_2]).all() # 1s -2s
assert not np.isnan(data[:, :t_1].any())
assert not np.isnan(data[:, t_2:].any())
assert_array_equal(data[:, -100:], raw[:10, n_stop - 100:n_stop][0])
assert_array_equal(raw.get_data(), raw[:][0])
# Test _sync_onset
times = [10, -88, 190]
onsets = _sync_onset(raw, times)
assert_array_almost_equal(onsets, times - raw.first_samp /
raw.info['sfreq'])
assert_array_almost_equal(times, _sync_onset(raw, onsets, True))
示例3: test_resample_raw
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import get_data [as 别名]
def test_resample_raw():
"""Test resampling using RawArray."""
x = np.zeros((1, 1001))
sfreq = 2048.
raw = RawArray(x, create_info(1, sfreq, 'eeg'))
raw.resample(128, npad=10)
data = raw.get_data()
assert data.shape == (1, 63)
示例4: test_get_data_reject
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import get_data [as 别名]
def test_get_data_reject():
"""Test if reject_by_annotation is working correctly."""
fs = 256
ch_names = ["C3", "Cz", "C4"]
info = create_info(ch_names, sfreq=fs)
raw = RawArray(np.zeros((len(ch_names), 10 * fs)), info)
raw.set_annotations(Annotations(onset=[2, 4], duration=[3, 2],
description="bad"))
with catch_logging() as log:
data = raw.get_data(reject_by_annotation="omit", verbose=True)
msg = ('Omitting 1024 of 2560 (40.00%) samples, retaining 1536' +
' (60.00%) samples.')
assert log.getvalue().strip() == msg
assert data.shape == (len(ch_names), 1536)
with catch_logging() as log:
data = raw.get_data(reject_by_annotation="nan", verbose=True)
msg = ('Setting 1024 of 2560 (40.00%) samples to NaN, retaining 1536' +
' (60.00%) samples.')
assert log.getvalue().strip() == msg
assert data.shape == (len(ch_names), 2560) # shape doesn't change
assert np.isnan(data).sum() == 3072 # but NaNs are introduced instead
示例5: test_annotation_omit
# 需要导入模块: from mne.io import RawArray [as 别名]
# 或者: from mne.io.RawArray import get_data [as 别名]
def test_annotation_omit():
"""Test raw.get_data with annotations."""
data = np.concatenate([np.ones((1, 1000)), 2 * np.ones((1, 1000))], -1)
info = create_info(1, 1000., 'eeg')
raw = RawArray(data, info)
raw.set_annotations(Annotations([0.5], [1], ['bad']))
expected = raw[0][0]
assert_allclose(raw.get_data(reject_by_annotation=None), expected)
# nan
expected[0, 500:1500] = np.nan
assert_allclose(raw.get_data(reject_by_annotation='nan'), expected)
got = np.concatenate([raw.get_data(start=start, stop=stop,
reject_by_annotation='nan')
for start, stop in ((0, 1000), (1000, 2000))], -1)
assert_allclose(got, expected)
# omit
expected = expected[:, np.isfinite(expected[0])]
assert_allclose(raw.get_data(reject_by_annotation='omit'), expected)
got = np.concatenate([raw.get_data(start=start, stop=stop,
reject_by_annotation='omit')
for start, stop in ((0, 1000), (1000, 2000))], -1)
assert_allclose(got, expected)
pytest.raises(ValueError, raw.get_data, reject_by_annotation='foo')