本文整理汇总了Python中mne.Epochs.get_data方法的典型用法代码示例。如果您正苦于以下问题:Python Epochs.get_data方法的具体用法?Python Epochs.get_data怎么用?Python Epochs.get_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.Epochs
的用法示例。
在下文中一共展示了Epochs.get_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reject_epochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_reject_epochs():
"""Test of epochs rejection
"""
epochs = Epochs(raw, events, event_id, tmin, tmax, baseline=(None, 0),
reject=reject, flat=flat)
n_events = len(epochs.events)
data = epochs.get_data()
n_clean_epochs = len(data)
# Should match
# mne_process_raw --raw test_raw.fif --projoff \
# --saveavetag -ave --ave test.ave --filteroff
assert_true(n_events > n_clean_epochs)
assert_true(n_clean_epochs == 3)
assert_true(epochs.drop_log == [[], [], [], ['MEG 2443'],
['MEG 2443'], ['MEG 2443'], ['MEG 2443']])
# Ensure epochs are not dropped based on a bad channel
raw_2 = raw.copy()
raw_2.info['bads'] = ['MEG 2443']
reject_crazy = dict(grad=1000e-15, mag=4e-15, eeg=80e-9, eog=150e-9)
epochs = Epochs(raw_2, events, event_id, tmin, tmax, baseline=(None, 0),
reject=reject_crazy, flat=flat)
epochs.drop_bad_epochs()
assert_true(all(['MEG 2442' in e for e in epochs.drop_log]))
assert_true(all(['MEG 2443' not in e for e in epochs.drop_log]))
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject, flat=flat,
reject_tmin=0., reject_tmax=.1)
data = epochs.get_data()
n_clean_epochs = len(data)
assert_true(n_clean_epochs == 7)
assert_true(epochs.times[epochs._reject_time][0] >= 0.)
assert_true(epochs.times[epochs._reject_time][-1] <= 0.1)
示例2: test_crop
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_crop():
"""Test of crop of epochs
"""
raw, events, picks = _get_data()
epochs = Epochs(raw, events[:5], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=False,
reject=reject, flat=flat)
assert_raises(RuntimeError, epochs.crop, None, 0.2) # not preloaded
data_normal = epochs.get_data()
epochs2 = Epochs(raw, events[:5], event_id, tmin, tmax,
picks=picks, baseline=(None, 0), preload=True,
reject=reject, flat=flat)
with warnings.catch_warnings(record=True) as w:
epochs2.crop(-20, 200)
assert_true(len(w) == 2)
# indices for slicing
tmin_window = tmin + 0.1
tmax_window = tmax - 0.1
tmask = (epochs.times >= tmin_window) & (epochs.times <= tmax_window)
assert_true(tmin_window > tmin)
assert_true(tmax_window < tmax)
epochs3 = epochs2.crop(tmin_window, tmax_window, copy=True)
data3 = epochs3.get_data()
epochs2.crop(tmin_window, tmax_window)
data2 = epochs2.get_data()
assert_array_equal(data2, data_normal[:, :, tmask])
assert_array_equal(data3, data_normal[:, :, tmask])
示例3: test_detrend
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_detrend():
"""Test detrending of epochs
"""
# test first-order
epochs_1 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=None, detrend=1)
epochs_2 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=None, detrend=None)
data_picks = pick_types(epochs_1.info, meg=True, eeg=True,
exclude='bads')
evoked_1 = epochs_1.average()
evoked_2 = epochs_2.average()
evoked_2.detrend(1)
# Due to roundoff these won't be exactly equal, but they should be close
assert_true(np.allclose(evoked_1.data, evoked_2.data,
rtol=1e-8, atol=1e-20))
# test zeroth-order case
for preload in [True, False]:
epochs_1 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=(None, None), preload=preload)
epochs_2 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=None, preload=preload, detrend=0)
a = epochs_1.get_data()
b = epochs_2.get_data()
# All data channels should be almost equal
assert_true(np.allclose(a[:, data_picks, :], b[:, data_picks, :],
rtol=1e-16, atol=1e-20))
# There are non-M/EEG channels that should not be equal:
assert_true(not np.allclose(a, b))
示例4: test_resample
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [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))
示例5: test_epochs_proj
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_epochs_proj():
"""Test handling projection (apply proj in Raw or in Epochs)
"""
exclude = raw.info["bads"] + ["MEG 2443", "EEG 053"] # bads + 2 more
this_picks = pick_types(raw.info, meg=True, eeg=False, stim=True, eog=True, exclude=exclude)
epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=True)
assert_true(all(p["active"] is True for p in epochs.info["projs"]))
evoked = epochs.average()
assert_true(all(p["active"] is True for p in evoked.info["projs"]))
data = epochs.get_data()
raw_proj = io.Raw(raw_fname, proj=True)
epochs_no_proj = Epochs(
raw_proj, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=False
)
data_no_proj = epochs_no_proj.get_data()
assert_true(all(p["active"] is True for p in epochs_no_proj.info["projs"]))
evoked_no_proj = epochs_no_proj.average()
assert_true(all(p["active"] is True for p in evoked_no_proj.info["projs"]))
assert_true(epochs_no_proj.proj is True) # as projs are active from Raw
assert_array_almost_equal(data, data_no_proj, decimal=8)
# make sure we can exclude avg ref
this_picks = pick_types(raw.info, meg=True, eeg=True, stim=True, eog=True, exclude=exclude)
epochs = Epochs(
raw, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=True, add_eeg_ref=True
)
assert_true(_has_eeg_average_ref_proj(epochs.info["projs"]))
epochs = Epochs(
raw, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=True, add_eeg_ref=False
)
assert_true(not _has_eeg_average_ref_proj(epochs.info["projs"]))
示例6: test_resample
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [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)
示例7: test_subtract_evoked
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_subtract_evoked():
"""Test subtraction of Evoked from Epochs
"""
epochs = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0))
# make sure subraction fails if data channels are missing
assert_raises(ValueError, epochs.subtract_evoked, epochs.average(picks[:5]))
# do the subraction using the default argument
epochs.subtract_evoked()
# apply SSP now
epochs.apply_proj()
# use preloading and SSP from the start
epochs2 = Epochs(raw, events[:10], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True, proj=True)
evoked = epochs2.average()
epochs2.subtract_evoked(evoked)
# this gives the same result
assert_allclose(epochs.get_data(), epochs2.get_data())
# if we compute the evoked response after subtracting it we get zero
zero_evoked = epochs.average()
data = zero_evoked.data
assert_array_almost_equal(data, np.zeros_like(data), decimal=20)
示例8: test_scaler
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_scaler():
"""Test methods of Scaler."""
raw = io.read_raw_fif(raw_fname)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
y = epochs.events[:, -1]
methods = (None, dict(mag=5, grad=10, eeg=20), 'mean', 'median')
infos = (epochs.info, epochs.info, None, None)
epochs_data_t = epochs_data.transpose([1, 0, 2])
for method, info in zip(methods, infos):
if method == 'median' and not check_version('sklearn', '0.17'):
assert_raises(ValueError, Scaler, info, method)
continue
if method == 'mean' and not check_version('sklearn', ''):
assert_raises(ImportError, Scaler, info, method)
continue
scaler = Scaler(info, method)
X = scaler.fit_transform(epochs_data, y)
assert_equal(X.shape, epochs_data.shape)
if method is None or isinstance(method, dict):
sd = DEFAULTS['scalings'] if method is None else method
stds = np.zeros(len(picks))
for key in ('mag', 'grad'):
stds[pick_types(epochs.info, meg=key)] = 1. / sd[key]
stds[pick_types(epochs.info, meg=False, eeg=True)] = 1. / sd['eeg']
means = np.zeros(len(epochs.ch_names))
elif method == 'mean':
stds = np.array([np.std(ch_data) for ch_data in epochs_data_t])
means = np.array([np.mean(ch_data) for ch_data in epochs_data_t])
else: # median
percs = np.array([np.percentile(ch_data, [25, 50, 75])
for ch_data in epochs_data_t])
stds = percs[:, 2] - percs[:, 0]
means = percs[:, 1]
assert_allclose(X * stds[:, np.newaxis] + means[:, np.newaxis],
epochs_data, rtol=1e-12, atol=1e-20, err_msg=method)
X2 = scaler.fit(epochs_data, y).transform(epochs_data)
assert_array_equal(X, X2)
# inverse_transform
Xi = scaler.inverse_transform(X)
assert_array_almost_equal(epochs_data, Xi)
# Test init exception
assert_raises(ValueError, Scaler, None, None)
assert_raises(ValueError, scaler.fit, epochs, y)
assert_raises(ValueError, scaler.transform, epochs)
epochs_bad = Epochs(raw, events, event_id, 0, 0.01,
picks=np.arange(len(raw.ch_names))) # non-data chs
scaler = Scaler(epochs_bad.info, None)
assert_raises(ValueError, scaler.fit, epochs_bad.get_data(), y)
示例9: test_preload_epochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_preload_epochs():
"""Test preload of epochs
"""
epochs_preload = Epochs(
raw, events[:16], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True, reject=reject, flat=flat
)
data_preload = epochs_preload.get_data()
epochs = Epochs(
raw, events[:16], event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=False, reject=reject, flat=flat
)
data = epochs.get_data()
assert_array_equal(data_preload, data)
assert_array_almost_equal(epochs_preload.average().data, epochs.average().data, 18)
示例10: test_pick_channels_mixin
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_pick_channels_mixin():
"""Test channel-picking functionality
"""
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks, baseline=(None, 0))
ch_names = epochs.ch_names[:3]
ch_names_orig = epochs.ch_names
dummy = epochs.pick_channels(ch_names, copy=True)
assert_equal(ch_names, dummy.ch_names)
assert_equal(ch_names_orig, epochs.ch_names)
assert_equal(len(ch_names_orig), epochs.get_data().shape[1])
epochs.pick_channels(ch_names)
assert_equal(ch_names, epochs.ch_names)
assert_equal(len(ch_names), epochs.get_data().shape[1])
示例11: test_concatenatechannels
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_concatenatechannels():
"""Test methods of ConcatenateChannels
"""
raw = fiff.Raw(raw_fname, preload=False)
events = read_events(event_name)
picks = fiff.pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
with warnings.catch_warnings(record=True) as w:
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
concat = ConcatenateChannels(epochs.info)
y = epochs.events[:, -1]
X = concat.fit_transform(epochs_data, y)
# Check data dimensions
assert_true(X.shape[0] == epochs_data.shape[0])
assert_true(X.shape[1] == epochs_data.shape[1] * epochs_data.shape[2])
assert_array_equal(concat.fit(epochs_data, y).transform(epochs_data), X)
# Check if data is preserved
n_times = epochs_data.shape[2]
assert_array_equal(epochs_data[0, 0, 0:n_times], X[0, 0:n_times])
# Test init exception
assert_raises(ValueError, concat.fit, epochs, y)
assert_raises(ValueError, concat.transform, epochs, y)
示例12: test_scaler
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_scaler():
"""Test methods of Scaler
"""
raw = fiff.Raw(raw_fname, preload=False)
events = read_events(event_name)
picks = fiff.pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
scaler = Scaler(epochs.info)
y = epochs.events[:, -1]
# np invalid divide value warnings
with warnings.catch_warnings(record=True):
X = scaler.fit_transform(epochs_data, y)
assert_true(X.shape == epochs_data.shape)
X2 = scaler.fit(epochs_data, y).transform(epochs_data)
assert_array_equal(X2, X)
# Test init exception
assert_raises(ValueError, scaler.fit, epochs, y)
assert_raises(ValueError, scaler.transform, epochs, y)
示例13: test_scaler
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_scaler():
"""Test methods of Scaler."""
raw = io.read_raw_fif(raw_fname)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
scaler = Scaler(epochs.info)
y = epochs.events[:, -1]
# np invalid divide value warnings
with warnings.catch_warnings(record=True):
X = scaler.fit_transform(epochs_data, y)
assert_true(X.shape == epochs_data.shape)
X2 = scaler.fit(epochs_data, y).transform(epochs_data)
assert_array_equal(X2, X)
# Test inverse_transform
with warnings.catch_warnings(record=True): # invalid value in mult
Xi = scaler.inverse_transform(X, y)
assert_array_almost_equal(epochs_data, Xi)
for kwargs in [{'with_mean': False}, {'with_std': False}]:
scaler = Scaler(epochs.info, **kwargs)
scaler.fit(epochs_data, y)
assert_array_almost_equal(
X, scaler.inverse_transform(scaler.transform(X)))
# Test init exception
assert_raises(ValueError, scaler.fit, epochs, y)
assert_raises(ValueError, scaler.transform, epochs, y)
示例14: test_regularized_csp
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_regularized_csp():
"""Test Common Spatial Patterns algorithm using regularized covariance."""
raw = io.read_raw_fif(raw_fname)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
n_channels = epochs_data.shape[1]
n_components = 3
reg_cov = [None, 0.05, 'ledoit_wolf', 'oas']
for reg in reg_cov:
csp = CSP(n_components=n_components, reg=reg, norm_trace=False)
csp.fit(epochs_data, epochs.events[:, -1])
y = epochs.events[:, -1]
X = csp.fit_transform(epochs_data, y)
assert_true(csp.filters_.shape == (n_channels, n_channels))
assert_true(csp.patterns_.shape == (n_channels, n_channels))
assert_array_almost_equal(csp.fit(epochs_data, y).
transform(epochs_data), X)
# test init exception
assert_raises(ValueError, csp.fit, epochs_data,
np.zeros_like(epochs.events))
assert_raises(ValueError, csp.fit, epochs, y)
assert_raises(ValueError, csp.transform, epochs)
csp.n_components = n_components
sources = csp.transform(epochs_data)
assert_true(sources.shape[1] == n_components)
示例15: test_csp
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import get_data [as 别名]
def test_csp():
"""Test Common Spatial Patterns algorithm on epochs
"""
raw = fiff.Raw(raw_fname, preload=False)
events = read_events(event_name)
picks = fiff.pick_types(raw.info, meg=True, stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
n_channels = epochs_data.shape[1]
n_components = 3
csp = CSP(n_components=n_components)
csp.fit(epochs_data, epochs.events[:, -1])
y = epochs.events[:, -1]
X = csp.fit_transform(epochs_data, y)
assert_true(csp.filters_.shape == (n_channels, n_channels))
assert_true(csp.patterns_.shape == (n_channels, n_channels))
assert_array_almost_equal(csp.fit(epochs_data, y).transform(epochs_data),
X)
# test init exception
assert_raises(ValueError, csp.fit, epochs_data,
np.zeros_like(epochs.events))
assert_raises(ValueError, csp.fit, epochs, y)
assert_raises(ValueError, csp.transform, epochs, y)
csp.n_components = n_components
sources = csp.transform(epochs_data)
assert_true(sources.shape[1] == n_components)