本文整理汇总了Python中mne.datasets.testing.data_path函数的典型用法代码示例。如果您正苦于以下问题:Python data_path函数的具体用法?Python data_path怎么用?Python data_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了data_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_eximia_nxe
def test_eximia_nxe():
"""Test reading Eximia NXE files"""
fname = op.join(data_path(), 'eximia', 'test_eximia.nxe')
raw = read_raw_eximia(fname, preload=True)
assert_true('RawEximia' in repr(raw))
_test_raw_reader(read_raw_eximia, fname=fname)
fname_mat = op.join(data_path(), 'eximia', 'test_eximia.mat')
mc = sio.loadmat(fname_mat)
m_data = mc['data']
m_header = mc['header']
assert_equal(raw._data.shape, m_data.shape)
assert_equal(m_header['Fs'][0, 0][0, 0], raw.info['sfreq'])
m_names = [x[0][0] for x in m_header['label'][0, 0]]
m_names = list(
map(lambda x: x.replace('GATE', 'GateIn').replace('TRIG', 'Trig'),
m_names))
assert_equal(raw.ch_names, m_names)
m_ch_types = [x[0][0] for x in m_header['chantype'][0, 0]]
m_ch_types = list(
map(lambda x: x.replace('unknown', 'stim').replace('trigger', 'stim'),
m_ch_types))
types_dict = {2: 'eeg', 3: 'stim', 202: 'eog'}
ch_types = [types_dict[raw.info['chs'][x]['kind']]
for x in range(len(raw.ch_names))]
assert_equal(ch_types, m_ch_types)
assert_array_equal(m_data, raw._data)
示例2: test_io_egi_pns_mff_bug
def test_io_egi_pns_mff_bug():
"""Test importing EGI MFF with PNS data (BUG)."""
egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi_pns_bug.mff')
with pytest.warns(RuntimeWarning, match='EGI PSG sample bug'):
raw = read_raw_egi(egi_fname_mff, include=None, preload=True,
verbose='warning')
egi_fname_mat = op.join(data_path(), 'EGI', 'test_egi_pns.mat')
mc = sio.loadmat(egi_fname_mat)
pns_chans = pick_types(raw.info, ecg=True, bio=True, emg=True)
pns_names = ['Resp. Temperature'[:15],
'Resp. Pressure',
'ECG',
'Body Position',
'Resp. Effort Chest'[:15],
'Resp. Effort Abdomen'[:15],
'EMG-Leg']
mat_names = [
'Resp_Temperature'[:15],
'Resp_Pressure',
'ECG',
'Body_Position',
'Resp_Effort_Chest'[:15],
'Resp_Effort_Abdomen'[:15],
'EMGLeg'
]
for ch_name, ch_idx, mat_name in zip(pns_names, pns_chans, mat_names):
print('Testing {}'.format(ch_name))
mc_key = [x for x in mc.keys() if mat_name in x][0]
cal = raw.info['chs'][ch_idx]['cal']
mat_data = mc[mc_key] * cal
mat_data[:, -1] = 0 # The MFF has one less sample, the last one
raw_data = raw[ch_idx][0]
assert_array_equal(mat_data, raw_data)
示例3: test_io_egi_mff
def test_io_egi_mff():
"""Test importing EGI MFF simple binary files."""
egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi.mff')
raw = read_raw_egi(egi_fname_mff, include=None)
assert ('RawMff' in repr(raw))
include = ['DIN1', 'DIN2', 'DIN3', 'DIN4', 'DIN5', 'DIN7']
raw = _test_raw_reader(read_raw_egi, input_fname=egi_fname_mff,
include=include, channel_naming='EEG %03d')
assert_equal('eeg' in raw, True)
eeg_chan = [c for c in raw.ch_names if 'EEG' in c]
assert_equal(len(eeg_chan), 129)
picks = pick_types(raw.info, eeg=True)
assert_equal(len(picks), 129)
assert_equal('STI 014' in raw.ch_names, True)
events = find_events(raw, stim_channel='STI 014')
assert_equal(len(events), 8)
assert_equal(np.unique(events[:, 1])[0], 0)
assert (np.unique(events[:, 0])[0] != 0)
assert (np.unique(events[:, 2])[0] != 0)
pytest.raises(ValueError, read_raw_egi, egi_fname_mff, include=['Foo'],
preload=False)
pytest.raises(ValueError, read_raw_egi, egi_fname_mff, exclude=['Bar'],
preload=False)
for ii, k in enumerate(include, 1):
assert (k in raw.event_id)
assert (raw.event_id[k] == ii)
示例4: test_maxwell_filter_additional
def test_maxwell_filter_additional():
"""Test processing of Maxwell filtered data"""
# TODO: Future tests integrate with mne/io/tests/test_proc_history
# Load testing data (raw, SSS std origin, SSS non-standard origin)
data_path = op.join(testing.data_path(download=False))
file_name = 'test_move_anon'
raw_fname = op.join(data_path, 'SSS', file_name + '_raw.fif')
with warnings.catch_warnings(record=True): # maxshield
raw = Raw(raw_fname, preload=False, proj=False,
allow_maxshield=True).crop(0., 1., False)
raw_sss = maxwell.maxwell_filter(raw)
# Test io on processed data
tempdir = _TempDir()
test_outname = op.join(tempdir, 'test_raw_sss.fif')
raw_sss.save(test_outname)
raw_sss_loaded = Raw(test_outname, preload=True, proj=False,
allow_maxshield=True)
# Some numerical imprecision since save uses 'single' fmt
assert_allclose(raw_sss_loaded._data[:, :], raw_sss._data[:, :],
rtol=1e-6, atol=1e-20)
示例5: test_find_ch_connectivity
def test_find_ch_connectivity():
"""Test computing the connectivity matrix."""
data_path = testing.data_path()
raw = read_raw_fif(raw_fname, preload=True)
sizes = {'mag': 828, 'grad': 1700, 'eeg': 386}
nchans = {'mag': 102, 'grad': 204, 'eeg': 60}
for ch_type in ['mag', 'grad', 'eeg']:
conn, ch_names = find_ch_connectivity(raw.info, ch_type)
# Silly test for checking the number of neighbors.
assert_equal(conn.getnnz(), sizes[ch_type])
assert_equal(len(ch_names), nchans[ch_type])
pytest.raises(ValueError, find_ch_connectivity, raw.info, None)
# Test computing the conn matrix with gradiometers.
conn, ch_names = _compute_ch_connectivity(raw.info, 'grad')
assert_equal(conn.getnnz(), 2680)
# Test ch_type=None.
raw.pick_types(meg='mag')
find_ch_connectivity(raw.info, None)
bti_fname = op.join(data_path, 'BTi', 'erm_HFH', 'c,rfDC')
bti_config_name = op.join(data_path, 'BTi', 'erm_HFH', 'config')
raw = read_raw_bti(bti_fname, bti_config_name, None)
_, ch_names = find_ch_connectivity(raw.info, 'mag')
assert 'A1' in ch_names
ctf_fname = op.join(data_path, 'CTF', 'testdata_ctf_short.ds')
raw = read_raw_ctf(ctf_fname)
_, ch_names = find_ch_connectivity(raw.info, 'mag')
assert 'MLC11' in ch_names
pytest.raises(ValueError, find_ch_connectivity, raw.info, 'eog')
示例6: test_events_long
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)
示例7: test_interpolation_ctf_comp
def test_interpolation_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 = io.read_raw_ctf(raw_fname, preload=True)
raw.info['bads'] = [raw.ch_names[5], raw.ch_names[-5]]
raw.interpolate_bads(mode='fast')
assert raw.info['bads'] == []
示例8: test_io_egi_crop_no_preload
def test_io_egi_crop_no_preload():
"""Test crop non-preloaded EGI MFF data (BUG)."""
egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi.mff')
raw = read_raw_egi(egi_fname_mff, preload=False)
raw.crop(17.5, 20.5)
raw.load_data()
raw_preload = read_raw_egi(egi_fname_mff, preload=True)
raw_preload.crop(17.5, 20.5)
raw_preload.load_data()
assert_allclose(raw._data, raw_preload._data)
示例9: test_inverse_ctf_comp
def test_inverse_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)
raw.apply_gradient_compensation(1)
sphere = make_sphere_model()
cov = make_ad_hoc_cov(raw.info)
src = mne.setup_volume_source_space(
pos=dict(rr=[[0., 0., 0.01]], nn=[[0., 1., 0.]]))
fwd = make_forward_solution(raw.info, None, src, sphere, eeg=False)
inv = make_inverse_operator(raw.info, fwd, cov, loose=1.)
apply_inverse_raw(raw, inv, 1. / 9.)
示例10: test_io_egi_pns_mff
def test_io_egi_pns_mff():
"""Test importing EGI MFF with PNS data."""
egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi_pns.mff')
raw = read_raw_egi(egi_fname_mff, include=None, preload=True,
verbose='error')
assert ('RawMff' in repr(raw))
pns_chans = pick_types(raw.info, ecg=True, bio=True, emg=True)
assert_equal(len(pns_chans), 7)
names = [raw.ch_names[x] for x in pns_chans]
pns_names = ['Resp. Temperature'[:15],
'Resp. Pressure',
'ECG',
'Body Position',
'Resp. Effort Chest'[:15],
'Resp. Effort Abdomen'[:15],
'EMG-Leg']
_test_raw_reader(read_raw_egi, input_fname=egi_fname_mff,
channel_naming='EEG %03d', verbose='error')
assert_equal(names, pns_names)
mat_names = [
'Resp_Temperature'[:15],
'Resp_Pressure',
'ECG',
'Body_Position',
'Resp_Effort_Chest'[:15],
'Resp_Effort_Abdomen'[:15],
'EMGLeg'
]
egi_fname_mat = op.join(data_path(), 'EGI', 'test_egi_pns.mat')
mc = sio.loadmat(egi_fname_mat)
for ch_name, ch_idx, mat_name in zip(pns_names, pns_chans, mat_names):
print('Testing {}'.format(ch_name))
mc_key = [x for x in mc.keys() if mat_name in x][0]
cal = raw.info['chs'][ch_idx]['cal']
mat_data = mc[mc_key] * cal
raw_data = raw[ch_idx][0]
assert_array_equal(mat_data, raw_data)
示例11: test_eeglab_event_from_annot
def test_eeglab_event_from_annot():
"""Test all forms of obtaining annotations."""
base_dir = op.join(testing.data_path(download=False), 'EEGLAB')
raw_fname_mat = op.join(base_dir, 'test_raw.set')
raw_fname = raw_fname_mat
montage = op.join(base_dir, 'test_chans.locs')
event_id = {'rt': 1, 'square': 2}
raw1 = read_raw_eeglab(input_fname=raw_fname, montage=montage,
preload=False)
annotations = read_annotations(raw_fname)
assert len(raw1.annotations) == 154
raw1.set_annotations(annotations)
events_b, _ = events_from_annotations(raw1, event_id=event_id)
assert len(events_b) == 154
示例12: test_plot_ctf
def test_plot_ctf():
"""Test plotting of CTF evoked."""
ctf_dir = op.join(testing.data_path(download=False), 'CTF')
raw_fname = op.join(ctf_dir, 'testdata_ctf.ds')
raw = mne.io.read_raw_ctf(raw_fname, preload=True)
events = np.array([[200, 0, 1]])
event_id = 1
tmin, tmax = -0.1, 0.5 # start and end of an epoch in sec.
picks = mne.pick_types(raw.info, meg=True, stim=True, eog=True,
ref_meg=True, exclude='bads')[::20]
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=picks, preload=True, decim=10, verbose='error')
evoked = epochs.average()
evoked.plot_joint(times=[0.1])
mne.viz.plot_compare_evokeds([evoked, evoked])
示例13: test_maxwell_filter_additional
def test_maxwell_filter_additional():
"""Test processing of Maxwell filtered data"""
# TODO: Future tests integrate with mne/io/tests/test_proc_history
# Load testing data (raw, SSS std origin, SSS non-standard origin)
data_path = op.join(testing.data_path(download=False))
file_name = 'test_move_anon'
raw_fname = op.join(data_path, 'SSS', file_name + '_raw.fif')
with warnings.catch_warnings(record=True): # maxshield
# Use 2.0 seconds of data to get stable cov. estimate
raw = Raw(raw_fname, preload=False, proj=False,
allow_maxshield=True).crop(0., 2., False)
# Get MEG channels, compute Maxwell filtered data
raw.load_data()
raw.pick_types(meg=True, eeg=False)
int_order, ext_order = 8, 3
raw_sss = maxwell.maxwell_filter(raw, int_order=int_order,
ext_order=ext_order)
# Test io on processed data
tempdir = _TempDir()
test_outname = op.join(tempdir, 'test_raw_sss.fif')
raw_sss.save(test_outname)
raw_sss_loaded = Raw(test_outname, preload=True, proj=False,
allow_maxshield=True)
# Some numerical imprecision since save uses 'single' fmt
assert_allclose(raw_sss_loaded._data[:, :], raw_sss._data[:, :],
rtol=1e-6, atol=1e-20)
# Test rank of covariance matrices for raw and SSS processed data
cov_raw = compute_raw_covariance(raw)
cov_sss = compute_raw_covariance(raw_sss)
scalings = None
cov_raw_rank = _estimate_rank_meeg_cov(cov_raw['data'], raw.info, scalings)
cov_sss_rank = _estimate_rank_meeg_cov(cov_sss['data'], raw_sss.info,
scalings)
assert_equal(cov_raw_rank, raw.info['nchan'])
assert_equal(cov_sss_rank, maxwell.get_num_moments(int_order, 0))
示例14: test_add_noise
def test_add_noise():
"""Test noise addition."""
rng = np.random.RandomState(0)
data_path = testing.data_path()
raw = read_raw_fif(data_path + '/MEG/sample/sample_audvis_trunc_raw.fif')
raw.del_proj()
picks = pick_types(raw.info, eeg=True, exclude=())
cov = compute_raw_covariance(raw, picks=picks)
with pytest.raises(RuntimeError, match='to be loaded'):
add_noise(raw, cov)
raw.crop(0, 1).load_data()
with pytest.raises(TypeError, match='Raw, Epochs, or Evoked'):
add_noise(0., cov)
with pytest.raises(TypeError, match='Covariance'):
add_noise(raw, 0.)
# test a no-op (data preserved)
orig_data = raw[:][0]
zero_cov = cov.copy()
zero_cov['data'].fill(0)
add_noise(raw, zero_cov)
new_data = raw[:][0]
assert_allclose(orig_data, new_data, atol=1e-30)
# set to zero to make comparisons easier
raw._data[:] = 0.
epochs = EpochsArray(np.zeros((1, len(raw.ch_names), 100)),
raw.info.copy())
epochs.info['bads'] = []
evoked = epochs.average(picks=np.arange(len(raw.ch_names)))
for inst in (raw, epochs, evoked):
with catch_logging() as log:
add_noise(inst, cov, random_state=rng, verbose=True)
log = log.getvalue()
want = ('to {0}/{1} channels ({0}'
.format(len(cov['names']), len(raw.ch_names)))
assert want in log
if inst is evoked:
inst = EpochsArray(inst.data[np.newaxis], inst.info)
if inst is raw:
cov_new = compute_raw_covariance(inst, picks=picks,
verbose='error') # samples
else:
cov_new = compute_covariance(inst, verbose='error') # avg ref
assert cov['names'] == cov_new['names']
r = np.corrcoef(cov['data'].ravel(), cov_new['data'].ravel())[0, 1]
assert r > 0.99
示例15: 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