本文整理汇总了Python中mne.evoked.EvokedArray类的典型用法代码示例。如果您正苦于以下问题:Python EvokedArray类的具体用法?Python EvokedArray怎么用?Python EvokedArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EvokedArray类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_evoked_arithmetic
def test_evoked_arithmetic():
"""Test evoked arithmetic
"""
ev = read_evokeds(fname, condition=0)
ev1 = EvokedArray(np.ones_like(ev.data), ev.info, ev.times[0], nave=20)
ev2 = EvokedArray(-np.ones_like(ev.data), ev.info, ev.times[0], nave=10)
# combine_evoked([ev1, ev2]) should be the same as ev1 + ev2:
# data should be added according to their `nave` weights
# nave = ev1.nave + ev2.nave
ev = ev1 + ev2
assert_equal(ev.nave, ev1.nave + ev2.nave)
assert_allclose(ev.data, 1. / 3. * np.ones_like(ev.data))
ev = ev1 - ev2
assert_equal(ev.nave, ev1.nave + ev2.nave)
assert_equal(ev.comment, ev1.comment + ' - ' + ev2.comment)
assert_allclose(ev.data, np.ones_like(ev1.data))
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
ev = merge_evoked([ev1, ev2])
assert_true(len(w) >= 1)
assert_allclose(ev.data, 1. / 3. * np.ones_like(ev.data))
# default comment behavior if evoked.comment is None
old_comment1 = ev1.comment
old_comment2 = ev2.comment
ev1.comment = None
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
ev = ev1 - ev2
assert_equal(ev.comment, 'unknown')
ev1.comment = old_comment1
ev2.comment = old_comment2
# equal weighting
ev = combine_evoked([ev1, ev2], weights='equal')
assert_allclose(ev.data, np.zeros_like(ev1.data))
# combine_evoked([ev1, ev2], weights=[1, 0]) should yield the same as ev1
ev = combine_evoked([ev1, ev2], weights=[1, 0])
assert_equal(ev.nave, ev1.nave)
assert_allclose(ev.data, ev1.data)
# simple subtraction (like in oddball)
ev = combine_evoked([ev1, ev2], weights=[1, -1])
assert_allclose(ev.data, 2 * np.ones_like(ev1.data))
assert_raises(ValueError, combine_evoked, [ev1, ev2], weights='foo')
assert_raises(ValueError, combine_evoked, [ev1, ev2], weights=[1])
# grand average
evoked1, evoked2 = read_evokeds(fname, condition=[0, 1], proj=True)
ch_names = evoked1.ch_names[2:]
evoked1.info['bads'] = ['EEG 008'] # test interpolation
evoked1.drop_channels(evoked1.ch_names[:1])
evoked2.drop_channels(evoked2.ch_names[1:2])
gave = grand_average([evoked1, evoked2])
assert_equal(gave.data.shape, [len(ch_names), evoked1.data.shape[1]])
assert_equal(ch_names, gave.ch_names)
assert_equal(gave.nave, 2)
示例2: test_evoked_baseline
def test_evoked_baseline():
"""Test evoked baseline."""
evoked = read_evokeds(fname, condition=0, baseline=None)
# Here we create a data_set with constant data.
evoked = EvokedArray(np.ones_like(evoked.data), evoked.info,
evoked.times[0])
# Mean baseline correction is applied, since the data is equal to its mean
# the resulting data should be a matrix of zeroes.
evoked.apply_baseline((None, None))
assert_allclose(evoked.data, np.zeros_like(evoked.data))
示例3: test_array_epochs
def test_array_epochs():
"""Test creating evoked from array."""
tempdir = _TempDir()
# creating
rng = np.random.RandomState(42)
data1 = rng.randn(20, 60)
sfreq = 1e3
ch_names = ['EEG %03d' % (i + 1) for i in range(20)]
types = ['eeg'] * 20
info = create_info(ch_names, sfreq, types)
evoked1 = EvokedArray(data1, info, tmin=-0.01)
# save, read, and compare evokeds
tmp_fname = op.join(tempdir, 'evkdary-ave.fif')
evoked1.save(tmp_fname)
evoked2 = read_evokeds(tmp_fname)[0]
data2 = evoked2.data
assert_allclose(data1, data2)
assert_allclose(evoked1.times, evoked2.times)
assert_equal(evoked1.first, evoked2.first)
assert_equal(evoked1.last, evoked2.last)
assert_equal(evoked1.kind, evoked2.kind)
assert_equal(evoked1.nave, evoked2.nave)
# now compare with EpochsArray (with single epoch)
data3 = data1[np.newaxis, :, :]
events = np.c_[10, 0, 1]
evoked3 = EpochsArray(data3, info, events=events, tmin=-0.01).average()
assert_allclose(evoked1.data, evoked3.data)
assert_allclose(evoked1.times, evoked3.times)
assert_equal(evoked1.first, evoked3.first)
assert_equal(evoked1.last, evoked3.last)
assert_equal(evoked1.kind, evoked3.kind)
assert_equal(evoked1.nave, evoked3.nave)
# test kind check
with pytest.raises(ValueError, match='Invalid value'):
EvokedArray(data1, info, tmin=0, kind=1)
with pytest.raises(ValueError, match='Invalid value'):
EvokedArray(data1, info, kind='mean')
# test match between channels info and data
ch_names = ['EEG %03d' % (i + 1) for i in range(19)]
types = ['eeg'] * 19
info = create_info(ch_names, sfreq, types)
pytest.raises(ValueError, EvokedArray, data1, info, tmin=-0.01)
示例4: test_arithmetic
def test_arithmetic():
"""Test evoked arithmetic."""
ev = read_evokeds(fname, condition=0)
ev1 = EvokedArray(np.ones_like(ev.data), ev.info, ev.times[0], nave=20)
ev2 = EvokedArray(-np.ones_like(ev.data), ev.info, ev.times[0], nave=10)
# combine_evoked([ev1, ev2]) should be the same as ev1 + ev2:
# data should be added according to their `nave` weights
# nave = ev1.nave + ev2.nave
ev = combine_evoked([ev1, ev2], weights='nave')
assert_equal(ev.nave, ev1.nave + ev2.nave)
assert_allclose(ev.data, 1. / 3. * np.ones_like(ev.data))
# with same trial counts, a bunch of things should be equivalent
for weights in ('nave', 'equal', [0.5, 0.5]):
ev = combine_evoked([ev1, ev1], weights=weights)
assert_allclose(ev.data, ev1.data)
assert_equal(ev.nave, 2 * ev1.nave)
ev = combine_evoked([ev1, -ev1], weights=weights)
assert_allclose(ev.data, 0., atol=1e-20)
assert_equal(ev.nave, 2 * ev1.nave)
ev = combine_evoked([ev1, -ev1], weights='equal')
assert_allclose(ev.data, 0., atol=1e-20)
assert_equal(ev.nave, 2 * ev1.nave)
ev = combine_evoked([ev1, -ev2], weights='equal')
expected = int(round(1. / (0.25 / ev1.nave + 0.25 / ev2.nave)))
assert_equal(expected, 27) # this is reasonable
assert_equal(ev.nave, expected)
# default comment behavior if evoked.comment is None
old_comment1 = ev1.comment
old_comment2 = ev2.comment
ev1.comment = None
ev = combine_evoked([ev1, -ev2], weights=[1, -1])
assert_equal(ev.comment.count('unknown'), 2)
assert_true('-unknown' in ev.comment)
assert_true(' + ' in ev.comment)
ev1.comment = old_comment1
ev2.comment = old_comment2
# equal weighting
ev = combine_evoked([ev1, ev2], weights='equal')
assert_allclose(ev.data, np.zeros_like(ev1.data))
# combine_evoked([ev1, ev2], weights=[1, 0]) should yield the same as ev1
ev = combine_evoked([ev1, ev2], weights=[1, 0])
assert_equal(ev.nave, ev1.nave)
assert_allclose(ev.data, ev1.data)
# simple subtraction (like in oddball)
ev = combine_evoked([ev1, ev2], weights=[1, -1])
assert_allclose(ev.data, 2 * np.ones_like(ev1.data))
assert_raises(ValueError, combine_evoked, [ev1, ev2], weights='foo')
assert_raises(ValueError, combine_evoked, [ev1, ev2], weights=[1])
# grand average
evoked1, evoked2 = read_evokeds(fname, condition=[0, 1], proj=True)
ch_names = evoked1.ch_names[2:]
evoked1.info['bads'] = ['EEG 008'] # test interpolation
evoked1.drop_channels(evoked1.ch_names[:1])
evoked2.drop_channels(evoked2.ch_names[1:2])
gave = grand_average([evoked1, evoked2])
assert_equal(gave.data.shape, [len(ch_names), evoked1.data.shape[1]])
assert_equal(ch_names, gave.ch_names)
assert_equal(gave.nave, 2)
assert_raises(ValueError, grand_average, [1, evoked1])
示例5: len
from mne.io.meas_info import create_info
print data.shape
sfreq = d['sfreq']
ch_names = layout.names
print ch_names
types = ['mag'] * len(ch_names)
info = create_info(ch_names, sfreq, types)
events = np.vstack(zip([125 for _ in xrange(len(labels))], [0 for _ in xrange(len(labels))], labels))
print events.shape
#help(EpochsArray)
ea = EpochsArray(data, info, events, tmin=d['tmin'])
from mne.evoked import EvokedArray
evoked = EvokedArray(data[labels==1].mean(axis=0), info, tmin=d['tmin'])
print evoked
print info
times = np.arange(0.05, 0.15, 0.01)
print len(info['ch_names'])
evoked.plot_topomap(0.15, ch_type='mag', layout=layout, size=10, colorbar=False)
#evoked.plot_topomap(times, ch_type='mag', layout=layout, size=10, colorbar=False)
evoked = EvokedArray(data[labels==0].mean(axis=0), info, tmin=d['tmin'])
evoked.plot_topomap(0.15, ch_type='mag', layout=layout, size=10, colorbar=False)
#evoked.plot_topomap(times, ch_type='mag', layout=layout, size=10, colorbar=False)
evoked = EvokedArray(data[labels==1].mean(axis=0) - data[labels==0].mean(axis=0), info, tmin=d['tmin'])
evoked.plot_topomap(0.25, ch_type='mag', layout=layout, size=10, colorbar=False)