本文整理汇总了Python中mne.read_trans函数的典型用法代码示例。如果您正苦于以下问题:Python read_trans函数的具体用法?Python read_trans怎么用?Python read_trans使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_trans函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_io_trans
def test_io_trans():
"""Test reading and writing of trans files
"""
tempdir = _TempDir()
os.mkdir(op.join(tempdir, "sample"))
assert_raises(RuntimeError, _find_trans, "sample", subjects_dir=tempdir)
trans0 = read_trans(fname)
fname1 = op.join(tempdir, "sample", "test-trans.fif")
write_trans(fname1, trans0)
assert_true(fname1 == _find_trans("sample", subjects_dir=tempdir))
trans1 = read_trans(fname1)
# check all properties
assert_true(trans0["from"] == trans1["from"])
assert_true(trans0["to"] == trans1["to"])
assert_array_equal(trans0["trans"], trans1["trans"])
# check reading non -trans.fif files
assert_raises(IOError, read_trans, fname_eve)
# check warning on bad filenames
with warnings.catch_warnings(record=True) as w:
fname2 = op.join(tempdir, "trans-test-bad-name.fif")
write_trans(fname2, trans0)
assert_true(len(w) >= 1)
示例2: test_io_trans
def test_io_trans():
"""Test reading and writing of trans files
"""
tempdir = _TempDir()
os.mkdir(op.join(tempdir, 'sample'))
assert_raises(RuntimeError, _find_trans, 'sample', subjects_dir=tempdir)
trans0 = read_trans(fname)
fname1 = op.join(tempdir, 'sample', 'test-trans.fif')
trans0.save(fname1)
assert_true(fname1 == _find_trans('sample', subjects_dir=tempdir))
trans1 = read_trans(fname1)
# check all properties
assert_true(trans0['from'] == trans1['from'])
assert_true(trans0['to'] == trans1['to'])
assert_array_equal(trans0['trans'], trans1['trans'])
# check reading non -trans.fif files
assert_raises(IOError, read_trans, fname_eve)
# check warning on bad filenames
with warnings.catch_warnings(record=True) as w:
fname2 = op.join(tempdir, 'trans-test-bad-name.fif')
write_trans(fname2, trans0)
assert_naming(w, 'test_transforms.py', 1)
示例3: compute_forward_and_inverse_solutions
def compute_forward_and_inverse_solutions(self, orientation = 'fixed'):
"""docstring for compute_forward_solution"""
info = self.grand_average_evoked.info
trans = mne.read_trans(op.join(self.processed_files, '%s-trans.fif' %self.subject))
src = glob.glob(op.join(self.subjects_dir, self.subject, 'bem', '*-ico-4-src.fif'))[0]
bem = glob.glob(op.join(self.subjects_dir, self.subject, 'bem', '*-bem-sol.fif'))[0]
fname = op.join(self.processed_files, '%s_forward.fif' %self.subject)
# check if fwd exists, if not, make it
if not op.exists(fname):
fwd = mne.make_forward_solution(info = info, trans = trans, src = src,
bem = bem, fname = fname, meg = True, eeg = False,
overwrite = True, ignore_ref = True)
self.add_preprocessing_notes("Forward solution generated and saved to %s" %fname)
if orientation == 'fixed':
force_fixed = True
else:
force_fixed = False
fwd = mne.read_forward_solution(fname,force_fixed=force_fixed)
self.forward_solution = fwd
inv = mne.minimum_norm.make_inverse_operator(info, self.forward_solution, self.cov_reg, loose = None, depth = None, fixed = force_fixed)
self.inverse_solution = inv
mne.minimum_norm.write_inverse_operator(op.join(self.processed_files, '%s_inv.fif' %self.subject), self.inverse_solution)
self.add_preprocessing_notes("Inverse solution generated and saved to %s" %op.join(self.processed_files, '%s_inv.fif' %self.subject))
return fwd, inv
示例4: test_plot_dipole_locations
def test_plot_dipole_locations():
"""Test plotting dipole locations."""
dipoles = read_dipole(dip_fname)
trans = read_trans(trans_fname)
dipoles.plot_locations(trans, 'sample', subjects_dir, fig_name='foo')
assert_raises(ValueError, dipoles.plot_locations, trans, 'sample',
subjects_dir, mode='foo')
示例5: test_do_forward_solution
def test_do_forward_solution():
"""Test wrapping forward solution from python
"""
mri = read_trans(fname_mri)
fname_fake = op.join(temp_dir, 'no_have.fif')
# ## Error checks
# bad subject
assert_raises(ValueError, do_forward_solution, 1, fname_raw,
subjects_dir=subjects_dir)
# bad meas
assert_raises(ValueError, do_forward_solution, 'sample', 1,
subjects_dir=subjects_dir)
# meas doesn't exist
assert_raises(IOError, do_forward_solution, 'sample', fname_fake,
subjects_dir=subjects_dir)
# don't specify trans and meas
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
subjects_dir=subjects_dir)
# specify both trans and meas
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
trans='me', mri='you', subjects_dir=subjects_dir)
# specify non-existent trans
assert_raises(IOError, do_forward_solution, 'sample', fname_raw,
trans=fname_fake, subjects_dir=subjects_dir)
# specify non-existent mri
assert_raises(IOError, do_forward_solution, 'sample', fname_raw,
mri=fname_fake, subjects_dir=subjects_dir)
# specify non-string mri
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
mri=1, subjects_dir=subjects_dir)
# specify non-string trans
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
trans=1, subjects_dir=subjects_dir)
# test specifying an actual trans in python space -- this should work but
# the transform I/O reduces our accuracy -- so we'll just hack a test here
# by making it bomb with eeg=False and meg=False
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
mri=mri, eeg=False, meg=False, subjects_dir=subjects_dir)
# mindist as non-integer
assert_raises(TypeError, do_forward_solution, 'sample', fname_raw,
mri=fname_mri, mindist=dict(), subjects_dir=subjects_dir)
# mindist as string but not 'all'
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
mri=fname_mri, eeg=False, mindist='yall',
subjects_dir=subjects_dir)
# src, spacing, and bem as non-str
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
mri=fname_mri, src=1, subjects_dir=subjects_dir)
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
mri=fname_mri, spacing=1, subjects_dir=subjects_dir)
assert_raises(ValueError, do_forward_solution, 'sample', fname_raw,
mri=fname_mri, bem=1, subjects_dir=subjects_dir)
# no overwrite flag
assert_raises(IOError, do_forward_solution, 'sample', fname_raw,
existing_file, mri=fname_mri, subjects_dir=subjects_dir)
# let's catch an MNE error, this time about trans being wrong
assert_raises(CalledProcessError, do_forward_solution, 'sample',
fname_raw, existing_file, trans=fname_mri, overwrite=True,
spacing='oct6', subjects_dir=subjects_dir)
示例6: test_io_trans
def test_io_trans():
"""Test reading and writing of trans files
"""
info0 = read_trans(fname)
fname1 = op.join(tempdir, 'test-trans.fif')
write_trans(fname1, info0)
info1 = read_trans(fname1)
# check all properties
assert_true(info0['from'] == info1['from'])
assert_true(info0['to'] == info1['to'])
assert_array_equal(info0['trans'], info1['trans'])
for d0, d1 in zip(info0['dig'], info1['dig']):
assert_array_equal(d0['r'], d1['r'])
for name in ['kind', 'ident', 'coord_frame']:
assert_true(d0[name] == d1[name])
示例7: plot_coregistration
def plot_coregistration(subject, subjects_dir, hcp_path, recordings_path,
info_from=(('data_type', 'rest'), ('run_index', 0)),
view_init=(('azim', 0), ('elev', 0))):
"""A diagnostic plot to show the HCP coregistration
Parameters
----------
subject : str
The subject
subjects_dir : str
The path corresponding to MNE/freesurfer SUBJECTS_DIR (to be created)
hcp_path : str
The path where the HCP files can be found.
recordings_path : str
The path to converted data (including the head<->device transform).
info_from : tuple of tuples | dict
The reader info concerning the data from which sensor positions
should be read.
Must not be empty room as sensor positions are in head
coordinates for 4D systems, hence not available in that case.
Note that differences between the sensor positions across runs
are smaller than 12 digits, hence negligible.
view_init : tuple of tuples | dict
The initival view, defaults to azimuth and elevation of 0,
a simple lateral view
Returns
-------
fig : matplotlib.figure.Figure
The figure object.
"""
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D # noqa
if isinstance(info_from, tuple):
info_from = dict(info_from)
if isinstance(view_init, tuple):
view_init = dict(view_init)
head_mri_t = read_trans(
op.join(recordings_path, subject,
'{}-head_mri-trans.fif'.format(subject)))
info = read_info(subject=subject, hcp_path=hcp_path, **info_from)
info = pick_info(info, _pick_data_channels(info, with_ref_meg=False))
sens_pnts = np.array([c['loc'][:3] for c in info['chs']])
sens_pnts = apply_trans(head_mri_t, sens_pnts)
sens_pnts *= 1e3 # put in mm scale
pnts, tris = read_surface(
op.join(subjects_dir, subject, 'bem', 'inner_skull.surf'))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(*sens_pnts.T, color='purple', marker='o')
ax.scatter(*pnts.T, color='green', alpha=0.3)
ax.view_init(**view_init)
fig.tight_layout()
return fig
示例8: test_get_trans
def test_get_trans():
"""Test converting '-trans.txt' to '-trans.fif'"""
trans = read_trans(fname)
trans = invert_transform(trans) # starts out as head->MRI, so invert
trans_2 = _get_trans(fname_trans)[0]
assert_equal(trans['from'], trans_2['from'])
assert_equal(trans['to'], trans_2['to'])
assert_allclose(trans['trans'], trans_2['trans'], rtol=1e-5, atol=1e-5)
示例9: test_get_mri_head_t
def test_get_mri_head_t():
"""Test converting '-trans.txt' to '-trans.fif'"""
trans = read_trans(fname)
trans = invert_transform(trans) # starts out as head->MRI, so invert
trans_2 = _get_mri_head_t_from_trans_file(fname_trans)
assert_equal(trans["from"], trans_2["from"])
assert_equal(trans["to"], trans_2["to"])
assert_allclose(trans["trans"], trans_2["trans"], rtol=1e-5, atol=1e-5)
示例10: test_combine
def test_combine():
"""Test combining transforms
"""
trans = read_trans(fname)
inv = invert_transform(trans)
combine_transforms(trans, inv, trans["from"], trans["from"])
assert_raises(RuntimeError, combine_transforms, trans, inv, trans["to"], trans["from"])
assert_raises(RuntimeError, combine_transforms, trans, inv, trans["from"], trans["to"])
assert_raises(RuntimeError, combine_transforms, trans, trans, trans["from"], trans["to"])
示例11: test_eeg_field_interpolation
def test_eeg_field_interpolation():
"""Test interpolation of EEG field onto head
"""
trans = read_trans(trans_fname)
info = read_info(evoked_fname)
surf = get_head_surface('sample', subjects_dir=subjects_dir)
# we must have trans if surface is in MRI coords
assert_raises(ValueError, make_surface_mapping, info, surf, 'eeg')
data = make_surface_mapping(info, surf, 'eeg', trans, mode='accurate')
assert_array_equal(data.shape, (2562, 60)) # maps data onto surf
示例12: test_combine
def test_combine():
"""Test combining transforms."""
trans = read_trans(fname)
inv = invert_transform(trans)
combine_transforms(trans, inv, trans['from'], trans['from'])
pytest.raises(RuntimeError, combine_transforms, trans, inv,
trans['to'], trans['from'])
pytest.raises(RuntimeError, combine_transforms, trans, inv,
trans['from'], trans['to'])
pytest.raises(RuntimeError, combine_transforms, trans, trans,
trans['from'], trans['to'])
示例13: test_io_trans
def test_io_trans():
"""Test reading and writing of trans files."""
tempdir = _TempDir()
os.mkdir(op.join(tempdir, 'sample'))
pytest.raises(RuntimeError, _find_trans, 'sample', subjects_dir=tempdir)
trans0 = read_trans(fname)
fname1 = op.join(tempdir, 'sample', 'test-trans.fif')
trans0.save(fname1)
assert fname1 == _find_trans('sample', subjects_dir=tempdir)
trans1 = read_trans(fname1)
# check all properties
assert trans0 == trans1
# check reading non -trans.fif files
pytest.raises(IOError, read_trans, fname_eve)
# check warning on bad filenames
fname2 = op.join(tempdir, 'trans-test-bad-name.fif')
with pytest.warns(RuntimeWarning, match='-trans.fif'):
write_trans(fname2, trans0)
示例14: test_io_trans
def test_io_trans():
"""Test reading and writing of trans files
"""
trans0 = read_trans(fname)
fname1 = op.join(tempdir, 'test-trans.fif')
write_trans(fname1, trans0)
trans1 = read_trans(fname1)
# check all properties
assert_true(trans0['from'] == trans1['from'])
assert_true(trans0['to'] == trans1['to'])
assert_array_equal(trans0['trans'], trans1['trans'])
# check reading non -trans.fif files
assert_raises(IOError, read_trans, fname_eve)
# check warning on bad filenames
with warnings.catch_warnings(record=True) as w:
fname2 = op.join(tempdir, 'trans-test-bad-name.fif')
write_trans(fname2, trans0)
assert_true(len(w) >= 1)
示例15: _get_data
def _get_data():
"""Helper to get some starting data"""
# raw with ECG channel
raw = Raw(raw_fname).crop(0.0, 5.0).load_data()
data_picks = pick_types(raw.info, meg=True, eeg=True)
other_picks = pick_types(raw.info, meg=False, stim=True, eog=True)
picks = np.sort(np.concatenate((data_picks[::16], other_picks)))
raw = raw.pick_channels([raw.ch_names[p] for p in picks])
ecg = RawArray(np.zeros((1, len(raw.times))), create_info(["ECG 063"], raw.info["sfreq"], "ecg"))
for key in ("dev_head_t", "buffer_size_sec", "highpass", "lowpass", "filename", "dig"):
ecg.info[key] = raw.info[key]
raw.add_channels([ecg])
src = read_source_spaces(src_fname)
trans = read_trans(trans_fname)
sphere = make_sphere_model("auto", "auto", raw.info)
stc = _make_stc(raw, src)
return raw, src, stc, trans, sphere