本文整理汇总了Python中mne.make_fixed_length_events函数的典型用法代码示例。如果您正苦于以下问题:Python make_fixed_length_events函数的具体用法?Python make_fixed_length_events怎么用?Python make_fixed_length_events使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_fixed_length_events函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_fixed_length_events
def test_make_fixed_length_events():
"""Test making events of a fixed length
"""
raw = io.Raw(raw_fname)
events = make_fixed_length_events(raw, id=1)
assert_true(events.shape[1], 3)
tmin, tmax = raw.times[[0, -1]]
duration = tmax - tmin
events = make_fixed_length_events(raw, 1, tmin, tmax, duration)
assert_equal(events.shape[0], 1)
示例2: test_make_fixed_length_events
def test_make_fixed_length_events():
"""Test making events of a fixed length."""
raw = read_raw_fif(raw_fname)
events = make_fixed_length_events(raw, id=1)
assert events.shape[1] == 3
events_zero = make_fixed_length_events(raw, 1, first_samp=False)
assert_equal(events_zero[0, 0], 0)
assert_array_equal(events_zero[:, 0], events[:, 0] - raw.first_samp)
# With limits
tmin, tmax = raw.times[[0, -1]]
duration = tmax - tmin
events = make_fixed_length_events(raw, 1, tmin, tmax, duration)
assert_equal(events.shape[0], 1)
# With bad limits (no resulting events)
pytest.raises(ValueError, make_fixed_length_events, raw, 1,
tmin, tmax - 1e-3, duration)
# not raw, bad id or duration
pytest.raises(TypeError, make_fixed_length_events, raw, 2.3)
pytest.raises(TypeError, make_fixed_length_events, 'not raw', 2)
pytest.raises(TypeError, make_fixed_length_events, raw, 23, tmin, tmax,
'abc')
# Let's try some ugly sample rate/sample count combos
data = np.random.RandomState(0).randn(1, 27768)
# This breaks unless np.round() is used in make_fixed_length_events
info = create_info(1, 155.4499969482422)
raw = RawArray(data, info)
events = make_fixed_length_events(raw, 1, duration=raw.times[-1])
assert events[0, 0] == 0
assert len(events) == 1
# Without use_rounding=True this breaks
raw = RawArray(data[:, :21216], info)
events = make_fixed_length_events(raw, 1, duration=raw.times[-1])
assert events[0, 0] == 0
assert len(events) == 1
# Make sure it gets used properly by compute_raw_covariance
cov = compute_raw_covariance(raw, tstep=None)
expected = np.cov(data[:, :21216])
np.testing.assert_allclose(cov['data'], expected, atol=1e-12)
# overlaps
events = make_fixed_length_events(raw, 1, duration=1)
assert len(events) == 136
events_ol = make_fixed_length_events(raw, 1, duration=1, overlap=0.5)
assert len(events_ol) == 271
events_ol_2 = make_fixed_length_events(raw, 1, duration=1, overlap=0.9)
assert len(events_ol_2) == 1355
assert_array_equal(events_ol_2[:, 0], np.unique(events_ol_2[:, 0]))
with pytest.raises(ValueError, match='overlap must be'):
make_fixed_length_events(raw, 1, duration=1, overlap=1.1)
示例3: test_make_fixed_length_events
def test_make_fixed_length_events():
"""Test making events of a fixed length"""
raw = io.read_raw_fif(raw_fname)
events = make_fixed_length_events(raw, id=1)
assert_true(events.shape[1], 3)
events_zero = make_fixed_length_events(raw, 1, first_samp=False)
assert_equal(events_zero[0, 0], 0)
assert_array_equal(events_zero[:, 0], events[:, 0] - raw.first_samp)
# With limits
tmin, tmax = raw.times[[0, -1]]
duration = tmax - tmin
events = make_fixed_length_events(raw, 1, tmin, tmax, duration)
assert_equal(events.shape[0], 1)
# With bad limits (no resulting events)
assert_raises(ValueError, make_fixed_length_events, raw, 1,
tmin, tmax - 1e-3, duration)
示例4: test_cov_ctf
def test_cov_ctf():
"""Test basic cov computation on ctf data with/without compensation."""
raw = read_raw_ctf(ctf_fname).crop(0., 2.).load_data()
events = make_fixed_length_events(raw, 99999)
assert len(events) == 2
ch_names = [raw.info['ch_names'][pick]
for pick in pick_types(raw.info, meg=True, eeg=False,
ref_meg=False)]
for comp in [0, 1]:
raw.apply_gradient_compensation(comp)
epochs = Epochs(raw, events, None, -0.2, 0.2, preload=True)
with pytest.warns(RuntimeWarning, match='Too few samples'):
noise_cov = compute_covariance(epochs, tmax=0.,
method=['empirical'])
prepare_noise_cov(noise_cov, raw.info, ch_names)
raw.apply_gradient_compensation(0)
epochs = Epochs(raw, events, None, -0.2, 0.2, preload=True)
with pytest.warns(RuntimeWarning, match='Too few samples'):
noise_cov = compute_covariance(epochs, tmax=0., method=['empirical'])
raw.apply_gradient_compensation(1)
# TODO This next call in principle should fail.
prepare_noise_cov(noise_cov, raw.info, ch_names)
# make sure comps matrices was not removed from raw
assert raw.info['comps'], 'Comps matrices removed'
示例5: raw_epochs_events
def raw_epochs_events():
"""Create raw, epochs, and events for tests."""
raw = read_raw_fif(raw_fname).set_eeg_reference(projection=True).crop(0, 3)
raw = maxwell_filter(raw, regularize=None) # heavily reduce the rank
assert raw.info['bads'] == [] # no bads
events = make_fixed_length_events(raw)
epochs = Epochs(raw, events, tmin=-0.2, tmax=0, preload=True)
return (raw, epochs, events)
示例6: test_stockwell_ctf
def test_stockwell_ctf():
"""Test that Stockwell can be calculated on CTF data."""
raw = read_raw_fif(raw_ctf_fname)
raw.apply_gradient_compensation(3)
events = make_fixed_length_events(raw, duration=0.5)
evoked = Epochs(raw, events, tmin=-0.2, tmax=0.3, decim=10,
preload=True, verbose='error').average()
tfr_stockwell(evoked, verbose='error') # smoke test
示例7: test_tfr_ctf
def test_tfr_ctf():
"""Test that TFRs can be calculated on CTF data."""
raw = read_raw_fif(raw_ctf_fname).crop(0, 1)
raw.apply_gradient_compensation(3)
events = mne.make_fixed_length_events(raw, duration=0.5)
epochs = mne.Epochs(raw, events)
for method in (tfr_multitaper, tfr_morlet):
method(epochs, [10], 1) # smoke test
示例8: test_ctf_plotting
def test_ctf_plotting():
"""Test CTF topomap plotting."""
raw = read_raw_fif(ctf_fname, preload=True)
events = make_fixed_length_events(raw, duration=0.01)
assert len(events) > 10
evoked = Epochs(raw, events, tmin=0, tmax=0.01, baseline=None).average()
assert get_current_comp(evoked.info) == 3
# smoke test that compensation does not matter
evoked.plot_topomap(time_unit='s')
示例9: test_field_map_ctf
def test_field_map_ctf():
"""Test that field mapping can be done with CTF data."""
raw = read_raw_fif(raw_ctf_fname).crop(0, 1)
raw.apply_gradient_compensation(3)
events = make_fixed_length_events(raw, duration=0.5)
evoked = Epochs(raw, events).average()
evoked.pick_channels(evoked.ch_names[:50]) # crappy mapping but faster
# smoke test
make_field_map(evoked, trans=trans_fname, subject='sample',
subjects_dir=subjects_dir)
示例10: test_dipole_fitting_ctf
def test_dipole_fitting_ctf():
"""Test dipole fitting with CTF data."""
raw_ctf = read_raw_ctf(fname_ctf).set_eeg_reference()
events = make_fixed_length_events(raw_ctf, 1)
evoked = Epochs(raw_ctf, events, 1, 0, 0, baseline=None).average()
cov = make_ad_hoc_cov(evoked.info)
sphere = make_sphere_model((0., 0., 0.))
# XXX Eventually we should do some better checks about accuracy, but
# for now our CTF phantom fitting tutorials will have to do
# (otherwise we need to add that to the testing dataset, which is
# a bit too big)
fit_dipole(evoked, cov, sphere)
示例11: test_ctf_plotting
def test_ctf_plotting():
"""Test CTF topomap plotting."""
raw = read_raw_fif(ctf_fname, preload=True)
assert raw.compensation_grade == 3
events = make_fixed_length_events(raw, duration=0.01)
assert len(events) > 10
evoked = Epochs(raw, events, tmin=0, tmax=0.01, baseline=None).average()
assert get_current_comp(evoked.info) == 3
# smoke test that compensation does not matter
evoked.plot_topomap(time_unit='s')
# better test that topomaps can still be used without plotting ref
evoked.pick_types(meg=True, ref_meg=False)
evoked.plot_topomap()
示例12: test_plot_evoked_cov
def test_plot_evoked_cov():
"""Test plot_evoked with noise_cov."""
evoked = _get_epochs().average()
cov = read_cov(cov_fname)
cov['projs'] = [] # avoid warnings
evoked.plot(noise_cov=cov, time_unit='s')
with pytest.raises(TypeError, match='Covariance'):
evoked.plot(noise_cov=1., time_unit='s')
with pytest.raises(IOError, match='No such file'):
evoked.plot(noise_cov='nonexistent-cov.fif', time_unit='s')
raw = read_raw_fif(raw_sss_fname)
events = make_fixed_length_events(raw)
epochs = Epochs(raw, events, picks=picks)
cov = compute_covariance(epochs)
evoked_sss = epochs.average()
with pytest.warns(RuntimeWarning, match='relative scaling'):
evoked_sss.plot(noise_cov=cov, time_unit='s')
plt.close('all')
示例13: test_lcmv_ctf_comp
def test_lcmv_ctf_comp():
"""Test interpolation with compensated CTF data."""
ctf_dir = op.join(testing.data_path(download=False), 'CTF')
raw_fname = op.join(ctf_dir, 'somMDYO-18av.ds')
raw = mne.io.read_raw_ctf(raw_fname, preload=True)
events = mne.make_fixed_length_events(raw, duration=0.2)[:2]
epochs = mne.Epochs(raw, events, tmin=0., tmax=0.2)
evoked = epochs.average()
with pytest.warns(RuntimeWarning,
match='Too few samples .* estimate may be unreliable'):
data_cov = mne.compute_covariance(epochs)
fwd = mne.make_forward_solution(evoked.info, None,
mne.setup_volume_source_space(pos=15.0),
mne.make_sphere_model())
filters = mne.beamformer.make_lcmv(evoked.info, fwd, data_cov)
assert 'weights' in filters
示例14: test_plot_evoked_cov
def test_plot_evoked_cov():
"""Test plot_evoked with noise_cov."""
import matplotlib.pyplot as plt
evoked = _get_epochs().average()
cov = read_cov(cov_fname)
cov['projs'] = [] # avoid warnings
evoked.plot(noise_cov=cov, time_unit='s')
with pytest.raises(TypeError, match='Covariance'):
evoked.plot(noise_cov=1., time_unit='s')
with pytest.raises(IOError, match='No such file'):
evoked.plot(noise_cov='nonexistent-cov.fif', time_unit='s')
raw = read_raw_fif(raw_sss_fname)
events = make_fixed_length_events(raw)
epochs = Epochs(raw, events)
cov = compute_covariance(epochs)
evoked_sss = epochs.average()
with warnings.catch_warnings(record=True) as w:
evoked_sss.plot(noise_cov=cov, time_unit='s')
plt.close('all')
assert any('relative scal' in str(ww.message) for ww in w)
示例15: get_epochs
def get_epochs(self,resample=None):
from mne.time_frequency import psd_multitaper
raw = self.raw
validation_windowsize = self.validation_windowsize
front = self.front
back = self.back
# l_freq = self.l_freq
# h_freq = self.h_freq
events = mne.make_fixed_length_events(raw,id=1,start=front,
stop=raw.times[-1]-back,
duration=validation_windowsize)
epochs = mne.Epochs(raw,events,event_id=1,tmin=0,tmax=validation_windowsize,
preload=True)
if resample is not None:
epochs.resample(resample)
# psds,freq = psd_multitaper(epochs,fmin=l_freq,
# fmax=h_freq,
# tmin=0,tmax=validation_windowsize,
# low_bias=True,)
# psds = 10 * np.log10(psds)
self.epochs = epochs