本文整理汇总了Python中mne.fiff.pick_types函数的典型用法代码示例。如果您正苦于以下问题:Python pick_types函数的具体用法?Python pick_types怎么用?Python pick_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pick_types函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_data
def test_data():
"""Test reading raw kit files
"""
raw_py = kit.read_raw_kit(input_fname=op.join(data_dir, 'test.sqd'),
mrk_fname=op.join(data_dir, 'test_mrk.sqd'),
elp_fname=op.join(data_dir, 'test_elp.txt'),
hsp_fname=op.join(data_dir, 'test_hsp.txt'),
sns_fname=op.join(data_dir, 'sns.txt'),
stim=range(167, 159, -1), stimthresh=1,
preload=True)
# Binary file only stores the sensor channels
py_picks = pick_types(raw_py.info, exclude='bads')
raw_bin = op.join(data_dir, 'test_bin.fif')
raw_bin = Raw(raw_bin, preload=True)
bin_picks = pick_types(raw_bin.info, stim=True, exclude='bads')
data_bin, _ = raw_bin[bin_picks]
data_py, _ = raw_py[py_picks]
# this .mat was generated using the Yokogawa MEG Reader
data_Ykgw = op.join(data_dir, 'test_Ykgw.mat')
data_Ykgw = scipy.io.loadmat(data_Ykgw)['data']
data_Ykgw = data_Ykgw[py_picks]
assert_array_almost_equal(data_py, data_Ykgw)
py_picks = pick_types(raw_py.info, stim=True, exclude='bads')
data_py, _ = raw_py[py_picks]
assert_array_almost_equal(data_py, data_bin)
示例2: test_data
def test_data():
"""Test reading raw kit files
"""
raw_py = read_raw_kit(sqd_path, mrk_path, elp_path, hsp_path,
stim=list(range(167, 159, -1)), slope='+',
stimthresh=1, preload=True)
print(repr(raw_py))
# Binary file only stores the sensor channels
py_picks = pick_types(raw_py.info, exclude='bads')
raw_bin = op.join(data_dir, 'test_bin.fif')
raw_bin = Raw(raw_bin, preload=True)
bin_picks = pick_types(raw_bin.info, stim=True, exclude='bads')
data_bin, _ = raw_bin[bin_picks]
data_py, _ = raw_py[py_picks]
# this .mat was generated using the Yokogawa MEG Reader
data_Ykgw = op.join(data_dir, 'test_Ykgw.mat')
data_Ykgw = scipy.io.loadmat(data_Ykgw)['data']
data_Ykgw = data_Ykgw[py_picks]
assert_array_almost_equal(data_py, data_Ykgw)
py_picks = pick_types(raw_py.info, stim=True, ref_meg=False,
exclude='bads')
data_py, _ = raw_py[py_picks]
assert_array_almost_equal(data_py, data_bin)
示例3: test_compensation_mne
def test_compensation_mne():
"""Test comensation by comparing with MNE
"""
def make_evoked(fname, comp):
raw = Raw(fname, compensation=comp)
picks = pick_types(raw.info, meg=True, ref_meg=True)
events = np.array([[0, 0, 1]], dtype=np.int)
evoked = Epochs(raw, events, 1, 0, 20e-3, picks=picks).average()
return evoked
def compensate_mne(fname, comp):
tmp_fname = '%s-%d.fif' % (fname[:-4], comp)
cmd = ['mne_compensate_data', '--in', fname,
'--out', tmp_fname, '--grad', str(comp)]
run_subprocess(cmd)
return read_evokeds(tmp_fname)[0]
# save evoked response with default compensation
fname_default = op.join(tempdir, 'ctf_default-ave.fif')
make_evoked(ctf_comp_fname, None).save(fname_default)
for comp in [0, 1, 2, 3]:
evoked_py = make_evoked(ctf_comp_fname, comp)
evoked_c = compensate_mne(fname_default, comp)
picks_py = pick_types(evoked_py.info, meg=True, ref_meg=True)
picks_c = pick_types(evoked_c.info, meg=True, ref_meg=True)
assert_allclose(evoked_py.data[picks_py], evoked_c.data[picks_c],
rtol=1e-3, atol=1e-17)
示例4: test_set_eeg_reference
def test_set_eeg_reference():
""" Test rereference eeg data"""
raw = Raw(fif_fname, preload=True)
# Rereference raw data by creating a copy of original data
reref, ref_data = set_eeg_reference(raw, ['EEG 001', 'EEG 002'], copy=True)
# Separate EEG channels from other channel types
picks_eeg = pick_types(raw.info, meg=False, eeg=True, exclude='bads')
picks_other = pick_types(raw.info, meg=True, eeg=False, eog=True,
stim=True, exclude='bads')
# Get the raw EEG data and other channel data
raw_eeg_data = raw[picks_eeg][0]
raw_other_data = raw[picks_other][0]
# Get the rereferenced EEG data and channel other
reref_eeg_data = reref[picks_eeg][0]
unref_eeg_data = reref_eeg_data + ref_data
# Undo rereferencing of EEG channels
reref_other_data = reref[picks_other][0]
# Check that both EEG data and other data is the same
assert_array_equal(raw_eeg_data, unref_eeg_data)
assert_array_equal(raw_other_data, reref_other_data)
# Test that data is modified in place when copy=False
reref, ref_data = set_eeg_reference(raw, ['EEG 001', 'EEG 002'],
copy=False)
assert_true(raw is reref)
示例5: test_raw_to_nitime
def test_raw_to_nitime():
""" Test nitime export """
raw = Raw(fif_fname, preload=True)
picks_meg = pick_types(raw.info, meg=True, exclude='bads')
picks = picks_meg[:4]
raw_ts = raw.to_nitime(picks=picks)
assert_true(raw_ts.data.shape[0] == len(picks))
raw = Raw(fif_fname, preload=False)
picks_meg = pick_types(raw.info, meg=True, exclude='bads')
picks = picks_meg[:4]
raw_ts = raw.to_nitime(picks=picks)
assert_true(raw_ts.data.shape[0] == len(picks))
raw = Raw(fif_fname, preload=True)
picks_meg = pick_types(raw.info, meg=True, exclude='bads')
picks = picks_meg[:4]
raw_ts = raw.to_nitime(picks=picks, copy=False)
assert_true(raw_ts.data.shape[0] == len(picks))
raw = Raw(fif_fname, preload=False)
picks_meg = pick_types(raw.info, meg=True, exclude='bads')
picks = picks_meg[:4]
raw_ts = raw.to_nitime(picks=picks, copy=False)
assert_true(raw_ts.data.shape[0] == len(picks))
示例6: test_brainvision_data
def test_brainvision_data():
"""Test reading raw Brain Vision files
"""
raw_py = read_raw_brainvision(vhdr_path, elp_path, elp_names, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_py, times_py = raw_py[picks]
print(raw_py) # to test repr
print(raw_py.info) # to test Info repr
# compare with a file that was generated using MNE-C
raw_bin = Raw(eeg_bin, preload=True)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_bin, times_bin = raw_bin[picks]
assert_array_almost_equal(data_py, data_bin)
assert_array_almost_equal(times_py, times_bin)
# Make sure EOG channels are marked correctly
raw_py = read_raw_brainvision(vhdr_path, elp_path, elp_names, eog=eog,
preload=True)
for ch in raw_py.info['chs']:
if ch['ch_name'] in eog:
assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH)
elif ch['ch_name'] in elp_names:
assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH)
elif ch['ch_name'] == 'STI 014':
assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH)
else:
raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
示例7: test_rank_estimation
def test_rank_estimation():
"""Test raw rank estimation
"""
raw = Raw(fif_fname)
n_meg = len(pick_types(raw.info, meg=True, eeg=False, exclude="bads"))
n_eeg = len(pick_types(raw.info, meg=False, eeg=True, exclude="bads"))
raw = Raw(fif_fname, preload=True)
assert_array_equal(raw.estimate_rank(), n_meg + n_eeg)
raw = Raw(fif_fname, preload=False)
raw.apply_proj()
n_proj = len(raw.info["projs"])
assert_array_equal(raw.estimate_rank(tstart=10, tstop=20), n_meg + n_eeg - n_proj)
示例8: test_filter
def test_filter():
""" Test filtering and Raw.apply_function interface """
raw = Raw(fif_fname, preload=True)
picks_meg = pick_types(raw.info, meg=True)
picks = picks_meg[:4]
raw_lp = deepcopy(raw)
raw_lp.filter(0.0, 4.0, picks=picks, n_jobs=2)
raw_hp = deepcopy(raw)
raw_lp.filter(8.0, None, picks=picks, n_jobs=2)
raw_bp = deepcopy(raw)
raw_bp.filter(4.0, 8.0, picks=picks)
data, _ = raw[picks, :]
lp_data, _ = raw_lp[picks, :]
hp_data, _ = raw_hp[picks, :]
bp_data, _ = raw_bp[picks, :]
assert_array_almost_equal(data, lp_data + hp_data + bp_data)
# make sure we didn't touch other channels
data, _ = raw[picks_meg[4:], :]
bp_data, _ = raw_bp[picks_meg[4:], :]
assert_array_equal(data, bp_data)
示例9: test_detrend
def test_detrend():
"""Test detrending of epochs
"""
# test first-order
epochs_1 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=None, detrend=1)
epochs_2 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=None, detrend=None)
data_picks = fiff.pick_types(epochs_1.info, meg=True, eeg=True,
exclude='bads')
evoked_1 = epochs_1.average()
evoked_2 = epochs_2.average()
evoked_2.detrend(1)
# Due to roundoff these won't be exactly equal, but they should be close
assert_true(np.allclose(evoked_1.data, evoked_2.data,
rtol=1e-8, atol=1e-20))
# test zeroth-order case
for preload in [True, False]:
epochs_1 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=(None, None), preload=preload)
epochs_2 = Epochs(raw, events[:4], event_id, tmin, tmax, picks=picks,
baseline=None, preload=preload, detrend=0)
a = epochs_1.get_data()
b = epochs_2.get_data()
# All data channels should be almost equal
assert_true(np.allclose(a[:, data_picks, :], b[:, data_picks, :],
rtol=1e-16, atol=1e-20))
# There are non-M/EEG channels that should not be equal:
assert_true(not np.allclose(a, b))
示例10: test_preload_modify
def test_preload_modify():
""" Test preloading and modifying data
"""
for preload in [False, True, "memmap.dat"]:
raw = Raw(fif_fname, preload=preload)
nsamp = raw.last_samp - raw.first_samp + 1
picks = pick_types(raw.info, meg="grad", exclude="bads")
data = np.random.randn(len(picks), nsamp / 2)
try:
raw[picks, : nsamp / 2] = data
except RuntimeError as err:
if not preload:
continue
else:
raise err
tmp_fname = op.join(tempdir, "raw.fif")
raw.save(tmp_fname, overwrite=True)
raw_new = Raw(tmp_fname)
data_new, _ = raw_new[picks, : nsamp / 2]
assert_allclose(data, data_new)
示例11: test_psd
def test_psd():
"""Test PSD estimation
"""
raw = fiff.Raw(raw_fname)
exclude = raw.info['bads'] + ['MEG 2443', 'EEG 053'] # bads + 2 more
# picks MEG gradiometers
picks = fiff.pick_types(raw.info, meg='mag', eeg=False, stim=False,
exclude=exclude)
picks = picks[:2]
tmin, tmax = 0, 10 # use the first 60s of data
fmin, fmax = 2, 70 # look at frequencies between 5 and 70Hz
NFFT = 124 # the FFT size (NFFT). Ideally a power of 2
psds, freqs = compute_raw_psd(raw, tmin=tmin, tmax=tmax, picks=picks,
fmin=fmin, fmax=fmax, NFFT=NFFT, n_jobs=1,
proj=False)
psds_proj, freqs = compute_raw_psd(raw, tmin=tmin, tmax=tmax, picks=picks,
fmin=fmin, fmax=fmax, NFFT=NFFT,
n_jobs=1, proj=True)
assert_array_almost_equal(psds, psds_proj)
assert_true(psds.shape == (len(picks), len(freqs)))
assert_true(np.sum(freqs < 0) == 0)
assert_true(np.sum(psds < 0) == 0)
示例12: test_apply_mne_inverse_epochs
def test_apply_mne_inverse_epochs():
"""Test MNE with precomputed inverse operator on Epochs
"""
event_id, tmin, tmax = 1, -0.2, 0.5
picks = fiff.pick_types(raw.info, meg=True, eeg=False, stim=True,
ecg=True, eog=True, include=['STI 014'])
reject = dict(grad=4000e-13, mag=4e-12, eog=150e-6)
flat = dict(grad=1e-15, mag=1e-15)
events = read_events(fname_event)[:15]
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=(None, 0), reject=reject, flat=flat)
stcs = apply_inverse_epochs(epochs, inverse_operator, lambda2, "dSPM",
label=label, pick_normal=True)
assert_true(len(stcs) == 4)
assert_true(3 < stcs[0].data.max() < 10)
data = sum(stc.data for stc in stcs) / len(stcs)
flip = label_sign_flip(label, inverse_operator['src'])
label_mean = np.mean(data, axis=0)
label_mean_flip = np.mean(flip[:, np.newaxis] * data, axis=0)
assert_true(label_mean.max() < label_mean_flip.max())
示例13: test_ems
def test_ems():
"""Test event-matched spatial filters"""
raw = fiff.Raw(raw_fname, preload=False)
# create unequal number of events
events = read_events(event_name)
events[-2, 2] = 3
picks = fiff.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()
示例14: test_compute_proj_epochs
def test_compute_proj_epochs():
"""Test SSP computation on epochs"""
event_id, tmin, tmax = 1, -0.2, 0.3
raw = Raw(raw_fname, preload=True)
events = read_events(event_fname)
bad_ch = 'MEG 2443'
picks = pick_types(raw.info, meg=True, eeg=False, stim=False, eog=False,
exclude=[])
epochs = Epochs(raw, events, event_id, tmin, tmax, picks=picks,
baseline=None, proj=False)
evoked = epochs.average()
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=1)
write_proj(op.join(tempdir, 'proj.fif.gz'), projs)
for p_fname in [proj_fname, proj_gz_fname,
op.join(tempdir, 'proj.fif.gz')]:
projs2 = read_proj(p_fname)
assert_true(len(projs) == len(projs2))
for p1, p2 in zip(projs, projs2):
assert_true(p1['desc'] == p2['desc'])
assert_true(p1['data']['col_names'] == p2['data']['col_names'])
assert_true(p1['active'] == p2['active'])
# compare with sign invariance
p1_data = p1['data']['data'] * np.sign(p1['data']['data'][0, 0])
p2_data = p2['data']['data'] * np.sign(p2['data']['data'][0, 0])
if bad_ch in p1['data']['col_names']:
bad = p1['data']['col_names'].index('MEG 2443')
mask = np.ones(p1_data.size, dtype=np.bool)
mask[bad] = False
p1_data = p1_data[:, mask]
p2_data = p2_data[:, mask]
corr = np.corrcoef(p1_data, p2_data)[0, 1]
assert_array_almost_equal(corr, 1.0, 5)
# test that you can compute the projection matrix
projs = activate_proj(projs)
proj, nproj, U = make_projector(projs, epochs.ch_names, bads=[])
assert_true(nproj == 2)
assert_true(U.shape[1] == 2)
# test that you can save them
epochs.info['projs'] += projs
evoked = epochs.average()
evoked.save(op.join(tempdir, 'foo.fif'))
projs = read_proj(proj_fname)
projs_evoked = compute_proj_evoked(evoked, n_grad=1, n_mag=1, n_eeg=0)
assert_true(len(projs_evoked) == 2)
# XXX : test something
# test parallelization
projs = compute_proj_epochs(epochs, n_grad=1, n_mag=1, n_eeg=0, n_jobs=2)
projs = activate_proj(projs)
proj_par, _, _ = make_projector(projs, epochs.ch_names, bads=[])
assert_allclose(proj, proj_par, rtol=1e-8, atol=1e-16)
示例15: test_preload_modify
def test_preload_modify():
""" Test preloading and modifying data
"""
for preload in [False, True, 'memmap.dat']:
raw = Raw(fif_fname, preload=preload)
nsamp = raw.last_samp - raw.first_samp + 1
picks = pick_types(raw.info, meg='grad', exclude='bads')
data = np.random.randn(len(picks), nsamp / 2)
try:
raw[picks, :nsamp / 2] = data
except RuntimeError as err:
if not preload:
continue
else:
raise err
tmp_fname = op.join(tempdir, 'raw.fif')
raw.save(tmp_fname)
raw_new = Raw(tmp_fname)
data_new, _ = raw_new[picks, :nsamp / 2]
assert_array_almost_equal(data, data_new)