本文整理汇总了Python中mne.io.read_info函数的典型用法代码示例。如果您正苦于以下问题:Python read_info函数的具体用法?Python read_info怎么用?Python read_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_helmet
def test_helmet():
"""Test loading helmet surfaces."""
base_dir = op.join(op.dirname(__file__), '..', 'io')
fname_raw = op.join(base_dir, 'tests', 'data', 'test_raw.fif')
fname_kit_raw = op.join(base_dir, 'kit', 'tests', 'data',
'test_bin_raw.fif')
fname_bti_raw = op.join(base_dir, 'bti', 'tests', 'data',
'exported4D_linux_raw.fif')
fname_ctf_raw = op.join(base_dir, 'tests', 'data', 'test_ctf_raw.fif')
fname_trans = op.join(base_dir, 'tests', 'data',
'sample-audvis-raw-trans.txt')
trans = _get_trans(fname_trans)[0]
new_info = read_info(fname_raw)
artemis_info = new_info.copy()
for pick in pick_types(new_info):
new_info['chs'][pick]['coil_type'] = 9999
artemis_info['chs'][pick]['coil_type'] = \
FIFF.FIFFV_COIL_ARTEMIS123_GRAD
for info, n, name in [(read_info(fname_raw), 304, '306m'),
(read_info(fname_kit_raw), 304, 'KIT'),
(read_info(fname_bti_raw), 304, 'Magnes'),
(read_info(fname_ctf_raw), 342, 'CTF'),
(new_info, 102, 'unknown'),
(artemis_info, 102, 'ARTEMIS123')
]:
with catch_logging() as log:
helmet = get_meg_helmet_surf(info, trans, verbose=True)
log = log.getvalue()
assert name in log
assert_equal(len(helmet['rr']), n)
assert_equal(len(helmet['rr']), len(helmet['nn']))
示例2: test_read_write_info
def test_read_write_info():
"""Test IO of info
"""
tempdir = _TempDir()
info = read_info(raw_fname)
temp_file = op.join(tempdir, 'info.fif')
# check for bug `#1198`
info['dev_head_t']['trans'] = np.eye(4)
t1 = info['dev_head_t']['trans']
write_info(temp_file, info)
info2 = read_info(temp_file)
t2 = info2['dev_head_t']['trans']
assert_true(len(info['chs']) == len(info2['chs']))
assert_array_equal(t1, t2)
# proc_history (e.g., GH#1875)
creator = u'é'
info = read_info(chpi_fname)
info['proc_history'][0]['creator'] = creator
info['hpi_meas'][0]['creator'] = creator
info['subject_info']['his_id'] = creator
write_info(temp_file, info)
info = read_info(temp_file)
assert_equal(info['proc_history'][0]['creator'], creator)
assert_equal(info['hpi_meas'][0]['creator'], creator)
assert_equal(info['subject_info']['his_id'], creator)
示例3: test_read_write_info
def test_read_write_info():
"""Test IO of info."""
tempdir = _TempDir()
info = read_info(raw_fname)
temp_file = op.join(tempdir, 'info.fif')
# check for bug `#1198`
info['dev_head_t']['trans'] = np.eye(4)
t1 = info['dev_head_t']['trans']
write_info(temp_file, info)
info2 = read_info(temp_file)
t2 = info2['dev_head_t']['trans']
assert_true(len(info['chs']) == len(info2['chs']))
assert_array_equal(t1, t2)
# proc_history (e.g., GH#1875)
creator = u'é'
info = read_info(chpi_fname)
info['proc_history'][0]['creator'] = creator
info['hpi_meas'][0]['creator'] = creator
info['subject_info']['his_id'] = creator
if info['gantry_angle'] is None: # future testing data may include it
info['gantry_angle'] = 0. # Elekta supine position
gantry_angle = info['gantry_angle']
write_info(temp_file, info)
info = read_info(temp_file)
assert_equal(info['proc_history'][0]['creator'], creator)
assert_equal(info['hpi_meas'][0]['creator'], creator)
assert_equal(info['subject_info']['his_id'], creator)
assert_equal(info['gantry_angle'], gantry_angle)
示例4: test_csr_csc
def test_csr_csc():
"""Test CSR and CSC."""
info = read_info(sss_ctc_fname)
info = pick_info(info, pick_types(info, meg=True, exclude=[]))
sss_ctc = info['proc_history'][0]['max_info']['sss_ctc']
ct = sss_ctc['decoupler'].copy()
# CSC
assert isinstance(ct, sparse.csc_matrix)
tempdir = _TempDir()
fname = op.join(tempdir, 'test.fif')
write_info(fname, info)
info_read = read_info(fname)
ct_read = info_read['proc_history'][0]['max_info']['sss_ctc']['decoupler']
assert isinstance(ct_read, sparse.csc_matrix)
assert_array_equal(ct_read.toarray(), ct.toarray())
# Now CSR
csr = ct.tocsr()
assert isinstance(csr, sparse.csr_matrix)
assert_array_equal(csr.toarray(), ct.toarray())
info['proc_history'][0]['max_info']['sss_ctc']['decoupler'] = csr
fname = op.join(tempdir, 'test1.fif')
write_info(fname, info)
info_read = read_info(fname)
ct_read = info_read['proc_history'][0]['max_info']['sss_ctc']['decoupler']
assert isinstance(ct_read, sparse.csc_matrix) # this gets cast to CSC
assert_array_equal(ct_read.toarray(), ct.toarray())
示例5: test_read_write_info
def test_read_write_info():
"""Test IO of info."""
tempdir = _TempDir()
info = read_info(raw_fname)
temp_file = op.join(tempdir, 'info.fif')
# check for bug `#1198`
info['dev_head_t']['trans'] = np.eye(4)
t1 = info['dev_head_t']['trans']
write_info(temp_file, info)
info2 = read_info(temp_file)
t2 = info2['dev_head_t']['trans']
assert (len(info['chs']) == len(info2['chs']))
assert_array_equal(t1, t2)
# proc_history (e.g., GH#1875)
creator = u'é'
info = read_info(chpi_fname)
info['proc_history'][0]['creator'] = creator
info['hpi_meas'][0]['creator'] = creator
info['subject_info']['his_id'] = creator
info['subject_info']['weight'] = 11.1
info['subject_info']['height'] = 2.3
if info['gantry_angle'] is None: # future testing data may include it
info['gantry_angle'] = 0. # Elekta supine position
gantry_angle = info['gantry_angle']
meas_id = info['meas_id']
write_info(temp_file, info)
info = read_info(temp_file)
assert info['proc_history'][0]['creator'] == creator
assert info['hpi_meas'][0]['creator'] == creator
assert info['subject_info']['his_id'] == creator
assert info['gantry_angle'] == gantry_angle
assert info['subject_info']['height'] == 2.3
assert info['subject_info']['weight'] == 11.1
for key in ['secs', 'usecs', 'version']:
assert info['meas_id'][key] == meas_id[key]
assert_array_equal(info['meas_id']['machid'], meas_id['machid'])
# Test that writing twice produces the same file
m1 = hashlib.md5()
with open(temp_file, 'rb') as fid:
m1.update(fid.read())
m1 = m1.hexdigest()
temp_file_2 = op.join(tempdir, 'info2.fif')
assert temp_file_2 != temp_file
write_info(temp_file_2, info)
m2 = hashlib.md5()
with open(temp_file_2, 'rb') as fid:
m2.update(fid.read())
m2 = m2.hexdigest()
assert m1 == m2
示例6: test_read_write_info
def test_read_write_info():
"""Test IO of info
"""
info = io.read_info(raw_fname)
temp_file = op.join(tempdir, 'info.fif')
# check for bug `#1198`
info['dev_head_t']['trans'] = np.eye(4)
t1 = info['dev_head_t']['trans']
io.write_info(temp_file, info)
info2 = io.read_info(temp_file)
t2 = info2['dev_head_t']['trans']
assert_true(len(info['chs']) == len(info2['chs']))
assert_array_equal(t1, t2)
示例7: test_priors
def test_priors():
"""Test prior computations."""
# Depth prior
fwd = read_forward_solution(fname_meeg)
assert not is_fixed_orient(fwd)
n_sources = fwd['nsource']
info = read_info(fname_evoked)
depth_prior = compute_depth_prior(fwd, info, exp=0.8)
assert depth_prior.shape == (3 * n_sources,)
depth_prior = compute_depth_prior(fwd, info, exp=0.)
assert_array_equal(depth_prior, 1.)
with pytest.raises(ValueError, match='must be "whiten"'):
compute_depth_prior(fwd, info, limit_depth_chs='foo')
with pytest.raises(ValueError, match='noise_cov must be a Covariance'):
compute_depth_prior(fwd, info, limit_depth_chs='whiten')
fwd_fixed = convert_forward_solution(fwd, force_fixed=True)
with pytest.deprecated_call():
depth_prior = compute_depth_prior(
fwd_fixed['sol']['data'], info, is_fixed_ori=True)
assert depth_prior.shape == (n_sources,)
# Orientation prior
orient_prior = compute_orient_prior(fwd, 1.)
assert_array_equal(orient_prior, 1.)
orient_prior = compute_orient_prior(fwd_fixed, 0.)
assert_array_equal(orient_prior, 1.)
with pytest.raises(ValueError, match='oriented in surface coordinates'):
compute_orient_prior(fwd, 0.5)
fwd_surf_ori = convert_forward_solution(fwd, surf_ori=True)
orient_prior = compute_orient_prior(fwd_surf_ori, 0.5)
assert all(np.in1d(orient_prior, (0.5, 1.)))
with pytest.raises(ValueError, match='between 0 and 1'):
compute_orient_prior(fwd_surf_ori, -0.5)
with pytest.raises(ValueError, match='with fixed orientation'):
compute_orient_prior(fwd_fixed, 0.5)
示例8: test_rename_channels
def test_rename_channels():
"""Test rename channels"""
info = read_info(raw_fname)
# Error Tests
# Test channel name exists in ch_names
mapping = {'EEG 160': 'EEG060'}
assert_raises(ValueError, rename_channels, info, mapping)
# Test improper mapping configuration
mapping = {'MEG 2641': 1.0}
assert_raises(ValueError, rename_channels, info, mapping)
# Test non-unique mapping configuration
mapping = {'MEG 2641': 'MEG 2642'}
assert_raises(ValueError, rename_channels, info, mapping)
# Test bad input
assert_raises(ValueError, rename_channels, info, 1.)
# Test successful changes
# Test ch_name and ch_names are changed
info2 = deepcopy(info) # for consistency at the start of each test
info2['bads'] = ['EEG 060', 'EOG 061']
mapping = {'EEG 060': 'EEG060', 'EOG 061': 'EOG061'}
rename_channels(info2, mapping)
assert_true(info2['chs'][374]['ch_name'] == 'EEG060')
assert_true(info2['ch_names'][374] == 'EEG060')
assert_true(info2['chs'][375]['ch_name'] == 'EOG061')
assert_true(info2['ch_names'][375] == 'EOG061')
assert_array_equal(['EEG060', 'EOG061'], info2['bads'])
info2 = deepcopy(info)
rename_channels(info2, lambda x: x.replace(' ', ''))
assert_true(info2['chs'][373]['ch_name'] == 'EEG059')
info2 = deepcopy(info)
info2['bads'] = ['EEG 060', 'EEG 060']
rename_channels(info2, mapping)
assert_array_equal(['EEG060', 'EEG060'], info2['bads'])
示例9: test_rename_channels
def test_rename_channels():
"""Test rename channels
"""
info = read_info(raw_fname)
# Error Tests
# Test channel name exists in ch_names
mapping = {'EEG 160': 'EEG060'}
assert_raises(ValueError, rename_channels, info, mapping)
# Test change to EEG channel
mapping = {'EOG 061': ('EEG 061', 'eeg')}
with warnings.catch_warnings(record=True):
assert_raises(ValueError, rename_channels, info, mapping)
# Test change to illegal channel type
mapping = {'EOG 061': ('MEG 061', 'meg')}
with warnings.catch_warnings(record=True):
assert_raises(ValueError, rename_channels, info, mapping)
# Test channel type which you are changing from e.g. MEG
mapping = {'MEG 2641': ('MEG2641', 'eeg')}
with warnings.catch_warnings(record=True):
assert_raises(ValueError, rename_channels, info, mapping)
# Test improper mapping configuration
mapping = {'MEG 2641': 1.0}
assert_raises(ValueError, rename_channels, info, mapping)
# Test successful changes
# Test ch_name and ch_names are changed
info2 = deepcopy(info) # for consistency at the start of each test
info2['bads'] = ['EEG 060', 'EOG 061']
mapping = {'EEG 060': 'EEG060', 'EOG 061': 'EOG061'}
rename_channels(info2, mapping)
assert_true(info2['chs'][374]['ch_name'] == 'EEG060')
assert_true(info2['ch_names'][374] == 'EEG060')
assert_true('EEG060' in info2['bads'])
assert_true(info2['chs'][375]['ch_name'] == 'EOG061')
assert_true(info2['ch_names'][375] == 'EOG061')
assert_true('EOG061' in info2['bads'])
示例10: test_make_sphere_model
def test_make_sphere_model():
"""Test making a sphere model."""
info = read_info(fname_raw)
pytest.raises(ValueError, make_sphere_model, 'foo', 'auto', info)
pytest.raises(ValueError, make_sphere_model, 'auto', 'auto', None)
pytest.raises(ValueError, make_sphere_model, 'auto', 'auto', info,
relative_radii=(), sigmas=())
pytest.raises(ValueError, make_sphere_model, 'auto', 'auto', info,
relative_radii=(1,)) # wrong number of radii
# here we just make sure it works -- the functionality is actually
# tested more extensively e.g. in the forward and dipole code
with catch_logging() as log:
bem = make_sphere_model('auto', 'auto', info, verbose=True)
log = log.getvalue()
assert ' RV = ' in log
for line in log.split('\n'):
if ' RV = ' in line:
val = float(line.split()[-2])
assert val < 0.01 # actually decent fitting
break
assert '3 layers' in repr(bem)
assert 'Sphere ' in repr(bem)
assert ' mm' in repr(bem)
bem = make_sphere_model('auto', None, info)
assert 'no layers' in repr(bem)
assert 'Sphere ' in repr(bem)
pytest.raises(ValueError, make_sphere_model, sigmas=(0.33,),
relative_radii=(1.0,))
示例11: test_head_translation
def test_head_translation():
"""Test Maxwell filter head translation."""
raw = read_crop(raw_fname, (0., 1.))
# First try with an unchanged destination
with use_coil_def(elekta_def_fname):
raw_sss = maxwell_filter(raw, destination=raw_fname,
origin=mf_head_origin, regularize=None,
bad_condition='ignore')
assert_meg_snr(raw_sss, read_crop(sss_std_fname, (0., 1.)), 200.)
# Now with default
with use_coil_def(elekta_def_fname):
with pytest.warns(RuntimeWarning, match='over 25 mm'):
raw_sss = maxwell_filter(raw, destination=mf_head_origin,
origin=mf_head_origin, regularize=None,
bad_condition='ignore', verbose=True)
assert_meg_snr(raw_sss, read_crop(sss_trans_default_fname), 125.)
destination = np.eye(4)
destination[2, 3] = 0.04
assert_allclose(raw_sss.info['dev_head_t']['trans'], destination)
# Now to sample's head pos
with pytest.warns(RuntimeWarning, match='= 25.6 mm'):
raw_sss = maxwell_filter(raw, destination=sample_fname,
origin=mf_head_origin, regularize=None,
bad_condition='ignore', verbose=True)
assert_meg_snr(raw_sss, read_crop(sss_trans_sample_fname), 13., 100.)
assert_allclose(raw_sss.info['dev_head_t']['trans'],
read_info(sample_fname)['dev_head_t']['trans'])
# Degenerate cases
pytest.raises(RuntimeError, maxwell_filter, raw,
destination=mf_head_origin, coord_frame='meg')
pytest.raises(ValueError, maxwell_filter, raw, destination=[0.] * 4)
示例12: test_head_translation
def test_head_translation():
"""Test Maxwell filter head translation"""
with warnings.catch_warnings(record=True): # maxshield
raw = Raw(raw_fname, allow_maxshield=True).crop(0., 1., False)
# First try with an unchanged destination
raw_sss = maxwell_filter(raw, destination=raw_fname,
origin=mf_head_origin, regularize=None,
bad_condition='ignore')
assert_meg_snr(raw_sss, Raw(sss_std_fname).crop(0., 1., False), 200.)
# Now with default
with warnings.catch_warnings(record=True):
with catch_logging() as log:
raw_sss = maxwell_filter(raw, destination=mf_head_origin,
origin=mf_head_origin, regularize=None,
bad_condition='ignore', verbose='warning')
assert_true('over 25 mm' in log.getvalue())
assert_meg_snr(raw_sss, Raw(sss_trans_default_fname), 125.)
destination = np.eye(4)
destination[2, 3] = 0.04
assert_allclose(raw_sss.info['dev_head_t']['trans'], destination)
# Now to sample's head pos
with warnings.catch_warnings(record=True):
with catch_logging() as log:
raw_sss = maxwell_filter(raw, destination=sample_fname,
origin=mf_head_origin, regularize=None,
bad_condition='ignore', verbose='warning')
assert_true('= 25.6 mm' in log.getvalue())
assert_meg_snr(raw_sss, Raw(sss_trans_sample_fname), 350.)
assert_allclose(raw_sss.info['dev_head_t']['trans'],
read_info(sample_fname)['dev_head_t']['trans'])
# Degenerate cases
assert_raises(RuntimeError, maxwell_filter, raw,
destination=mf_head_origin, coord_frame='meg')
assert_raises(ValueError, maxwell_filter, raw, destination=[0.] * 4)
示例13: test_make_sphere_model
def test_make_sphere_model():
"""Test making a sphere model"""
info = read_info(fname_raw)
assert_raises(ValueError, make_sphere_model, 'foo', 'auto', info)
assert_raises(ValueError, make_sphere_model, 'auto', 'auto', None)
# here we just make sure it works -- the functionality is actually
# tested more extensively e.g. in the forward and dipole code
make_sphere_model('auto', 'auto', info)
示例14: test_multipolar_bases
def test_multipolar_bases():
"""Test multipolar moment basis calculation using sensor information."""
from scipy.io import loadmat
# Test our basis calculations
info = read_info(raw_fname)
with use_coil_def(elekta_def_fname):
coils = _prep_meg_channels(info, accurate=True, do_es=True)[0]
# Check against a known benchmark
sss_data = loadmat(bases_fname)
exp = dict(int_order=int_order, ext_order=ext_order)
for origin in ((0, 0, 0.04), (0, 0.02, 0.02)):
o_str = ''.join('%d' % (1000 * n) for n in origin)
exp.update(origin=origin)
S_tot = _sss_basis_basic(exp, coils, method='alternative')
# Test our real<->complex conversion functions
S_tot_complex = _bases_real_to_complex(S_tot, int_order, ext_order)
S_tot_round = _bases_complex_to_real(S_tot_complex,
int_order, ext_order)
assert_allclose(S_tot, S_tot_round, atol=1e-7)
S_tot_mat = np.concatenate([sss_data['Sin' + o_str],
sss_data['Sout' + o_str]], axis=1)
S_tot_mat_real = _bases_complex_to_real(S_tot_mat,
int_order, ext_order)
S_tot_mat_round = _bases_real_to_complex(S_tot_mat_real,
int_order, ext_order)
assert_allclose(S_tot_mat, S_tot_mat_round, atol=1e-7)
assert_allclose(S_tot_complex, S_tot_mat, rtol=1e-4, atol=1e-8)
assert_allclose(S_tot, S_tot_mat_real, rtol=1e-4, atol=1e-8)
# Now normalize our columns
S_tot /= np.sqrt(np.sum(S_tot * S_tot, axis=0))[np.newaxis]
S_tot_complex /= np.sqrt(np.sum(
(S_tot_complex * S_tot_complex.conj()).real, axis=0))[np.newaxis]
# Check against a known benchmark
S_tot_mat = np.concatenate([sss_data['SNin' + o_str],
sss_data['SNout' + o_str]], axis=1)
# Check this roundtrip
S_tot_mat_real = _bases_complex_to_real(S_tot_mat,
int_order, ext_order)
S_tot_mat_round = _bases_real_to_complex(S_tot_mat_real,
int_order, ext_order)
assert_allclose(S_tot_mat, S_tot_mat_round, atol=1e-7)
assert_allclose(S_tot_complex, S_tot_mat, rtol=1e-4, atol=1e-8)
# Now test our optimized version
S_tot = _sss_basis_basic(exp, coils)
with use_coil_def(elekta_def_fname):
S_tot_fast = _trans_sss_basis(
exp, all_coils=_prep_mf_coils(info), trans=info['dev_head_t'])
# there are some sign differences for columns (order/degrees)
# in here, likely due to Condon-Shortley. Here we use a
# Magnetometer channel to figure out the flips because the
# gradiometer channels have effectively zero values for first three
# external components (i.e., S_tot[grad_picks, 80:83])
flips = (np.sign(S_tot_fast[2]) != np.sign(S_tot[2]))
flips = 1 - 2 * flips
assert_allclose(S_tot, S_tot_fast * flips, atol=1e-16)
示例15: test_pick_chpi
def test_pick_chpi():
"""Test picking cHPI."""
# Make sure we don't mis-classify cHPI channels
info = read_info(op.join(io_dir, 'tests', 'data', 'test_chpi_raw_sss.fif'))
_assert_channel_types(info)
channel_types = {channel_type(info, idx) for idx in range(info['nchan'])}
assert 'chpi' in channel_types
assert 'seeg' not in channel_types
assert 'ecog' not in channel_types