本文整理汇总了Python中mne.pick_types函数的典型用法代码示例。如果您正苦于以下问题:Python pick_types函数的具体用法?Python pick_types怎么用?Python pick_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pick_types函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _picks_by_type_old
def _picks_by_type_old(info, meg_combined=False, ref_meg=False,
exclude='bads'):
"""Use the old, slower _picks_by_type code."""
picks_list = []
has = [_contains_ch_type(info, k) for k in _DATA_CH_TYPES_SPLIT]
has = dict(zip(_DATA_CH_TYPES_SPLIT, has))
if has['mag'] and (meg_combined is not True or not has['grad']):
picks_list.append(
('mag', pick_types(info, meg='mag', eeg=False, stim=False,
ref_meg=ref_meg, exclude=exclude))
)
if has['grad'] and (meg_combined is not True or not has['mag']):
picks_list.append(
('grad', pick_types(info, meg='grad', eeg=False, stim=False,
ref_meg=ref_meg, exclude=exclude))
)
if has['mag'] and has['grad'] and meg_combined is True:
picks_list.append(
('meg', pick_types(info, meg=True, eeg=False, stim=False,
ref_meg=ref_meg, exclude=exclude))
)
for ch_type in _DATA_CH_TYPES_SPLIT:
if ch_type in ['grad', 'mag']: # exclude just MEG channels
continue
if has[ch_type]:
picks_list.append(
(ch_type, pick_types(info, meg=False, stim=False,
ref_meg=ref_meg, exclude=exclude,
**{ch_type: True}))
)
return picks_list
示例2: 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]
with warnings.catch_warnings(record=True):
raw_ts = raw.to_nitime(picks=picks)
assert_equal(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]
with warnings.catch_warnings(record=True):
raw_ts = raw.to_nitime(picks=picks)
assert_equal(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]
with warnings.catch_warnings(record=True):
raw_ts = raw.to_nitime(picks=picks, copy=False)
assert_equal(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]
with warnings.catch_warnings(record=True):
raw_ts = raw.to_nitime(picks=picks, copy=False)
assert_equal(raw_ts.data.shape[0], len(picks))
示例3: _load_data
def _load_data():
"""Helper function to load data."""
# It is more memory efficient to load data in a separate
# function so it's loaded on-demand
raw = io.read_raw_fif(raw_fname, add_eeg_ref=False)
events = read_events(event_name)
picks_eeg = pick_types(raw.info, meg=False, eeg=True, exclude=[])
# select every second channel for faster speed but compensate by using
# mode='accurate'.
picks_meg = pick_types(raw.info, meg=True, eeg=False, exclude=[])[1::2]
picks = pick_types(raw.info, meg=True, eeg=True, exclude=[])
with warnings.catch_warnings(record=True): # proj
epochs_eeg = Epochs(raw, events, event_id, tmin, tmax, picks=picks_eeg, preload=True, reject=dict(eeg=80e-6))
epochs_meg = Epochs(
raw, events, event_id, tmin, tmax, picks=picks_meg, preload=True, reject=dict(grad=1000e-12, mag=4e-12)
)
epochs = Epochs(
raw,
events,
event_id,
tmin,
tmax,
picks=picks,
preload=True,
reject=dict(eeg=80e-6, grad=1000e-12, mag=4e-12),
)
return raw, epochs, epochs_eeg, epochs_meg
示例4: test_find_ecg
def test_find_ecg():
"""Test find ECG peaks"""
raw = Raw(raw_fname)
# once with mag-trick
# once with characteristic channel
for ch_name in ['MEG 1531', None]:
events, ch_ECG, average_pulse, ecg = find_ecg_events(
raw, event_id=999, ch_name=None, return_ecg=True)
assert_equal(len(raw.times), len(ecg))
n_events = len(events)
_, times = raw[0, :]
assert_true(55 < average_pulse < 60)
picks = pick_types(
raw.info, meg='grad', eeg=False, stim=False,
eog=False, ecg=True, emg=False, ref_meg=False,
exclude='bads')
raw.load_data()
ecg_epochs = create_ecg_epochs(raw, picks=picks, keep_ecg=True)
assert_equal(len(ecg_epochs.events), n_events)
assert_true('ECG-SYN' not in raw.ch_names)
assert_true('ECG-SYN' in ecg_epochs.ch_names)
picks = pick_types(
ecg_epochs.info, meg=False, eeg=False, stim=False,
eog=False, ecg=True, emg=False, ref_meg=False,
exclude='bads')
assert_true(len(picks) == 1)
示例5: test_check_compensation_consistency
def test_check_compensation_consistency():
"""Test check picks compensation."""
raw = read_raw_ctf(ctf_fname, preload=False)
events = make_fixed_length_events(raw, 99999)
picks = pick_types(raw.info, meg=True, exclude=[], ref_meg=True)
pick_ch_names = [raw.info['ch_names'][idx] for idx in picks]
for (comp, expected_result) in zip([0, 1], [False, False]):
raw.apply_gradient_compensation(comp)
ret, missing = _bad_chans_comp(raw.info, pick_ch_names)
assert ret == expected_result
assert len(missing) == 0
Epochs(raw, events, None, -0.2, 0.2, preload=False, picks=picks)
picks = pick_types(raw.info, meg=True, exclude=[], ref_meg=False)
pick_ch_names = [raw.info['ch_names'][idx] for idx in picks]
for (comp, expected_result) in zip([0, 1], [False, True]):
raw.apply_gradient_compensation(comp)
ret, missing = _bad_chans_comp(raw.info, pick_ch_names)
assert ret == expected_result
assert len(missing) == 17
with catch_logging() as log:
Epochs(raw, events, None, -0.2, 0.2, preload=False,
picks=picks, verbose=True)
assert'Removing 5 compensators' in log.getvalue()
示例6: test_simulate_raw_chpi
def test_simulate_raw_chpi():
"""Test simulation of raw data with cHPI"""
with warnings.catch_warnings(record=True): # MaxShield
raw = Raw(raw_chpi_fname, allow_maxshield=True)
sphere = make_sphere_model('auto', 'auto', raw.info)
# make sparse spherical source space
sphere_vol = tuple(sphere['r0'] * 1000.) + (sphere.radius * 1000.,)
src = setup_volume_source_space('sample', sphere=sphere_vol, pos=70.)
stc = _make_stc(raw, src)
# simulate data with cHPI on
raw_sim = simulate_raw(raw, stc, None, src, sphere, cov=None, chpi=False)
raw_chpi = simulate_raw(raw, stc, None, src, sphere, cov=None, chpi=True)
# XXX we need to test that the cHPI signals are actually in the correct
# place, but that should be a subsequent enhancement (not trivial to do so)
psd_sim, freqs_sim = compute_raw_psd(raw_sim)
psd_chpi, freqs_chpi = compute_raw_psd(raw_chpi)
assert_array_equal(freqs_sim, freqs_chpi)
hpi_freqs = np.array([x['custom_ref'][0]
for x in raw.info['hpi_meas'][0]['hpi_coils']])
freq_idx = np.sort([np.argmin(np.abs(freqs_sim - f)) for f in hpi_freqs])
picks_meg = pick_types(raw.info, meg=True, eeg=False)
picks_eeg = pick_types(raw.info, meg=False, eeg=True)
assert_allclose(psd_sim[picks_eeg], psd_chpi[picks_eeg])
assert_true((psd_chpi[picks_meg][:, freq_idx] >
100 * psd_sim[picks_meg][:, freq_idx]).all())
示例7: test_brainvision_data
def test_brainvision_data():
"""Test reading raw Brain Vision files
"""
assert_raises(IOError, read_raw_brainvision, vmrk_path)
assert_raises(ValueError, read_raw_brainvision, vhdr_path, montage,
preload=True, scale="foo")
raw_py = _test_raw_reader(read_raw_brainvision, test_preloading=True,
vhdr_fname=vhdr_path, montage=montage, eog=eog)
assert_true('RawBrainVision' in repr(raw_py))
assert_equal(raw_py.info['highpass'], 0.)
assert_equal(raw_py.info['lowpass'], 250.)
picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads')
data_py, times_py = raw_py[picks]
# 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
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'] == 'STI 014':
assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH)
elif ch['ch_name'] in raw_py.info['ch_names']:
assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH)
else:
raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
示例8: test_ransac
def test_ransac():
"""Some basic tests for ransac."""
event_id = {'Visual/Left': 3}
tmin, tmax = -0.2, 0.5
events = mne.find_events(raw)
epochs = mne.Epochs(raw, events, event_id, tmin, tmax,
baseline=(None, 0), decim=8,
reject=None, preload=True)
# normal case
picks = mne.pick_types(epochs.info, meg='mag', eeg=False, stim=False,
eog=False, exclude=[])
ransac = Ransac(picks=picks)
epochs_clean = ransac.fit_transform(epochs)
assert_true(len(epochs_clean) == len(epochs))
# Pass numpy instead of epochs
X = epochs.get_data()
assert_raises(AttributeError, ransac.fit, X)
#
# should not contain both channel types
picks = mne.pick_types(epochs.info, meg=True, eeg=False, stim=False,
eog=False, exclude=[])
ransac = Ransac(picks=picks)
assert_raises(ValueError, ransac.fit, epochs)
#
# should not contain other channel types.
picks = mne.pick_types(raw.info, meg=False, eeg=True, stim=True,
eog=False, exclude=[])
ransac = Ransac(picks=picks)
assert_raises(ValueError, ransac.fit, epochs)
示例9: test_clean_info_bads
def test_clean_info_bads():
"""Test cleaning info['bads'] when bad_channels are excluded """
raw_file = op.join(op.dirname(__file__), "io", "tests", "data", "test_raw.fif")
raw = Raw(raw_file)
# select eeg channels
picks_eeg = pick_types(raw.info, meg=False, eeg=True)
# select 3 eeg channels as bads
idx_eeg_bad_ch = picks_eeg[[1, 5, 14]]
eeg_bad_ch = [raw.info["ch_names"][k] for k in idx_eeg_bad_ch]
# select meg channels
picks_meg = pick_types(raw.info, meg=True, eeg=False)
# select randomly 3 meg channels as bads
idx_meg_bad_ch = picks_meg[[0, 15, 34]]
meg_bad_ch = [raw.info["ch_names"][k] for k in idx_meg_bad_ch]
# simulate the bad channels
raw.info["bads"] = eeg_bad_ch + meg_bad_ch
# simulate the call to pick_info excluding the bad eeg channels
info_eeg = pick_info(raw.info, picks_eeg)
# simulate the call to pick_info excluding the bad meg channels
info_meg = pick_info(raw.info, picks_meg)
assert_equal(info_eeg["bads"], eeg_bad_ch)
assert_equal(info_meg["bads"], meg_bad_ch)
示例10: test_pick_seeg_ecog
def test_pick_seeg_ecog():
"""Test picking with sEEG and ECoG
"""
names = 'A1 A2 Fz O OTp1 OTp2 E1 OTp3 E2 E3'.split()
types = 'mag mag eeg eeg seeg seeg ecog seeg ecog ecog'.split()
info = create_info(names, 1024., types)
idx = channel_indices_by_type(info)
assert_array_equal(idx['mag'], [0, 1])
assert_array_equal(idx['eeg'], [2, 3])
assert_array_equal(idx['seeg'], [4, 5, 7])
assert_array_equal(idx['ecog'], [6, 8, 9])
assert_array_equal(pick_types(info, meg=False, seeg=True), [4, 5, 7])
for i, t in enumerate(types):
assert_equal(channel_type(info, i), types[i])
raw = RawArray(np.zeros((len(names), 10)), info)
events = np.array([[1, 0, 0], [2, 0, 0]])
epochs = Epochs(raw, events, {'event': 0}, -1e-5, 1e-5, add_eeg_ref=False)
evoked = epochs.average(pick_types(epochs.info, meg=True, seeg=True))
e_seeg = evoked.copy().pick_types(meg=False, seeg=True)
for l, r in zip(e_seeg.ch_names, [names[4], names[5], names[7]]):
assert_equal(l, r)
# Deal with constant debacle
raw = read_raw_fif(op.join(io_dir, 'tests', 'data',
'test_chpi_raw_sss.fif'), add_eeg_ref=False)
assert_equal(len(pick_types(raw.info, meg=False, seeg=True, ecog=True)), 0)
示例11: test_load_fiff_from_raw
def test_load_fiff_from_raw():
"Test loading data from a fiff raw file"
ds = load.fiff.events(raw_path)
# test separate events
ds_evt = load.fiff.events(events=evt_path)
ds_evt.name = ds.name
assert_dataobj_equal(ds_evt, ds)
# add epochs as ndvar
ds = ds.sub('trigger == 32')
ds_ndvar = load.fiff.add_epochs(ds, -0.1, 0.3, decim=10, data='mag',
proj=False, reject=2e-12)
meg = ds_ndvar['meg']
eq_(meg.ndim, 3)
data = meg.get_data(('case', 'sensor', 'time'))
eq_(data.shape, (14, 102, 6))
# compare with mne epochs
ds_mne = load.fiff.add_mne_epochs(ds, -0.1, 0.3, decim=10, proj=False,
reject={'mag': 2e-12})
epochs = ds_mne['epochs']
picks = pick_types(epochs.info, meg='mag')
mne_data = epochs.get_data()[:, picks]
eq_(meg.sensor.names, [epochs.info['ch_names'][i] for i in picks])
assert_array_equal(data, mne_data)
# with proj
meg = load.fiff.epochs(ds, -0.1, 0.3, decim=10, data='mag', proj=True,
reject=2e-12)
epochs = load.fiff.mne_epochs(ds, -0.1, 0.3, decim=10, proj=True,
reject={'mag': 2e-12})
picks = pick_types(epochs.info, meg='mag')
mne_data = epochs.get_data()[:, picks]
assert_array_almost_equal(meg.x, mne_data, 10)
示例12: 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'])
示例13: interpolate_bads
def interpolate_bads(inst, picks, dots=None, reset_bads=True, mode='accurate'):
"""Interpolate bad MEG and EEG channels."""
import mne
# to prevent cobyla printf error
# XXX putting to critical for now unless better solution
# emerges
verbose = mne.set_log_level('CRITICAL', return_old_level=True)
eeg_picks = set(pick_types(inst.info, meg=False, eeg=True, exclude=[]))
eeg_picks_interp = [p for p in picks if p in eeg_picks]
if len(eeg_picks_interp) > 0:
_interpolate_bads_eeg(inst, picks=eeg_picks_interp)
meg_picks = set(pick_types(inst.info, meg=True, eeg=False, exclude=[]))
meg_picks_interp = [p for p in picks if p in meg_picks]
if len(meg_picks_interp) > 0:
_interpolate_bads_meg_fast(inst, picks=meg_picks_interp,
dots=dots, mode=mode)
if reset_bads is True:
inst.info['bads'] = []
mne.set_log_level(verbose)
return inst
示例14: test_epochs_proj
def test_epochs_proj():
"""Test handling projection (apply proj in Raw or in Epochs)
"""
exclude = raw.info["bads"] + ["MEG 2443", "EEG 053"] # bads + 2 more
this_picks = pick_types(raw.info, meg=True, eeg=False, stim=True, eog=True, exclude=exclude)
epochs = Epochs(raw, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=True)
assert_true(all(p["active"] is True for p in epochs.info["projs"]))
evoked = epochs.average()
assert_true(all(p["active"] is True for p in evoked.info["projs"]))
data = epochs.get_data()
raw_proj = io.Raw(raw_fname, proj=True)
epochs_no_proj = Epochs(
raw_proj, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=False
)
data_no_proj = epochs_no_proj.get_data()
assert_true(all(p["active"] is True for p in epochs_no_proj.info["projs"]))
evoked_no_proj = epochs_no_proj.average()
assert_true(all(p["active"] is True for p in evoked_no_proj.info["projs"]))
assert_true(epochs_no_proj.proj is True) # as projs are active from Raw
assert_array_almost_equal(data, data_no_proj, decimal=8)
# make sure we can exclude avg ref
this_picks = pick_types(raw.info, meg=True, eeg=True, stim=True, eog=True, exclude=exclude)
epochs = Epochs(
raw, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=True, add_eeg_ref=True
)
assert_true(_has_eeg_average_ref_proj(epochs.info["projs"]))
epochs = Epochs(
raw, events[:4], event_id, tmin, tmax, picks=this_picks, baseline=(None, 0), proj=True, add_eeg_ref=False
)
assert_true(not _has_eeg_average_ref_proj(epochs.info["projs"]))
示例15: get_data_picks
def get_data_picks(inst, meg_combined=False):
"""Get data channel indices as separate list of tuples
Parameters
----------
inst : instance of mne.measuerment_info.Info
The info
meg_combined : bool
Whether to return combined picks for grad and mag.
Returns
-------
picks_list : list of tuples
The list of tuples of picks and the type string.
"""
info = inst.info
picks_list = []
has_mag, has_grad, has_eeg = [k in inst for k in ('mag', 'grad', 'eeg')]
if has_mag and (meg_combined is not True or not has_grad):
picks_list.append(
(pick_types(info, meg='mag', eeg=False, stim=False), 'mag')
)
if has_grad and (meg_combined is not True or not has_mag):
picks_list.append(
(pick_types(info, meg='grad', eeg=False, stim=False), 'grad')
)
if has_mag and has_grad and meg_combined is True:
picks_list.append(
(pick_types(info, meg=True, eeg=False, stim=False), 'meg')
)
if has_eeg:
picks_list.append(
(pick_types(info, meg=False, eeg=True, stim=False), 'eeg')
)
return picks_list