本文整理汇总了Python中mne.Epochs.drop_bad方法的典型用法代码示例。如果您正苦于以下问题:Python Epochs.drop_bad方法的具体用法?Python Epochs.drop_bad怎么用?Python Epochs.drop_bad使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.Epochs
的用法示例。
在下文中一共展示了Epochs.drop_bad方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_events_long
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import drop_bad [as 别名]
def test_events_long():
"""Test events."""
data_path = testing.data_path()
raw_fname = data_path + '/MEG/sample/sample_audvis_trunc_raw.fif'
raw = read_raw_fif(raw_fname, preload=True)
raw_tmin, raw_tmax = 0, 90
tmin, tmax = -0.2, 0.5
event_id = dict(aud_l=1, vis_l=3)
# select gradiometers
picks = pick_types(raw.info, meg='grad', eeg=False, eog=True,
stim=True, exclude=raw.info['bads'])
# load data with usual Epochs for later verification
raw = concatenate_raws([raw, raw.copy(), raw.copy(), raw.copy(),
raw.copy(), raw.copy()])
assert 110 < raw.times[-1] < 130
raw_cropped = raw.copy().crop(raw_tmin, raw_tmax)
events_offline = find_events(raw_cropped)
epochs_offline = Epochs(raw_cropped, events_offline, event_id=event_id,
tmin=tmin, tmax=tmax, picks=picks, decim=1,
reject=dict(grad=4000e-13, eog=150e-6),
baseline=None)
epochs_offline.drop_bad()
# create the mock-client object
rt_client = MockRtClient(raw)
rt_epochs = RtEpochs(rt_client, event_id, tmin, tmax, picks=picks, decim=1,
reject=dict(grad=4000e-13, eog=150e-6), baseline=None,
isi_max=1.)
rt_epochs.start()
rt_client.send_data(rt_epochs, picks, tmin=raw_tmin, tmax=raw_tmax,
buffer_size=1000)
expected_events = epochs_offline.events.copy()
expected_events[:, 0] = expected_events[:, 0] - raw_cropped.first_samp
assert np.all(expected_events[:, 0] <=
(raw_tmax - tmax) * raw.info['sfreq'])
assert_array_equal(rt_epochs.events, expected_events)
assert len(rt_epochs) == len(epochs_offline)
data_picks = pick_types(epochs_offline.info, meg='grad', eeg=False,
eog=True,
stim=False, exclude=raw.info['bads'])
for ev_num, ev in enumerate(rt_epochs.iter_evoked()):
if ev_num == 0:
X_rt = ev.data[None, data_picks, :]
y_rt = int(ev.comment) # comment attribute contains the event_id
else:
X_rt = np.concatenate((X_rt, ev.data[None, data_picks, :]), axis=0)
y_rt = np.append(y_rt, int(ev.comment))
X_offline = epochs_offline.get_data()[:, data_picks, :]
y_offline = epochs_offline.events[:, 2]
assert_array_equal(X_rt, X_offline)
assert_array_equal(y_rt, y_offline)
示例2: test_fieldtrip_rtepochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import drop_bad [as 别名]
def test_fieldtrip_rtepochs(free_tcp_port, tmpdir):
"""Test FieldTrip RtEpochs."""
raw_tmax = 7
raw = read_raw_fif(raw_fname, preload=True)
raw.crop(tmin=0, tmax=raw_tmax)
events_offline = find_events(raw, stim_channel='STI 014')
event_id = list(np.unique(events_offline[:, 2]))
tmin, tmax = -0.2, 0.5
epochs_offline = Epochs(raw, events_offline, event_id=event_id,
tmin=tmin, tmax=tmax)
epochs_offline.drop_bad()
isi_max = (np.max(np.diff(epochs_offline.events[:, 0])) /
raw.info['sfreq']) + 1.0
kill_signal = _start_buffer_thread(free_tcp_port)
try:
data_rt = None
events_ids_rt = None
with pytest.warns(RuntimeWarning, match='Trying to guess it'):
with FieldTripClient(host='localhost', port=free_tcp_port,
tmax=raw_tmax, wait_max=2) as rt_client:
# get measurement info guessed by MNE-Python
raw_info = rt_client.get_measurement_info()
assert ([ch['ch_name'] for ch in raw_info['chs']] ==
[ch['ch_name'] for ch in raw.info['chs']])
# create the real-time epochs object
epochs_rt = RtEpochs(rt_client, event_id, tmin, tmax,
stim_channel='STI 014', isi_max=isi_max)
epochs_rt.start()
time.sleep(0.5)
for ev_num, ev in enumerate(epochs_rt.iter_evoked()):
if ev_num == 0:
data_rt = ev.data[None, :, :]
events_ids_rt = int(
ev.comment) # comment attribute contains event_id
else:
data_rt = np.concatenate(
(data_rt, ev.data[None, :, :]), axis=0)
events_ids_rt = np.append(events_ids_rt,
int(ev.comment))
_call_base_epochs_public_api(epochs_rt, tmpdir)
epochs_rt.stop(stop_receive_thread=True)
assert_array_equal(events_ids_rt, epochs_rt.events[:, 2])
assert_array_equal(data_rt, epochs_rt.get_data())
assert len(epochs_rt) == len(epochs_offline)
assert_array_equal(events_ids_rt, epochs_offline.events[:, 2])
assert_allclose(epochs_rt.get_data(), epochs_offline.get_data(),
rtol=1.e-5, atol=1.e-8) # defaults of np.isclose
finally:
kill_signal.put(False) # stop the buffer
示例3: test_source_psd_epochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import drop_bad [as 别名]
def test_source_psd_epochs():
"""Test multi-taper source PSD computation in label from epochs."""
raw = read_raw_fif(fname_data)
inverse_operator = read_inverse_operator(fname_inv)
label = read_label(fname_label)
event_id, tmin, tmax = 1, -0.2, 0.5
lambda2, method = 1. / 9., 'dSPM'
bandwidth = 8.
fmin, fmax = 0, 100
picks = pick_types(raw.info, meg=True, eeg=False, stim=True,
ecg=True, eog=True, include=['STI 014'],
exclude='bads')
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
events = find_events(raw, stim_channel='STI 014')
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject)
# only look at one epoch
epochs.drop_bad()
one_epochs = epochs[:1]
inv = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=1. / 9., method="dSPM")
# return list
stc_psd = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
prepared=True)[0]
# return generator
stcs = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
return_generator=True,
prepared=True)
for stc in stcs:
stc_psd_gen = stc
assert_array_almost_equal(stc_psd.data, stc_psd_gen.data)
# compare with direct computation
stc = apply_inverse_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
prepared=True)[0]
sfreq = epochs.info['sfreq']
psd, freqs = _psd_multitaper(stc.data, sfreq=sfreq, bandwidth=bandwidth,
fmin=fmin, fmax=fmax)
assert_array_almost_equal(psd, stc_psd.data)
assert_array_almost_equal(freqs, stc_psd.times)
# Check corner cases caused by tiny bandwidth
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=0.01, low_bias=True,
fmin=fmin, fmax=fmax,
return_generator=False,
prepared=True)
compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=0.01, low_bias=False,
fmin=fmin, fmax=fmax,
return_generator=False,
prepared=True)
assert_true(len(w) >= 2)
assert_true(any('not properly use' in str(ww.message) for ww in w))
assert_true(any('Bandwidth too small' in str(ww.message) for ww in w))
示例4: enumerate
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import drop_bad [as 别名]
freq_scores = np.zeros((n_freqs - 1,))
# Loop through each frequency range of interest
for freq, (fmin, fmax) in enumerate(freq_ranges):
# Infer window size based on the frequency being used
w_size = n_cycles / ((fmax + fmin) / 2.) # in seconds
# Apply band-pass filter to isolate the specified frequencies
raw_filter = raw.copy().filter(fmin, fmax, n_jobs=1, fir_design='firwin',
skip_by_annotation='edge')
# Extract epochs from filtered data, padded by window size
epochs = Epochs(raw_filter, events, event_id, tmin - w_size, tmax + w_size,
proj=False, baseline=None, preload=True)
epochs.drop_bad()
y = le.fit_transform(epochs.events[:, 2])
X = epochs.get_data()
# Save mean scores over folds for each frequency and time window
freq_scores[freq] = np.mean(cross_val_score(estimator=clf, X=X, y=y,
scoring='roc_auc', cv=cv,
n_jobs=1), axis=0)
###############################################################################
# Plot frequency results
plt.bar(freqs[:-1], freq_scores, width=np.diff(freqs)[0],
align='edge', edgecolor='black')
plt.xticks(freqs)
示例5: test_source_psd_epochs
# 需要导入模块: from mne import Epochs [as 别名]
# 或者: from mne.Epochs import drop_bad [as 别名]
def test_source_psd_epochs():
"""Test multi-taper source PSD computation in label from epochs."""
raw = read_raw_fif(fname_data)
inverse_operator = read_inverse_operator(fname_inv)
label = read_label(fname_label)
event_id, tmin, tmax = 1, -0.2, 0.5
lambda2, method = 1. / 9., 'dSPM'
bandwidth = 8.
fmin, fmax = 0, 100
picks = pick_types(raw.info, meg=True, eeg=False, stim=True,
ecg=True, eog=True, include=['STI 014'],
exclude='bads')
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
events = find_events(raw, stim_channel='STI 014')
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject)
# only look at one epoch
epochs.drop_bad()
one_epochs = epochs[:1]
inv = prepare_inverse_operator(inverse_operator, nave=1,
lambda2=1. / 9., method="dSPM")
# return list
stc_psd = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
prepared=True)[0]
# return generator
stcs = compute_source_psd_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
bandwidth=bandwidth,
fmin=fmin, fmax=fmax,
return_generator=True,
prepared=True)
for stc in stcs:
stc_psd_gen = stc
assert_allclose(stc_psd.data, stc_psd_gen.data, atol=1e-7)
# compare with direct computation
stc = apply_inverse_epochs(one_epochs, inv,
lambda2=lambda2, method=method,
pick_ori="normal", label=label,
prepared=True)[0]
sfreq = epochs.info['sfreq']
psd, freqs = psd_array_multitaper(stc.data, sfreq=sfreq,
bandwidth=bandwidth, fmin=fmin,
fmax=fmax)
assert_allclose(psd, stc_psd.data, atol=1e-7)
assert_allclose(freqs, stc_psd.times)
# Check corner cases caused by tiny bandwidth
with pytest.raises(ValueError, match='use a value of at least'):
compute_source_psd_epochs(
one_epochs, inv, lambda2=lambda2, method=method,
pick_ori="normal", label=label, bandwidth=0.01, low_bias=True,
fmin=fmin, fmax=fmax, return_generator=False, prepared=True)