本文整理汇总了Python中mne.fiff.read_evoked函数的典型用法代码示例。如果您正苦于以下问题:Python read_evoked函数的具体用法?Python read_evoked怎么用?Python read_evoked使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_evoked函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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()]
fiff.write_evoked(op.join(tempdir, 'evoked.fif'), evoked)
evoked2 = read_evoked(op.join(tempdir, 'evoked.fif'), [0, 1])
evoked3 = [read_evoked(op.join(tempdir, 'evoked.fif'), 'Unknown'),
read_evoked(op.join(tempdir, 'evoked.fif'), 'Unknown',
kind='standard_error')]
for evoked_new in [evoked2, evoked3]:
assert_true(evoked_new[0]._aspect_kind ==
fiff.FIFF.FIFFV_ASPECT_AVERAGE)
assert_true(evoked_new[0].kind == 'average')
assert_true(evoked_new[1]._aspect_kind ==
fiff.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)
示例2: test_evoked_proj
def test_evoked_proj():
"""Test SSP proj operations
"""
for proj in [True, False]:
ave = read_evoked(fname, setno=0, proj=proj)
assert_true(all(p['active'] == proj for p in ave.info['projs']))
# test adding / deleting proj
if proj:
assert_raises(ValueError, ave.add_proj, [],
{'remove_existing': True})
assert_raises(ValueError, ave.del_proj, 0)
else:
projs = deepcopy(ave.info['projs'])
n_proj = len(ave.info['projs'])
ave.del_proj(0)
assert_true(len(ave.info['projs']) == n_proj - 1)
ave.add_proj(projs, remove_existing=False)
assert_true(len(ave.info['projs']) == 2 * n_proj - 1)
ave.add_proj(projs, remove_existing=True)
assert_true(len(ave.info['projs']) == n_proj)
ave = read_evoked(fname, setno=0, proj=False)
data = ave.data.copy()
ave.apply_proj()
assert_allclose(np.dot(ave._projector, data), ave.data)
示例3: test_evoked_resample
def test_evoked_resample():
"""Test for resampling of evoked data
"""
# upsample, write it out, read it in
ave = read_evoked(fname, 0)
sfreq_normal = ave.info['sfreq']
ave.resample(2 * sfreq_normal)
write_evoked(op.join(tempdir, 'evoked.fif'), ave)
ave_up = read_evoked(op.join(tempdir, 'evoked.fif'), 0)
# compare it to the original
ave_normal = read_evoked(fname, 0)
# and compare the original to the downsampled upsampled version
ave_new = read_evoked(op.join(tempdir, 'evoked.fif'), 0)
ave_new.resample(sfreq_normal)
assert_array_almost_equal(ave_normal.data, ave_new.data, 2)
assert_array_almost_equal(ave_normal.times, ave_new.times)
assert_equal(ave_normal.nave, ave_new.nave)
assert_equal(ave_normal._aspect_kind, ave_new._aspect_kind)
assert_equal(ave_normal.kind, ave_new.kind)
assert_equal(ave_normal.last, ave_new.last)
assert_equal(ave_normal.first, ave_new.first)
# for the above to work, the upsampling just about had to, but
# we'll add a couple extra checks anyway
assert_true(len(ave_up.times) == 2 * len(ave_normal.times))
assert_true(ave_up.data.shape[1] == 2 * ave_normal.data.shape[1])
示例4: test_io_evoked
def test_io_evoked():
"""Test IO for evoked data (fif + gz) with integer and str args
"""
ave = read_evoked(fname, 0)
write_evoked(op.join(tempdir, 'evoked.fif'), ave)
ave2 = read_evoked(op.join(tempdir, 'evoked.fif'))
# This not being assert_array_equal due to windows rounding
assert_true(np.allclose(ave.data, ave2.data, atol=1e-16, rtol=1e-3))
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)
# test compressed i/o
ave2 = read_evoked(fname_gz, 0)
assert_true(np.allclose(ave.data, ave2.data, atol=1e-16, rtol=1e-8))
# test str access
setno = 'Left Auditory'
assert_raises(ValueError, read_evoked, fname, setno, kind='stderr')
assert_raises(ValueError, read_evoked, fname, setno, kind='standard_error')
ave3 = read_evoked(fname, setno)
assert_array_almost_equal(ave.data, ave3.data, 19)
示例5: test_evoked_to_nitime
def test_evoked_to_nitime():
""" Test to_nitime """
aves = read_evoked(fname, [0, 1, 2, 3])
evoked_ts = aves[0].to_nitime()
assert_equal(evoked_ts.data, aves[0].data)
picks2 = [1, 2]
aves = read_evoked(fname, [0, 1, 2, 3])
evoked_ts = aves[0].to_nitime(picks=picks2)
assert_equal(evoked_ts.data, aves[0].data[picks2])
示例6: test_evoked_detrend
def test_evoked_detrend():
"""Test for detrending evoked data
"""
ave = read_evoked(fname, 0)
ave_normal = read_evoked(fname, 0)
ave.detrend(0)
ave_normal.data -= np.mean(ave_normal.data, axis=1)[:, np.newaxis]
picks = pick_types(ave.info, meg=True, eeg=True, exclude='bads')
assert_true(np.allclose(ave.data[picks], ave_normal.data[picks],
rtol=1e-8, atol=1e-16))
示例7: test_io_multi_evoked
def test_io_multi_evoked():
"""Test IO for multiple evoked datasets
"""
aves = read_evoked(fname, [0, 1, 2, 3])
write_evoked('evoked.fif', aves)
aves2 = read_evoked('evoked.fif', [0, 1, 2, 3])
for [ave, ave2] in zip(aves, aves2):
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.last, ave2.last)
assert_equal(ave.first, ave2.first)
示例8: test_meg_field_interpolation_helmet
def test_meg_field_interpolation_helmet():
"""Test interpolation of MEG field onto helmet
"""
evoked = read_evoked(evoked_fname, setno='Left Auditory')
info = evoked.info
surf = get_meg_helmet_surf(info)
# let's reduce the number of channels by a bunch to speed it up
info['bads'] = info['ch_names'][:200]
# bad ch_type
assert_raises(ValueError, make_surface_mapping, info, surf, 'foo')
# bad mode
assert_raises(ValueError, make_surface_mapping, info, surf, 'meg',
mode='foo')
# no picks
evoked_eeg = pick_types_evoked(evoked, meg=False, eeg=True)
assert_raises(RuntimeError, make_surface_mapping, evoked_eeg.info,
surf, 'meg')
# bad surface def
nn = surf['nn']
del surf['nn']
assert_raises(KeyError, make_surface_mapping, info, surf, 'meg')
surf['nn'] = nn
cf = surf['coord_frame']
del surf['coord_frame']
assert_raises(KeyError, make_surface_mapping, info, surf, 'meg')
surf['coord_frame'] = cf
# now do it
data = make_surface_mapping(info, surf, 'meg', mode='fast')
assert_array_equal(data.shape, (304, 106)) # data onto surf
示例9: test_io_evoked
def test_io_evoked():
"""Test IO for evoked data
"""
ave = read_evoked(fname)
ave.crop(tmin=0)
write_evoked('evoked.fif', ave)
ave2 = read_evoked('evoked.fif')
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.last, ave2.last)
assert_equal(ave.first, ave2.first)
示例10: test_plot_topomap
def test_plot_topomap():
"""Testing topomap plotting
"""
# evoked
evoked = fiff.read_evoked(evoked_fname, 'Left Auditory',
baseline=(None, 0))
evoked.plot_topomap(0.1, 'mag', layout=layout)
plot_evoked_topomap(evoked, None, ch_type='mag')
times = [0.1, 0.2]
plot_evoked_topomap(evoked, times, ch_type='eeg')
plot_evoked_topomap(evoked, times, ch_type='grad')
plot_evoked_topomap(evoked, times, ch_type='planar1')
plot_evoked_topomap(evoked, times, ch_type='planar2')
with warnings.catch_warnings(True): # delaunay triangulation warning
plot_evoked_topomap(evoked, times, ch_type='mag', layout='auto')
assert_raises(RuntimeError, plot_evoked_topomap, evoked, 0.1, 'mag',
proj='interactive') # projs have already been applied
evoked.proj = False # let's fake it like they haven't been applied
plot_evoked_topomap(evoked, 0.1, 'mag', proj='interactive')
assert_raises(RuntimeError, plot_evoked_topomap, evoked, np.repeat(.1, 50))
assert_raises(ValueError, plot_evoked_topomap, evoked, [-3e12, 15e6])
# projs
projs = read_proj(ecg_fname)[:7]
plot_projs_topomap(projs)
plt.close('all')
示例11: test_plot_topomap
def test_plot_topomap():
"""Test topomap plotting
"""
# evoked
warnings.simplefilter('always', UserWarning)
with warnings.catch_warnings(record=True):
evoked = fiff.read_evoked(evoked_fname, 'Left Auditory',
baseline=(None, 0))
evoked.plot_topomap(0.1, 'mag', layout=layout)
plot_evoked_topomap(evoked, None, ch_type='mag')
times = [0.1, 0.2]
plot_evoked_topomap(evoked, times, ch_type='eeg')
plot_evoked_topomap(evoked, times, ch_type='grad')
plot_evoked_topomap(evoked, times, ch_type='planar1')
plot_evoked_topomap(evoked, times, ch_type='planar2')
plot_evoked_topomap(evoked, times, ch_type='grad', show_names=True)
p = plot_evoked_topomap(evoked, times, ch_type='grad',
show_names=lambda x: x.replace('MEG', ''))
subplot = [x for x in p.get_children() if
isinstance(x, matplotlib.axes.Subplot)][0]
assert_true(all('MEG' not in x.get_text()
for x in subplot.get_children()
if isinstance(x, matplotlib.text.Text)))
# Test title
def get_texts(p):
return [x.get_text() for x in p.get_children() if
isinstance(x, matplotlib.text.Text)]
p = plot_evoked_topomap(evoked, times, ch_type='eeg')
assert_equal(len(get_texts(p)), 0)
p = plot_evoked_topomap(evoked, times, ch_type='eeg', title='Custom')
texts = get_texts(p)
assert_equal(len(texts), 1)
assert_equal(texts[0], 'Custom')
# delaunay triangulation warning
with warnings.catch_warnings(record=True):
plot_evoked_topomap(evoked, times, ch_type='mag', layout='auto')
assert_raises(RuntimeError, plot_evoked_topomap, evoked, 0.1, 'mag',
proj='interactive') # projs have already been applied
evoked.proj = False # let's fake it like they haven't been applied
plot_evoked_topomap(evoked, 0.1, 'mag', proj='interactive')
assert_raises(RuntimeError, plot_evoked_topomap, evoked,
np.repeat(.1, 50))
assert_raises(ValueError, plot_evoked_topomap, evoked, [-3e12, 15e6])
projs = read_proj(ecg_fname)
projs = [p for p in projs if p['desc'].lower().find('eeg') < 0]
plot_projs_topomap(projs)
plt.close('all')
for ch in evoked.info['chs']:
if ch['coil_type'] == fiff.FIFF.FIFFV_COIL_EEG:
if ch['eeg_loc'] is not None:
ch['eeg_loc'].fill(0)
ch['loc'].fill(0)
assert_raises(RuntimeError, plot_evoked_topomap, evoked,
times, ch_type='eeg')
示例12: test_drop_channels_mixin
def test_drop_channels_mixin():
"""Test channels-dropping functionality
"""
evoked = read_evoked(fname, setno=0, proj=True)
drop_ch = evoked.ch_names[:3]
ch_names = evoked.ch_names[3:]
evoked.drop_channels(drop_ch)
assert_equal(ch_names, evoked.ch_names)
assert_equal(len(ch_names), len(evoked.data))
示例13: test_io_evoked
def test_io_evoked():
"""Test IO for evoked data (fif + gz) with integer and str args
"""
ave = read_evokeds(fname, 0)
write_evokeds(op.join(tempdir, 'evoked.fif'), ave)
ave2 = read_evokeds(op.join(tempdir, 'evoked.fif'))[0]
# This not being assert_array_equal due to windows rounding
assert_true(np.allclose(ave.data, ave2.data, atol=1e-16, rtol=1e-3))
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)
# test compressed i/o
ave2 = read_evokeds(fname_gz, 0)
assert_true(np.allclose(ave.data, ave2.data, atol=1e-16, rtol=1e-8))
# test str access
condition = 'Left Auditory'
assert_raises(ValueError, read_evokeds, fname, condition, kind='stderr')
assert_raises(ValueError, read_evokeds, fname, condition,
kind='standard_error')
ave3 = read_evokeds(fname, condition)
assert_array_almost_equal(ave.data, ave3.data, 19)
# test deprecation warning for read_evoked and write_evoked
# XXX should be deleted for 0.9 release
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
ave = read_evoked(fname, setno=0)
assert_true(w[0].category == DeprecationWarning)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
write_evoked(op.join(tempdir, 'evoked.fif'), ave)
assert_true(w[0].category == DeprecationWarning)
# test read_evokeds and write_evokeds
types = ['Left Auditory', 'Right Auditory', 'Left visual', 'Right visual']
aves1 = read_evokeds(fname)
aves2 = read_evokeds(fname, [0, 1, 2, 3])
aves3 = read_evokeds(fname, types)
write_evokeds(op.join(tempdir, 'evoked.fif'), aves1)
aves4 = read_evokeds(op.join(tempdir, 'evoked.fif'))
for aves in [aves2, aves3, aves4]:
for [av1, av2] in zip(aves1, aves):
assert_array_almost_equal(av1.data, av2.data)
assert_array_almost_equal(av1.times, av2.times)
assert_equal(av1.nave, av2.nave)
assert_equal(av1.kind, av2.kind)
assert_equal(av1._aspect_kind, av2._aspect_kind)
assert_equal(av1.last, av2.last)
assert_equal(av1.first, av2.first)
assert_equal(av1.comment, av2.comment)
示例14: test_as_data_frame
def test_as_data_frame():
"""Test Pandas exporter"""
ave = read_evoked(fname, [0])[0]
assert_raises(ValueError, ave.as_data_frame, picks=np.arange(400))
df = ave.as_data_frame()
assert_true((df.columns == ave.ch_names).all())
df = ave.as_data_frame(use_time_index=False)
assert_true('time' in df.columns)
assert_array_equal(df.values[:, 1], ave.data[0] * 1e13)
assert_array_equal(df.values[:, 3], ave.data[2] * 1e15)
示例15: test_io_multi_evoked
def test_io_multi_evoked():
"""Test IO for multiple evoked datasets
"""
aves = read_evoked(fname, [0, 1, 2, 3])
write_evoked(op.join(tempdir, 'evoked.fif'), aves)
aves2 = read_evoked(op.join(tempdir, 'evoked.fif'), [0, 1, 2, 3])
types = ['Left Auditory', 'Right Auditory', 'Left visual', 'Right visual']
aves3 = read_evoked(op.join(tempdir, 'evoked.fif'), types)
for aves_new in [aves2, aves3]:
for [ave, ave_new] in zip(aves, aves_new):
assert_array_almost_equal(ave.data, ave_new.data)
assert_array_almost_equal(ave.times, ave_new.times)
assert_equal(ave.nave, ave_new.nave)
assert_equal(ave.kind, ave_new.kind)
assert_equal(ave._aspect_kind, ave_new._aspect_kind)
assert_equal(ave.last, ave_new.last)
assert_equal(ave.first, ave_new.first)
# this should throw an error since there are mulitple datasets
assert_raises(ValueError, read_evoked, fname)