本文整理汇总了Python中mne.read_events函数的典型用法代码示例。如果您正苦于以下问题:Python read_events函数的具体用法?Python read_events怎么用?Python read_events使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_events函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_ems
def test_ems():
"""Test event-matched spatial filters"""
raw = io.Raw(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.equalize_event_counts(epochs.event_id, copy=False)
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.equalize_event_counts(epochs.event_id, copy=False)
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:BushraR,项目名称:mne-python,代码行数:33,代码来源:test_ems.py
示例2: test_io_events
def test_io_events():
"""Test IO for events
"""
events = mne.read_events(fname)
mne.write_events('events.fif', events)
events2 = mne.read_events('events.fif')
assert_array_almost_equal(events, events2)
开发者ID:emilyruzich,项目名称:mne-python,代码行数:7,代码来源:test_event.py
示例3: test_info
def test_info():
"""Test info object"""
raw = io.Raw(raw_fname)
event_id, tmin, tmax = 1, -0.2, 0.5
events = read_events(event_name)
event_id = int(events[0, 2])
epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
baseline=(None, 0))
evoked = epochs.average()
events = read_events(event_name)
# Test subclassing was successful.
info = Info(a=7, b='aaaaa')
assert_true('a' in info)
assert_true('b' in info)
info[42] = 'foo'
assert_true(info[42] == 'foo')
# test info attribute in API objects
for obj in [raw, epochs, evoked]:
assert_true(isinstance(obj.info, Info))
info_str = '%s' % obj.info
assert_equal(len(info_str.split('\n')), (len(obj.info.keys()) + 2))
assert_true(all(k in info_str for k in obj.info.keys()))
开发者ID:agramfort,项目名称:mne-python,代码行数:26,代码来源:test_meas_info.py
示例4: test_io_cov
def test_io_cov():
"""Test IO for noise covariance matrices
"""
events = mne.read_events(fname)
mne.write_events('events.fif', events)
events2 = mne.read_events(fname)
assert_array_almost_equal(events, events2)
开发者ID:arokem,项目名称:mne-python,代码行数:7,代码来源:test_event.py
示例5: test_info
def test_info():
"""Test info object"""
raw = Raw(raw_fname)
event_id, tmin, tmax = 1, -0.2, 0.5
events = read_events(event_name)
event_id = int(events[0, 2])
epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None,
baseline=(None, 0))
evoked = epochs.average()
events = read_events(event_name)
# Test subclassing was successful.
info = Info(a=7, b='aaaaa')
assert_true('a' in info)
assert_true('b' in info)
info[42] = 'foo'
assert_true(info[42] == 'foo')
# Test info attribute in API objects
for obj in [raw, epochs, evoked]:
assert_true(isinstance(obj.info, Info))
info_str = '%s' % obj.info
assert_equal(len(info_str.split('\n')), len(obj.info.keys()) + 2)
assert_true(all(k in info_str for k in obj.info.keys()))
# Test read-only fields
info = raw.info.copy()
nchan = len(info['chs'])
ch_names = [ch['ch_name'] for ch in info['chs']]
assert_equal(info['nchan'], nchan)
assert_equal(list(info['ch_names']), ch_names)
# Deleting of regular fields should work
info['foo'] = 'bar'
del info['foo']
# Test updating of fields
del info['chs'][-1]
info._update_redundant()
assert_equal(info['nchan'], nchan - 1)
assert_equal(list(info['ch_names']), ch_names[:-1])
info['chs'][0]['ch_name'] = 'foo'
info._update_redundant()
assert_equal(info['ch_names'][0], 'foo')
# Test casting to and from a dict
info_dict = dict(info)
info2 = Info(info_dict)
assert_equal(info, info2)
开发者ID:esdalmaijer,项目名称:mne-python,代码行数:52,代码来源:test_meas_info.py
示例6: test_info
def test_info():
"""Test info object."""
raw = read_raw_fif(raw_fname)
event_id, tmin, tmax = 1, -0.2, 0.5
events = read_events(event_name)
event_id = int(events[0, 2])
epochs = Epochs(raw, events[:1], event_id, tmin, tmax, picks=None, baseline=(None, 0))
evoked = epochs.average()
events = read_events(event_name)
# Test subclassing was successful.
info = Info(a=7, b="aaaaa")
assert_true("a" in info)
assert_true("b" in info)
info[42] = "foo"
assert_true(info[42] == "foo")
# Test info attribute in API objects
for obj in [raw, epochs, evoked]:
assert_true(isinstance(obj.info, Info))
info_str = "%s" % obj.info
assert_equal(len(info_str.split("\n")), len(obj.info.keys()) + 2)
assert_true(all(k in info_str for k in obj.info.keys()))
# Test read-only fields
info = raw.info.copy()
nchan = len(info["chs"])
ch_names = [ch["ch_name"] for ch in info["chs"]]
assert_equal(info["nchan"], nchan)
assert_equal(list(info["ch_names"]), ch_names)
# Deleting of regular fields should work
info["foo"] = "bar"
del info["foo"]
# Test updating of fields
del info["chs"][-1]
info._update_redundant()
assert_equal(info["nchan"], nchan - 1)
assert_equal(list(info["ch_names"]), ch_names[:-1])
info["chs"][0]["ch_name"] = "foo"
info._update_redundant()
assert_equal(info["ch_names"][0], "foo")
# Test casting to and from a dict
info_dict = dict(info)
info2 = Info(info_dict)
assert_equal(info, info2)
开发者ID:mne-tools,项目名称:mne-python,代码行数:51,代码来源:test_meas_info.py
示例7: 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
示例8: 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
示例9: _get_data
def _get_data(tmin=-0.2, tmax=0.5, event_id=dict(aud_l=1, vis_l=3),
event_id_gen=dict(aud_l=2, vis_l=4), test_times=None):
"""Aux function for testing GAT viz."""
with warnings.catch_warnings(record=True): # deprecated
gat = GeneralizationAcrossTime()
raw = read_raw_fif(raw_fname)
raw.add_proj([], remove_existing=True)
events = read_events(event_name)
picks = pick_types(raw.info, meg='mag', stim=False, ecg=False,
eog=False, exclude='bads')
picks = picks[1:13:3]
decim = 30
# Test on time generalization within one condition
with warnings.catch_warnings(record=True):
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
preload=True, decim=decim)
epochs_list = [epochs[k] for k in event_id]
equalize_epoch_counts(epochs_list)
epochs = concatenate_epochs(epochs_list)
# Test default running
with warnings.catch_warnings(record=True): # deprecated
gat = GeneralizationAcrossTime(test_times=test_times)
gat.fit(epochs)
gat.score(epochs)
return gat
开发者ID:nfoti,项目名称:mne-python,代码行数:26,代码来源:test_decoding.py
示例10: test_unsupervised_spatial_filter
def test_unsupervised_spatial_filter():
"""Test unsupervised spatial filter."""
from sklearn.decomposition import PCA
from sklearn.kernel_ridge import KernelRidge
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,
preload=True, baseline=None, verbose=False)
# Test estimator
assert_raises(ValueError, UnsupervisedSpatialFilter, KernelRidge(2))
# Test fit
X = epochs.get_data()
n_components = 4
usf = UnsupervisedSpatialFilter(PCA(n_components))
usf.fit(X)
usf1 = UnsupervisedSpatialFilter(PCA(n_components))
# test transform
assert_equal(usf.transform(X).ndim, 3)
# test fit_transform
assert_array_almost_equal(usf.transform(X), usf1.fit_transform(X))
# assert shape
assert_equal(usf.transform(X).shape[1], n_components)
# Test with average param
usf = UnsupervisedSpatialFilter(PCA(4), average=True)
usf.fit_transform(X)
assert_raises(ValueError, UnsupervisedSpatialFilter, PCA(4), 2)
开发者ID:Hugo-W,项目名称:mne-python,代码行数:33,代码来源:test_transformer.py
示例11: _get_data
def _get_data():
# Read raw data
raw = Raw(raw_fname)
raw.info['bads'] = ['MEG 2443', 'EEG 053'] # 2 bads channels
# Set picks
picks = mne.pick_types(raw.info, meg=True, eeg=False, eog=False,
stim=False, exclude='bads')
# Read several epochs
event_id, tmin, tmax = 1, -0.2, 0.5
events = mne.read_events(event_fname)[0:100]
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=picks, baseline=(None, 0), preload=True,
reject=dict(grad=4000e-13, mag=4e-12))
# Create an epochs object with one epoch and one channel of artificial data
event_id, tmin, tmax = 1, 0.0, 1.0
epochs_sin = mne.Epochs(raw, events[0:5], event_id, tmin, tmax, proj=True,
picks=[0], baseline=(None, 0), preload=True,
reject=dict(grad=4000e-13))
freq = 10
epochs_sin._data = np.sin(2 * np.pi * freq
* epochs_sin.times)[None, None, :]
return epochs, epochs_sin
开发者ID:anywave,项目名称:aw-export-fif,代码行数:25,代码来源:test_csd.py
示例12: test_n_components_and_max_pca_components_none
def test_n_components_and_max_pca_components_none(method):
"""Test n_components and max_pca_components=None."""
_skip_check_picard(method)
raw = read_raw_fif(raw_fname).crop(1.5, stop).load_data()
events = read_events(event_name)
picks = pick_types(raw.info, eeg=True, meg=False)
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), preload=True)
max_pca_components = None
n_components = None
random_state = 12345
tempdir = _TempDir()
output_fname = op.join(tempdir, 'test_ica-ica.fif')
ica = ICA(max_pca_components=max_pca_components, method=method,
n_components=n_components, random_state=random_state)
with pytest.warns(None): # convergence
ica.fit(epochs)
ica.save(output_fname)
ica = read_ica(output_fname)
# ICA.fit() replaced max_pca_components, which was previously None,
# with the appropriate integer value.
assert_equal(ica.max_pca_components, epochs.info['nchan'])
assert ica.n_components is None
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:27,代码来源:test_ica.py
示例13: test_continuous_regression_no_overlap
def test_continuous_regression_no_overlap():
"""Test regression without overlap correction, on real data."""
tmin, tmax = -.1, .5
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.apply_proj()
events = mne.read_events(event_fname)
event_id = dict(audio_l=1, audio_r=2)
raw = raw.pick_channels(raw.ch_names[:2])
epochs = mne.Epochs(raw, events, event_id, tmin, tmax,
baseline=None, reject=None)
revokeds = linear_regression_raw(raw, events, event_id,
tmin=tmin, tmax=tmax,
reject=None)
# Check that evokeds and revokeds are nearly equivalent
for cond in event_id.keys():
assert_allclose(revokeds[cond].data,
epochs[cond].average().data, rtol=1e-15)
# Test events that will lead to "duplicate" errors
old_latency = events[1, 0]
events[1, 0] = events[0, 0]
assert_raises(ValueError, linear_regression_raw,
raw, events, event_id, tmin, tmax)
events[1, 0] = old_latency
events[:, 0] = range(len(events))
assert_raises(ValueError, linear_regression_raw, raw,
events, event_id, tmin, tmax, decim=2)
开发者ID:nfoti,项目名称:mne-python,代码行数:33,代码来源:test_regression.py
示例14: test_epochs_vectorizer
def test_epochs_vectorizer():
"""Test methods of EpochsVectorizer
"""
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]
with warnings.catch_warnings(record=True):
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks, baseline=(None, 0), preload=True)
epochs_data = epochs.get_data()
vector = EpochsVectorizer(epochs.info)
y = epochs.events[:, -1]
X = vector.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(vector.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])
# Check inverse transform
Xi = vector.inverse_transform(X, y)
assert_true(Xi.shape[0] == epochs_data.shape[0])
assert_true(Xi.shape[1] == epochs_data.shape[1])
assert_array_equal(epochs_data[0, 0, 0:n_times], Xi[0, 0, 0:n_times])
# Test init exception
assert_raises(ValueError, vector.fit, epochs, y)
assert_raises(ValueError, vector.transform, epochs, y)
开发者ID:rajul,项目名称:mne-python,代码行数:33,代码来源:test_transformer.py
示例15: _get_data
def _get_data():
raw = io.Raw(raw_fname, add_eeg_ref=False)
events = read_events(event_name)
picks = pick_types(raw.info, meg=True, eeg=True, stim=True,
ecg=True, eog=True, include=['STI 014'],
exclude='bads')
return raw, events, picks
开发者ID:MadsJensen,项目名称:mne-python,代码行数:7,代码来源:test_epochs.py
示例16: _load_data
def _load_data():
"""Helper function to load data."""
# It is more memory efficient to load data in a separate
# function so it's loaded on-demand
raw = io.read_raw_fif(raw_fname, add_eeg_ref=False)
events = read_events(event_name)
picks_eeg = pick_types(raw.info, meg=False, eeg=True, exclude=[])
# select every second channel for faster speed but compensate by using
# mode='accurate'.
picks_meg = pick_types(raw.info, meg=True, eeg=False, exclude=[])[1::2]
picks = pick_types(raw.info, meg=True, eeg=True, exclude=[])
with warnings.catch_warnings(record=True): # proj
epochs_eeg = Epochs(raw, events, event_id, tmin, tmax, picks=picks_eeg, preload=True, reject=dict(eeg=80e-6))
epochs_meg = Epochs(
raw, events, event_id, tmin, tmax, picks=picks_meg, preload=True, reject=dict(grad=1000e-12, mag=4e-12)
)
epochs = Epochs(
raw,
events,
event_id,
tmin,
tmax,
picks=picks,
preload=True,
reject=dict(eeg=80e-6, grad=1000e-12, mag=4e-12),
)
return raw, epochs, epochs_eeg, epochs_meg
开发者ID:mmagnuski,项目名称:mne-python,代码行数:28,代码来源:test_interpolation.py
示例17: test_stockwell_api
def test_stockwell_api():
"""Test stockwell functions."""
raw = read_raw_fif(raw_fname)
event_id, tmin, tmax = 1, -0.2, 0.5
event_name = op.join(base_dir, 'test-eve.fif')
events = read_events(event_name)
epochs = Epochs(raw, events, # XXX pick 2 has epochs of zeros.
event_id, tmin, tmax, picks=[0, 1, 3])
for fmin, fmax in [(None, 50), (5, 50), (5, None)]:
with warnings.catch_warnings(record=True): # zero papdding
power, itc = tfr_stockwell(epochs, fmin=fmin, fmax=fmax,
return_itc=True)
if fmax is not None:
assert_true(power.freqs.max() <= fmax)
with warnings.catch_warnings(record=True): # padding
power_evoked = tfr_stockwell(epochs.average(), fmin=fmin,
fmax=fmax, return_itc=False)
# for multitaper these don't necessarily match, but they seem to
# for stockwell... if this fails, this maybe could be changed
# just to check the shape
assert_array_almost_equal(power_evoked.data, power.data)
assert_true(isinstance(power, AverageTFR))
assert_true(isinstance(itc, AverageTFR))
assert_equal(power.data.shape, itc.data.shape)
assert_true(itc.data.min() >= 0.0)
assert_true(itc.data.max() <= 1.0)
assert_true(np.log(power.data.max()) * 20 <= 0.0)
assert_true(np.log(power.data.max()) * 20 <= 0.0)
开发者ID:HSMin,项目名称:mne-python,代码行数:28,代码来源:test_stockwell.py
示例18: _get_data
def _get_data():
raw = io.read_raw_fif(raw_fname, add_eeg_ref=False, verbose=False,
preload=True)
events = read_events(event_name)
picks = pick_types(raw.info, meg=False, eeg=True, stim=False,
ecg=False, eog=False, exclude='bads')[::8]
return raw, events, picks
开发者ID:EmanuelaLiaci,项目名称:mne-python,代码行数:7,代码来源:test_xdawn.py
示例19: test_find_events
def test_find_events():
"""Test find events in raw file
"""
events = mne.read_events(fname)
raw = mne.fiff.Raw(raw_fname)
events2 = mne.find_events(raw)
assert_array_almost_equal(events, events2)
开发者ID:emilyruzich,项目名称:mne-python,代码行数:7,代码来源: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.read_events函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论