本文整理汇总了Python中mne.Epochs类的典型用法代码示例。如果您正苦于以下问题:Python Epochs类的具体用法?Python Epochs怎么用?Python Epochs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Epochs类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_epochs_to_nitime
def test_epochs_to_nitime():
"""Test test_to_nitime
"""
raw, events, picks = _get_data()
epochs = Epochs(raw, events[:5], event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True,
reject=reject, flat=flat)
picks2 = [0, 3]
epochs_ts = epochs.to_nitime(picks=None, epochs_idx=[0],
collapse=True, copy=True)
assert_true(epochs_ts.ch_names == epochs.ch_names)
epochs_ts = epochs.to_nitime(picks=picks2, epochs_idx=None,
collapse=True, copy=True)
assert_true(epochs_ts.ch_names == [epochs.ch_names[k] for k in picks2])
epochs_ts = epochs.to_nitime(picks=None, epochs_idx=[0],
collapse=False, copy=False)
assert_true(epochs_ts.ch_names == epochs.ch_names)
epochs_ts = epochs.to_nitime(picks=picks2, epochs_idx=None,
collapse=False, copy=False)
assert_true(epochs_ts.ch_names == [epochs.ch_names[k] for k in picks2])
开发者ID:MadsJensen,项目名称:mne-python,代码行数:25,代码来源:test_epochs.py
示例2: test_drop_epochs
def test_drop_epochs():
"""Test dropping of epochs.
"""
raw, events, picks = _get_data()
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0))
events1 = events[events[:, 2] == event_id]
# Bound checks
assert_raises(IndexError, epochs.drop_epochs, [len(epochs.events)])
assert_raises(IndexError, epochs.drop_epochs, [-1])
assert_raises(ValueError, epochs.drop_epochs, [[1, 2], [3, 4]])
# Test selection attribute
assert_array_equal(epochs.selection,
np.where(events[:, 2] == event_id)[0])
assert_equal(len(epochs.drop_log), len(events))
assert_true(all(epochs.drop_log[k] == ['IGNORED']
for k in set(range(len(events))) - set(epochs.selection)))
selection = epochs.selection.copy()
n_events = len(epochs.events)
epochs.drop_epochs([2, 4], reason='d')
assert_equal(epochs.drop_log_stats(), 2. / n_events * 100)
assert_equal(len(epochs.drop_log), len(events))
assert_equal([epochs.drop_log[k]
for k in selection[[2, 4]]], [['d'], ['d']])
assert_array_equal(events[epochs.selection], events1[[0, 1, 3, 5, 6]])
assert_array_equal(events[epochs[3:].selection], events1[[5, 6]])
assert_array_equal(events[epochs['1'].selection], events1[[0, 1, 3, 5, 6]])
开发者ID:MadsJensen,项目名称:mne-python,代码行数:30,代码来源:test_epochs.py
示例3: test_evoked_standard_error
def test_evoked_standard_error():
"""Test calculation and read/write of standard error
"""
epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=(None, 0))
evoked = [epochs.average(), epochs.standard_error()]
io.write_evokeds(op.join(tempdir, 'evoked.fif'), evoked)
evoked2 = read_evokeds(op.join(tempdir, 'evoked.fif'), [0, 1])
evoked3 = [read_evokeds(op.join(tempdir, 'evoked.fif'), 'Unknown'),
read_evokeds(op.join(tempdir, 'evoked.fif'), 'Unknown',
kind='standard_error')]
for evoked_new in [evoked2, evoked3]:
assert_true(evoked_new[0]._aspect_kind ==
FIFF.FIFFV_ASPECT_AVERAGE)
assert_true(evoked_new[0].kind == 'average')
assert_true(evoked_new[1]._aspect_kind ==
FIFF.FIFFV_ASPECT_STD_ERR)
assert_true(evoked_new[1].kind == 'standard_error')
for ave, ave2 in zip(evoked, evoked_new):
assert_array_almost_equal(ave.data, ave2.data)
assert_array_almost_equal(ave.times, ave2.times)
assert_equal(ave.nave, ave2.nave)
assert_equal(ave._aspect_kind, ave2._aspect_kind)
assert_equal(ave.kind, ave2.kind)
assert_equal(ave.last, ave2.last)
assert_equal(ave.first, ave2.first)
开发者ID:anywave,项目名称:aw-export-fif,代码行数:26,代码来源:test_epochs.py
示例4: test_xdawn_apply_transform
def test_xdawn_apply_transform():
"""Test Xdawn apply and transform."""
# get data
raw, events, picks = _get_data()
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
preload=True, baseline=None, verbose=False)
n_components = 2
# Fit Xdawn
xd = Xdawn(n_components=n_components, correct_overlap='auto')
xd.fit(epochs)
# apply on raw
xd.apply(raw)
# apply on epochs
denoise = xd.apply(epochs)
# apply on evoked
xd.apply(epochs.average())
# apply on other thing should raise an error
assert_raises(ValueError, xd.apply, 42)
# transform on epochs
xd.transform(epochs)
# transform on ndarray
xd.transform(epochs._data)
# transform on someting else
assert_raises(ValueError, xd.transform, 42)
# check numerical results with shuffled epochs
idx = np.arange(len(epochs))
np.random.shuffle(idx)
xd.fit(epochs[idx])
denoise_shfl = xd.apply(epochs)
assert_array_equal(denoise['cond2']._data, denoise_shfl['cond2']._data)
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:33,代码来源:test_xdawn.py
示例5: test_regularized_csp
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)
开发者ID:Hugo-W,项目名称:mne-python,代码行数:33,代码来源:test_csp.py
示例6: test_scaler
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)
开发者ID:Anevar,项目名称:mne-python,代码行数:26,代码来源:test_classifier.py
示例7: test_xdawn_regularization
def test_xdawn_regularization():
"""Test Xdawn with regularization."""
# Get data
raw, events, picks = _get_data()
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
preload=True, baseline=None, verbose=False)
# Test with overlapping events.
# modify events to simulate one overlap
events = epochs.events
sel = np.where(events[:, 2] == 2)[0][:2]
modified_event = events[sel[0]]
modified_event[0] += 1
epochs.events[sel[1]] = modified_event
# Fit and check that overlap was found and applied
xd = Xdawn(n_components=2, correct_overlap='auto', reg='oas')
xd.fit(epochs)
assert_equal(xd.correct_overlap_, True)
evoked = epochs['cond2'].average()
assert_true(np.sum(np.abs(evoked.data - xd.evokeds_['cond2'].data)))
# With covariance regularization
for reg in [.1, 0.1, 'ledoit_wolf', 'oas']:
xd = Xdawn(n_components=2, correct_overlap=False,
signal_cov=np.eye(len(picks)), reg=reg)
xd.fit(epochs)
# With bad shrinkage
xd = Xdawn(n_components=2, correct_overlap=False,
signal_cov=np.eye(len(picks)), reg=2)
assert_raises(ValueError, xd.fit, epochs)
开发者ID:deep-introspection,项目名称:mne-python,代码行数:30,代码来源:test_xdawn.py
示例8: test_compute_proj_epochs
def test_compute_proj_epochs():
"""Test SSP computation on epochs"""
event_id, tmin, tmax = 1, -0.2, 0.3
raw = Raw(raw_fname, preload=True)
events = read_events(event_fname)
bad_ch = 'MEG 2443'
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False,
exclude=[])
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=None, proj=False)
evoked = epochs.average()
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=1)
write_proj(op.join(tempdir, 'proj.fif.gz'), projs)
for p_fname in [proj_fname, proj_gz_fname,
op.join(tempdir, 'proj.fif.gz')]:
projs2 = read_proj(p_fname)
assert_true(len(projs) == len(projs2))
for p1, p2 in zip(projs, projs2):
assert_true(p1['desc'] == p2['desc'])
assert_true(p1['data']['col_names'] == p2['data']['col_names'])
assert_true(p1['active'] == p2['active'])
# compare with sign invariance
p1_data = p1['data']['data'] * np.sign(p1['data']['data'][0, 0])
p2_data = p2['data']['data'] * np.sign(p2['data']['data'][0, 0])
if bad_ch in p1['data']['col_names']:
bad = p1['data']['col_names'].index('MEG 2443')
mask = np.ones(p1_data.size, dtype=np.bool)
mask[bad] = False
p1_data = p1_data[:, mask]
p2_data = p2_data[:, mask]
corr = np.corrcoef(p1_data, p2_data)[0, 1]
assert_array_almost_equal(corr, 1.0, 5)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, epochs.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
epochs.info['projs'] += projs
evoked = epochs.average()
evoked.save(op.join(tempdir, 'foo.fif'))
projs = read_proj(proj_fname)
projs_evoked = compute_proj_evoked(evoked, n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(projs_evoked) == 2)
# XXX : test something
# test parallelization
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=2)
projs = activate_proj(projs)
proj_par, _, _ = make_projector(projs, epochs.ch_names, bads=[])
assert_allclose(proj, proj_par, rtol=1e-8, atol=1e-16)
开发者ID:Anevar,项目名称:mne-python,代码行数:60,代码来源:test_proj.py
示例9: test_epochs_vector_inverse
def test_epochs_vector_inverse():
"""Test vector inverse consistency between evoked and epochs."""
raw = read_raw_fif(fname_raw)
events = find_events(raw, stim_channel='STI 014')[:2]
reject = dict(grad=2000e-13, mag=4e-12, eog=150e-6)
epochs = Epochs(raw, events, None, 0, 0.01, baseline=None,
reject=reject, preload=True)
assert_equal(len(epochs), 2)
evoked = epochs.average(picks=range(len(epochs.ch_names)))
inv = read_inverse_operator(fname_inv)
method = "MNE"
snr = 3.
lambda2 = 1. / snr ** 2
stcs_epo = apply_inverse_epochs(epochs, inv, lambda2, method=method,
pick_ori='vector', return_generator=False)
stc_epo = np.mean(stcs_epo)
stc_evo = apply_inverse(evoked, inv, lambda2, method=method,
pick_ori='vector')
assert_allclose(stc_epo.data, stc_evo.data, rtol=1e-9, atol=0)
开发者ID:teonbrooks,项目名称:mne-python,代码行数:27,代码来源:test_source_estimate.py
示例10: test_psdestimator
def test_psdestimator():
"""Test methods of PSDEstimator
"""
raw = io.Raw(raw_fname, preload=False)
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()
psd = PSDEstimator(2 * np.pi, 0, np.inf)
y = epochs.events[:, -1]
X = psd.fit_transform(epochs_data, y)
assert_true(X.shape[0] == epochs_data.shape[0])
assert_array_equal(psd.fit(epochs_data, y).transform(epochs_data), X)
# Test init exception
assert_raises(ValueError, psd.fit, epochs, y)
assert_raises(ValueError, psd.transform, epochs, y)
开发者ID:vwyart,项目名称:mne-python,代码行数:28,代码来源:test_transformer.py
示例11: test_pick_seeg_ecog
def test_pick_seeg_ecog():
"""Test picking with sEEG and ECoG
"""
names = 'A1 A2 Fz O OTp1 OTp2 E1 OTp3 E2 E3'.split()
types = 'mag mag eeg eeg seeg seeg ecog seeg ecog ecog'.split()
info = create_info(names, 1024., types)
idx = channel_indices_by_type(info)
assert_array_equal(idx['mag'], [0, 1])
assert_array_equal(idx['eeg'], [2, 3])
assert_array_equal(idx['seeg'], [4, 5, 7])
assert_array_equal(idx['ecog'], [6, 8, 9])
assert_array_equal(pick_types(info, meg=False, seeg=True), [4, 5, 7])
for i, t in enumerate(types):
assert_equal(channel_type(info, i), types[i])
raw = RawArray(np.zeros((len(names), 10)), info)
events = np.array([[1, 0, 0], [2, 0, 0]])
epochs = Epochs(raw, events, {'event': 0}, -1e-5, 1e-5, add_eeg_ref=False)
evoked = epochs.average(pick_types(epochs.info, meg=True, seeg=True))
e_seeg = evoked.copy().pick_types(meg=False, seeg=True)
for l, r in zip(e_seeg.ch_names, [names[4], names[5], names[7]]):
assert_equal(l, r)
# Deal with constant debacle
raw = read_raw_fif(op.join(io_dir, 'tests', 'data',
'test_chpi_raw_sss.fif'), add_eeg_ref=False)
assert_equal(len(pick_types(raw.info, meg=False, seeg=True, ecog=True)), 0)
开发者ID:jmontoyam,项目名称:mne-python,代码行数:25,代码来源:test_pick.py
示例12: test_cov_mismatch
def test_cov_mismatch():
"""Test estimation with MEG<->Head mismatch."""
raw = read_raw_fif(raw_fname, add_eeg_ref=False).crop(0, 5).load_data()
events = find_events(raw, stim_channel="STI 014")
raw.pick_channels(raw.ch_names[:5])
raw.add_proj([], remove_existing=True)
epochs = Epochs(raw, events, None, tmin=-0.2, tmax=0.0, preload=True, add_eeg_ref=False)
for kind in ("shift", "None"):
epochs_2 = epochs.copy()
# This should be fine
with warnings.catch_warnings(record=True) as w:
compute_covariance([epochs, epochs_2])
assert_equal(len(w), 0)
if kind == "shift":
epochs_2.info["dev_head_t"]["trans"][:3, 3] += 0.001
else: # None
epochs_2.info["dev_head_t"] = None
assert_raises(ValueError, compute_covariance, [epochs, epochs_2])
assert_equal(len(w), 0)
compute_covariance([epochs, epochs_2], on_mismatch="ignore")
assert_equal(len(w), 0)
compute_covariance([epochs, epochs_2], on_mismatch="warn")
assert_raises(ValueError, compute_covariance, epochs, on_mismatch="x")
assert_true(any("transform mismatch" in str(ww.message) for ww in w))
# This should work
epochs.info["dev_head_t"] = None
epochs_2.info["dev_head_t"] = None
compute_covariance([epochs, epochs_2], method=None)
开发者ID:joewalter,项目名称:mne-python,代码行数:28,代码来源:test_cov.py
示例13: test_cov_mismatch
def test_cov_mismatch():
"""Test estimation with MEG<->Head mismatch."""
raw = read_raw_fif(raw_fname).crop(0, 5).load_data()
events = find_events(raw, stim_channel='STI 014')
raw.pick_channels(raw.ch_names[:5])
raw.add_proj([], remove_existing=True)
epochs = Epochs(raw, events, None, tmin=-0.2, tmax=0., preload=True)
for kind in ('shift', 'None'):
epochs_2 = epochs.copy()
# This should be fine
compute_covariance([epochs, epochs_2])
if kind == 'shift':
epochs_2.info['dev_head_t']['trans'][:3, 3] += 0.001
else: # None
epochs_2.info['dev_head_t'] = None
pytest.raises(ValueError, compute_covariance, [epochs, epochs_2])
compute_covariance([epochs, epochs_2], on_mismatch='ignore')
with pytest.raises(RuntimeWarning, match='transform mismatch'):
compute_covariance([epochs, epochs_2], on_mismatch='warn')
pytest.raises(ValueError, compute_covariance, epochs,
on_mismatch='x')
# This should work
epochs.info['dev_head_t'] = None
epochs_2.info['dev_head_t'] = None
compute_covariance([epochs, epochs_2], method=None)
开发者ID:jhouck,项目名称:mne-python,代码行数:25,代码来源:test_cov.py
示例14: test_scaler
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)
开发者ID:hoechenberger,项目名称:mne-python,代码行数:35,代码来源:test_transformer.py
示例15: test_xdawn_apply_transform
def test_xdawn_apply_transform():
"""Test Xdawn apply and transform."""
# Get data
raw, events, picks = _get_data()
raw.pick_types(eeg=True, meg=False)
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=False,
preload=True, baseline=None,
verbose=False)
n_components = 2
# Fit Xdawn
xd = Xdawn(n_components=n_components, correct_overlap=False)
xd.fit(epochs)
# Apply on different types of instances
for inst in [raw, epochs.average(), epochs]:
denoise = xd.apply(inst)
# Apply on other thing should raise an error
assert_raises(ValueError, xd.apply, 42)
# Transform on epochs
xd.transform(epochs)
# Transform on ndarray
xd.transform(epochs._data)
# Transform on someting else
assert_raises(ValueError, xd.transform, 42)
# Check numerical results with shuffled epochs
np.random.seed(0) # random makes unstable linalg
idx = np.arange(len(epochs))
np.random.shuffle(idx)
xd.fit(epochs[idx])
denoise_shfl = xd.apply(epochs)
assert_array_almost_equal(denoise['cond2']._data,
denoise_shfl['cond2']._data)
开发者ID:deep-introspection,项目名称:mne-python,代码行数:34,代码来源:test_xdawn.py
示例16: test_filterestimator
def test_filterestimator():
"""Test methods of FilterEstimator
"""
raw = io.Raw(raw_fname, preload=False)
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()
# Add tests for different combinations of l_freq and h_freq
filt = FilterEstimator(epochs.info, l_freq=1, h_freq=40)
y = epochs.events[:, -1]
with warnings.catch_warnings(record=True): # stop freq attenuation warning
X = filt.fit_transform(epochs_data, y)
assert_true(X.shape == epochs_data.shape)
assert_array_equal(filt.fit(epochs_data, y).transform(epochs_data), X)
filt = FilterEstimator(epochs.info, l_freq=0, h_freq=40)
y = epochs.events[:, -1]
with warnings.catch_warnings(record=True): # stop freq attenuation warning
X = filt.fit_transform(epochs_data, y)
filt = FilterEstimator(epochs.info, l_freq=1, h_freq=1)
y = epochs.events[:, -1]
with warnings.catch_warnings(record=True): # stop freq attenuation warning
assert_raises(ValueError, filt.fit_transform, epochs_data, y)
filt = FilterEstimator(epochs.info, l_freq=1, h_freq=None)
with warnings.catch_warnings(record=True): # stop freq attenuation warning
X = filt.fit_transform(epochs_data, y)
# Test init exception
assert_raises(ValueError, filt.fit, epochs, y)
assert_raises(ValueError, filt.transform, epochs, y)
开发者ID:rajul,项目名称:mne-python,代码行数:35,代码来源:test_transformer.py
示例17: test_ems
def test_ems():
"""Test event-matched spatial filters"""
raw = io.read_raw_fif(raw_fname, preload=False)
# create unequal number of events
events = read_events(event_name)
events[-2, 2] = 3
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)
assert_raises(ValueError, compute_ems, epochs, ['aud_l', 'vis_l'])
epochs = epochs.equalize_event_counts(epochs.event_id, copy=False)[0]
assert_raises(KeyError, compute_ems, epochs, ['blah', 'hahah'])
surrogates, filters, conditions = compute_ems(epochs)
assert_equal(list(set(conditions)), [1, 3])
events = read_events(event_name)
event_id2 = dict(aud_l=1, aud_r=2, vis_l=3)
epochs = Epochs(raw, events, event_id2, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
epochs = epochs.equalize_event_counts(epochs.event_id, copy=False)[0]
n_expected = sum([len(epochs[k]) for k in ['aud_l', 'vis_l']])
assert_raises(ValueError, compute_ems, epochs)
surrogates, filters, conditions = compute_ems(epochs, ['aud_r', 'vis_l'])
assert_equal(n_expected, len(surrogates))
assert_equal(n_expected, len(conditions))
assert_equal(list(set(conditions)), [2, 3])
raw.close()
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:33,代码来源:test_ems.py
示例18: test_csp
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)
开发者ID:Anevar,项目名称:mne-python,代码行数:33,代码来源:test_csp.py
示例19: test_acqparser_averaging
def test_acqparser_averaging():
"""Test averaging with AcqParserFIF vs. Elekta software."""
raw = read_raw_fif(fname_raw_elekta, preload=True)
acqp = AcqParserFIF(raw.info)
for cat in acqp.categories:
# XXX datasets match only when baseline is applied to both,
# not sure where relative dc shift comes from
cond = acqp.get_condition(raw, cat)
eps = Epochs(raw, baseline=(-.05, 0), **cond)
ev = eps.average()
ev_ref = read_evokeds(fname_ave_elekta, cat['comment'],
baseline=(-.05, 0), proj=False)
ev_mag = ev.copy()
ev_mag.pick_channels(['MEG0111'])
ev_grad = ev.copy()
ev_grad.pick_channels(['MEG2643', 'MEG1622'])
ev_ref_mag = ev_ref.copy()
ev_ref_mag.pick_channels(['MEG0111'])
ev_ref_grad = ev_ref.copy()
ev_ref_grad.pick_channels(['MEG2643', 'MEG1622'])
assert_allclose(ev_mag.data, ev_ref_mag.data,
rtol=0, atol=1e-15) # tol = 1 fT
# Elekta put these in a different order
assert ev_grad.ch_names[::-1] == ev_ref_grad.ch_names
assert_allclose(ev_grad.data[::-1], ev_ref_grad.data,
rtol=0, atol=1e-13) # tol = 1 fT/cm
开发者ID:kambysese,项目名称:mne-python,代码行数:26,代码来源:test_event.py
示例20: test_concatenatechannels
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)
开发者ID:Anevar,项目名称:mne-python,代码行数:29,代码来源:test_classifier.py
注:本文中的mne.Epochs类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论