本文整理汇总了Python中mne.io.read_raw_bti函数的典型用法代码示例。如果您正苦于以下问题:Python read_raw_bti函数的具体用法?Python read_raw_bti怎么用?Python read_raw_bti使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_raw_bti函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_no_conversion
def test_no_conversion():
""" Test bti no-conversion option """
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
raw = read_raw_bti(pdf, config, hs, convert=False)
raw_con = read_raw_bti(pdf, config, hs, convert=True)
bti_info = _read_bti_header(pdf, config)
dev_ctf_t = _correct_trans(bti_info["bti_transform"][0])
assert_array_equal(dev_ctf_t, raw.info["dev_ctf_t"]["trans"])
assert_array_equal(raw.info["dev_head_t"]["trans"], np.eye(4))
assert_array_equal(raw.info["ctf_head_t"]["trans"], np.eye(4))
dig, t = _process_bti_headshape(hs, convert=False, use_hpi=False)
assert_array_equal(t["trans"], np.eye(4))
for ii, (old, new, con) in enumerate(zip(dig, raw.info["dig"], raw_con.info["dig"])):
assert_equal(old["ident"], new["ident"])
assert_array_equal(old["r"], new["r"])
assert_true(not np.allclose(old["r"], con["r"]))
if ii > 10:
break
ch_map = dict((ch["chan_label"], ch["coil_trans"]) for ch in bti_info["chs"])
for ii, ch_label in enumerate(raw.bti_ch_labels):
if not ch_label.startswith("A"):
continue
t1 = _correct_trans(ch_map[ch_label])
t2 = raw.info["chs"][ii]["coil_trans"]
t3 = raw_con.info["chs"][ii]["coil_trans"]
assert_array_equal(t1, t2)
assert_true(not np.allclose(t1, t3))
开发者ID:teonbrooks,项目名称:mne-python,代码行数:32,代码来源:test_bti.py
示例2: test_info_no_rename_no_reorder_no_pdf
def test_info_no_rename_no_reorder_no_pdf():
"""Test private renaming, reordering and partial construction option."""
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
info, bti_info = _get_bti_info(
pdf_fname=pdf, config_fname=config, head_shape_fname=hs,
rotation_x=0.0, translation=(0.0, 0.02, 0.11), convert=False,
ecg_ch='E31', eog_ch=('E63', 'E64'),
rename_channels=False, sort_by_ch_name=False)
info2, bti_info = _get_bti_info(
pdf_fname=None, config_fname=config, head_shape_fname=hs,
rotation_x=0.0, translation=(0.0, 0.02, 0.11), convert=False,
ecg_ch='E31', eog_ch=('E63', 'E64'),
rename_channels=False, sort_by_ch_name=False)
assert_equal(info['ch_names'],
[ch['ch_name'] for ch in info['chs']])
assert_equal([n for n in info['ch_names'] if n.startswith('A')][:5],
['A22', 'A2', 'A104', 'A241', 'A138'])
assert_equal([n for n in info['ch_names'] if n.startswith('A')][-5:],
['A133', 'A158', 'A44', 'A134', 'A216'])
info = pick_info(info, pick_types(info, meg=True, stim=True,
resp=True))
info2 = pick_info(info2, pick_types(info2, meg=True, stim=True,
resp=True))
assert_true(info['sfreq'] is not None)
assert_true(info['lowpass'] is not None)
assert_true(info['highpass'] is not None)
assert_true(info['meas_date'] is not None)
assert_equal(info2['sfreq'], None)
assert_equal(info2['lowpass'], None)
assert_equal(info2['highpass'], None)
assert_equal(info2['meas_date'], None)
assert_equal(info['ch_names'], info2['ch_names'])
assert_equal(info['ch_names'], info2['ch_names'])
for key in ['dev_ctf_t', 'dev_head_t', 'ctf_head_t']:
assert_array_equal(info[key]['trans'], info2[key]['trans'])
assert_array_equal(
np.array([ch['loc'] for ch in info['chs']]),
np.array([ch['loc'] for ch in info2['chs']]))
# just check reading data | corner case
raw1 = read_raw_bti(
pdf_fname=pdf, config_fname=config, head_shape_fname=None,
sort_by_ch_name=False, preload=True)
# just check reading data | corner case
raw2 = read_raw_bti(
pdf_fname=pdf, config_fname=config, head_shape_fname=None,
rename_channels=False,
sort_by_ch_name=True, preload=True)
sort_idx = [raw1.bti_ch_labels.index(ch) for ch in raw2.bti_ch_labels]
raw1._data = raw1._data[sort_idx]
assert_array_equal(raw1._data, raw2._data)
assert_array_equal(raw2.bti_ch_labels, raw2.ch_names)
开发者ID:olafhauk,项目名称:mne-python,代码行数:59,代码来源:test_bti.py
示例3: test_bytes_io
def test_bytes_io():
""" Test bti bytes-io API """
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
raw = read_raw_bti(pdf, config, hs, convert=True, preload=False)
with open(pdf, 'rb') as fid:
pdf = six.BytesIO(fid.read())
with open(config, 'rb') as fid:
config = six.BytesIO(fid.read())
with open(hs, 'rb') as fid:
hs = six.BytesIO(fid.read())
raw2 = read_raw_bti(pdf, config, hs, convert=True, preload=False)
repr(raw2)
assert_array_equal(raw[:][0], raw2[:][0])
开发者ID:Famguy,项目名称:mne-python,代码行数:14,代码来源:test_bti.py
示例4: test_bytes_io
def test_bytes_io():
""" Test bti bytes-io API """
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
raw = read_raw_bti(pdf, config, hs, convert=True)
with open(pdf, "rb") as fid:
pdf = six.BytesIO(fid.read())
with open(config, "rb") as fid:
config = six.BytesIO(fid.read())
with open(hs, "rb") as fid:
hs = six.BytesIO(fid.read())
raw2 = read_raw_bti(pdf, config, hs, convert=True)
repr(raw2)
assert_array_equal(raw._data, raw2._data)
开发者ID:teonbrooks,项目名称:mne-python,代码行数:14,代码来源:test_bti.py
示例5: test_plot_trans
def test_plot_trans():
"""Test plotting of -trans.fif files and MEG sensor layouts
"""
evoked = read_evokeds(evoked_fname)[0]
with warnings.catch_warnings(record=True): # 4D weight tables
bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True,
preload=False).info
infos = dict(
Neuromag=evoked.info,
CTF=read_raw_ctf(ctf_fname).info,
BTi=bti,
KIT=read_raw_kit(sqd_fname).info,
)
for system, info in infos.items():
ref_meg = False if system == 'KIT' else True
plot_trans(info, trans_fname, subject='sample', meg_sensors=True,
subjects_dir=subjects_dir, ref_meg=ref_meg)
# KIT ref sensor coil def not defined
assert_raises(RuntimeError, plot_trans, infos['KIT'], None,
meg_sensors=True, ref_meg=True)
info = infos['Neuromag']
assert_raises(ValueError, plot_trans, info, trans_fname,
subject='sample', subjects_dir=subjects_dir,
ch_type='bad-chtype')
assert_raises(TypeError, plot_trans, 'foo', trans_fname,
subject='sample', subjects_dir=subjects_dir)
# no-head version
plot_trans(info, None, meg_sensors=True, dig=True, coord_frame='head')
# EEG only with strange options
with warnings.catch_warnings(record=True) as w:
plot_trans(evoked.copy().pick_types(meg=False, eeg=True).info,
trans=trans_fname, meg_sensors=True)
assert_true(['Cannot plot MEG' in str(ww.message) for ww in w])
开发者ID:MartinBaBer,项目名称:mne-python,代码行数:33,代码来源:test_3d.py
示例6: test_bytes_io
def test_bytes_io():
""" Test bti bytes-io API """
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
with warnings.catch_warnings(record=True): # weight tables
raw = read_raw_bti(pdf, config, hs, convert=True, preload=False)
with open(pdf, "rb") as fid:
pdf = six.BytesIO(fid.read())
with open(config, "rb") as fid:
config = six.BytesIO(fid.read())
with open(hs, "rb") as fid:
hs = six.BytesIO(fid.read())
with warnings.catch_warnings(record=True): # weight tables
raw2 = read_raw_bti(pdf, config, hs, convert=True, preload=False)
repr(raw2)
assert_array_equal(raw[:][0], raw2[:][0])
开发者ID:mmagnuski,项目名称:mne-python,代码行数:16,代码来源:test_bti.py
示例7: 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')
开发者ID:Eric89GXL,项目名称:mne-python,代码行数:34,代码来源:test_channels.py
示例8: test_raw
def test_raw():
""" Test bti conversion to Raw object """
for pdf, config, hs, exported in zip(pdf_fnames, config_fnames, hs_fnames,
exported_fnames):
# rx = 2 if 'linux' in pdf else 0
assert_raises(ValueError, read_raw_bti, pdf, 'eggs')
assert_raises(ValueError, read_raw_bti, pdf, config, 'spam')
if op.exists(tmp_raw_fname):
os.remove(tmp_raw_fname)
with Raw(exported, preload=True) as ex:
with read_raw_bti(pdf, config, hs) as ra:
assert_equal(ex.ch_names[:NCH], ra.ch_names[:NCH])
assert_array_almost_equal(ex.info['dev_head_t']['trans'],
ra.info['dev_head_t']['trans'], 7)
dig1, dig2 = [np.array([d['r'] for d in r_.info['dig']])
for r_ in (ra, ex)]
assert_array_equal(dig1, dig2)
coil1, coil2 = [np.concatenate([d['coil_trans'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
assert_array_almost_equal(coil1, coil2, 7)
loc1, loc2 = [np.concatenate([d['loc'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
assert_array_equal(loc1, loc2)
assert_array_equal(ra._data[:NCH], ex._data[:NCH])
assert_array_equal(ra.cals[:NCH], ex.cals[:NCH])
ra.save(tmp_raw_fname)
with Raw(tmp_raw_fname) as r:
print(r)
os.remove(tmp_raw_fname)
开发者ID:eh123,项目名称:mne-python,代码行数:35,代码来源:test_bti.py
示例9: test_no_conversion
def test_no_conversion():
""" Test bti no-conversion option """
get_info = partial(
_get_bti_info,
rotation_x=0.0, translation=(0.0, 0.02, 0.11), convert=False,
ecg_ch='E31', eog_ch=('E63', 'E64'),
rename_channels=False, sort_by_ch_name=False)
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
with warnings.catch_warnings(record=True): # weight tables
raw_info, _ = get_info(pdf, config, hs, convert=False)
with warnings.catch_warnings(record=True): # weight tables
raw_info_con = read_raw_bti(
pdf_fname=pdf, config_fname=config, head_shape_fname=hs,
convert=True, preload=False).info
pick_info(raw_info_con,
pick_types(raw_info_con, meg=True, ref_meg=True),
copy=False)
pick_info(raw_info,
pick_types(raw_info, meg=True, ref_meg=True), copy=False)
bti_info = _read_bti_header(pdf, config)
dev_ctf_t = _correct_trans(bti_info['bti_transform'][0])
assert_array_equal(dev_ctf_t, raw_info['dev_ctf_t']['trans'])
assert_array_equal(raw_info['dev_head_t']['trans'], np.eye(4))
assert_array_equal(raw_info['ctf_head_t']['trans'], np.eye(4))
dig, t = _process_bti_headshape(hs, convert=False, use_hpi=False)
assert_array_equal(t['trans'], np.eye(4))
for ii, (old, new, con) in enumerate(zip(
dig, raw_info['dig'], raw_info_con['dig'])):
assert_equal(old['ident'], new['ident'])
assert_array_equal(old['r'], new['r'])
assert_true(not np.allclose(old['r'], con['r']))
if ii > 10:
break
ch_map = dict((ch['chan_label'],
ch['loc']) for ch in bti_info['chs'])
for ii, ch_label in enumerate(raw_info['ch_names']):
if not ch_label.startswith('A'):
continue
t1 = ch_map[ch_label] # correction already performed in bti_info
t2 = raw_info['chs'][ii]['loc']
t3 = raw_info_con['chs'][ii]['loc']
assert_allclose(t1, t2, atol=1e-15)
assert_true(not np.allclose(t1, t3))
idx_a = raw_info_con['ch_names'].index('MEG 001')
idx_b = raw_info['ch_names'].index('A22')
assert_equal(
raw_info_con['chs'][idx_a]['coord_frame'],
FIFF.FIFFV_COORD_DEVICE)
assert_equal(
raw_info['chs'][idx_b]['coord_frame'],
FIFF.FIFFV_MNE_COORD_4D_HEAD)
开发者ID:demianw,项目名称:mne-python,代码行数:58,代码来源:test_bti.py
示例10: test_pick_refs
def test_pick_refs():
"""Test picking of reference sensors
"""
infos = list()
# KIT
kit_dir = op.join(io_dir, 'kit', 'tests', 'data')
sqd_path = op.join(kit_dir, 'test.sqd')
mrk_path = op.join(kit_dir, 'test_mrk.sqd')
elp_path = op.join(kit_dir, 'test_elp.txt')
hsp_path = op.join(kit_dir, 'test_hsp.txt')
raw_kit = read_raw_kit(sqd_path, mrk_path, elp_path, hsp_path)
infos.append(raw_kit.info)
# BTi
bti_dir = op.join(io_dir, 'bti', 'tests', 'data')
bti_pdf = op.join(bti_dir, 'test_pdf_linux')
bti_config = op.join(bti_dir, 'test_config_linux')
bti_hs = op.join(bti_dir, 'test_hs_linux')
with warnings.catch_warnings(record=True): # weight tables
raw_bti = read_raw_bti(bti_pdf, bti_config, bti_hs, preload=False)
infos.append(raw_bti.info)
# CTF
fname_ctf_raw = op.join(io_dir, 'tests', 'data', 'test_ctf_comp_raw.fif')
raw_ctf = read_raw_fif(fname_ctf_raw, add_eeg_ref=False)
raw_ctf.apply_gradient_compensation(2)
infos.append(raw_ctf.info)
for info in infos:
info['bads'] = []
assert_raises(ValueError, pick_types, info, meg='foo')
assert_raises(ValueError, pick_types, info, ref_meg='foo')
picks_meg_ref = pick_types(info, meg=True, ref_meg=True)
picks_meg = pick_types(info, meg=True, ref_meg=False)
picks_ref = pick_types(info, meg=False, ref_meg=True)
assert_array_equal(picks_meg_ref,
np.sort(np.concatenate([picks_meg, picks_ref])))
picks_grad = pick_types(info, meg='grad', ref_meg=False)
picks_ref_grad = pick_types(info, meg=False, ref_meg='grad')
picks_meg_ref_grad = pick_types(info, meg='grad', ref_meg='grad')
assert_array_equal(picks_meg_ref_grad,
np.sort(np.concatenate([picks_grad,
picks_ref_grad])))
picks_mag = pick_types(info, meg='mag', ref_meg=False)
picks_ref_mag = pick_types(info, meg=False, ref_meg='mag')
picks_meg_ref_mag = pick_types(info, meg='mag', ref_meg='mag')
assert_array_equal(picks_meg_ref_mag,
np.sort(np.concatenate([picks_mag,
picks_ref_mag])))
assert_array_equal(picks_meg,
np.sort(np.concatenate([picks_mag, picks_grad])))
assert_array_equal(picks_ref,
np.sort(np.concatenate([picks_ref_mag,
picks_ref_grad])))
assert_array_equal(picks_meg_ref, np.sort(np.concatenate(
[picks_grad, picks_mag, picks_ref_grad, picks_ref_mag])))
for pick in (picks_meg_ref, picks_meg, picks_ref,
picks_grad, picks_ref_grad, picks_meg_ref_grad,
picks_mag, picks_ref_mag, picks_meg_ref_mag):
if len(pick) > 0:
pick_info(info, pick)
开发者ID:jmontoyam,项目名称:mne-python,代码行数:58,代码来源:test_pick.py
示例11: run
def run():
"""Run command."""
from mne.commands.utils import get_optparser
parser = get_optparser(__file__)
parser.add_option('-p', '--pdf', dest='pdf_fname',
help='Input data file name', metavar='FILE')
parser.add_option('-c', '--config', dest='config_fname',
help='Input config file name', metavar='FILE',
default='config')
parser.add_option('--head_shape', dest='head_shape_fname',
help='Headshape file name', metavar='FILE',
default='hs_file')
parser.add_option('-o', '--out_fname', dest='out_fname',
help='Name of the resulting fiff file',
default='as_data_fname')
parser.add_option('-r', '--rotation_x', dest='rotation_x', type='float',
help='Compensatory rotation about Neuromag x axis, deg',
default=2.0)
parser.add_option('-T', '--translation', dest='translation', type='str',
help='Default translation, meter',
default=(0.00, 0.02, 0.11))
parser.add_option('--ecg_ch', dest='ecg_ch', type='str',
help='4D ECG channel name',
default='E31')
parser.add_option('--eog_ch', dest='eog_ch', type='str',
help='4D EOG channel names',
default='E63,E64')
options, args = parser.parse_args()
pdf_fname = options.pdf_fname
if pdf_fname is None:
parser.print_help()
sys.exit(1)
config_fname = options.config_fname
head_shape_fname = options.head_shape_fname
out_fname = options.out_fname
rotation_x = options.rotation_x
translation = options.translation
ecg_ch = options.ecg_ch
eog_ch = options.ecg_ch.split(',')
if out_fname == 'as_data_fname':
out_fname = pdf_fname + '_raw.fif'
raw = read_raw_bti(pdf_fname=pdf_fname, config_fname=config_fname,
head_shape_fname=head_shape_fname,
rotation_x=rotation_x, translation=translation,
ecg_ch=ecg_ch, eog_ch=eog_ch)
raw.save(out_fname)
raw.close()
if is_main:
sys.exit(0)
开发者ID:HSMin,项目名称:mne-python,代码行数:57,代码来源:mne_bti2fiff.py
示例12: test_raw
def test_raw():
""" Test bti conversion to Raw object """
for pdf, config, hs, exported in zip(pdf_fnames, config_fnames, hs_fnames,
exported_fnames):
# rx = 2 if 'linux' in pdf else 0
assert_raises(ValueError, read_raw_bti, pdf, 'eggs', preload=False)
assert_raises(ValueError, read_raw_bti, pdf, config, 'spam',
preload=False)
if op.exists(tmp_raw_fname):
os.remove(tmp_raw_fname)
ex = Raw(exported, preload=True)
with warnings.catch_warnings(record=True): # weight tables
ra = read_raw_bti(pdf, config, hs, preload=False)
assert_true('RawBTi' in repr(ra))
assert_equal(ex.ch_names[:NCH], ra.ch_names[:NCH])
assert_array_almost_equal(ex.info['dev_head_t']['trans'],
ra.info['dev_head_t']['trans'], 7)
with warnings.catch_warnings(record=True): # headshape
assert_dig_allclose(ex.info, ra.info)
coil1, coil2 = [np.concatenate([d['loc'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
assert_array_almost_equal(coil1, coil2, 7)
loc1, loc2 = [np.concatenate([d['loc'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
assert_allclose(loc1, loc2)
assert_allclose(ra[:NCH][0], ex[:NCH][0])
assert_array_equal([c['range'] for c in ra.info['chs'][:NCH]],
[c['range'] for c in ex.info['chs'][:NCH]])
assert_array_equal([c['cal'] for c in ra.info['chs'][:NCH]],
[c['cal'] for c in ex.info['chs'][:NCH]])
assert_array_equal(ra._cals[:NCH], ex._cals[:NCH])
# check our transforms
for key in ('dev_head_t', 'dev_ctf_t', 'ctf_head_t'):
if ex.info[key] is None:
pass
else:
assert_true(ra.info[key] is not None)
for ent in ('to', 'from', 'trans'):
assert_allclose(ex.info[key][ent],
ra.info[key][ent])
ra.save(tmp_raw_fname)
re = Raw(tmp_raw_fname)
print(re)
for key in ('dev_head_t', 'dev_ctf_t', 'ctf_head_t'):
assert_true(isinstance(re.info[key], dict))
this_t = re.info[key]['trans']
assert_equal(this_t.shape, (4, 4))
# cehck that matrix by is not identity
assert_true(not np.allclose(this_t, np.eye(4)))
os.remove(tmp_raw_fname)
开发者ID:demianw,项目名称:mne-python,代码行数:56,代码来源:test_bti.py
示例13: test_crop
def test_crop():
""" Test crop raw """
raw = read_raw_bti(pdf_fnames[0], config_fnames[0], hs_fnames[0])
y, t = raw[:]
t0, t1 = 0.25 * t[-1], 0.75 * t[-1]
mask = (t0 <= t) * (t <= t1)
raw_ = raw.crop(t0, t1)
y_, _ = raw_[:]
assert_true(y_.shape[1] == mask.sum())
assert_true(y_.shape[0] == y.shape[0])
开发者ID:ImmanuelSamuel,项目名称:mne-python,代码行数:10,代码来源:test_bti.py
示例14: test_raw
def test_raw():
""" Test bti conversion to Raw object """
for pdf, config, hs, exported in zip(pdf_fnames, config_fnames, hs_fnames,
exported_fnames):
# rx = 2 if 'linux' in pdf else 0
assert_raises(ValueError, read_raw_bti, pdf, 'eggs')
assert_raises(ValueError, read_raw_bti, pdf, config, 'spam')
if op.exists(tmp_raw_fname):
os.remove(tmp_raw_fname)
ex = Raw(exported, preload=True)
ra = read_raw_bti(pdf, config, hs)
assert_true('RawBTi' in repr(ra))
assert_equal(ex.ch_names[:NCH], ra.ch_names[:NCH])
assert_array_almost_equal(ex.info['dev_head_t']['trans'],
ra.info['dev_head_t']['trans'], 7)
dig1, dig2 = [np.array([d['r'] for d in r_.info['dig']])
for r_ in (ra, ex)]
assert_array_almost_equal(dig1, dig2, 18)
coil1, coil2 = [np.concatenate([d['loc'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
assert_array_almost_equal(coil1, coil2, 7)
loc1, loc2 = [np.concatenate([d['loc'].flatten()
for d in r_.info['chs'][:NCH]])
for r_ in (ra, ex)]
assert_allclose(loc1, loc2)
assert_array_equal(ra._data[:NCH], ex._data[:NCH])
assert_array_equal(ra._cals[:NCH], ex._cals[:NCH])
# check our transforms
for key in ('dev_head_t', 'dev_ctf_t', 'ctf_head_t'):
if ex.info[key] is None:
pass
else:
assert_true(ra.info[key] is not None)
for ent in ('to', 'from', 'trans'):
assert_allclose(ex.info[key][ent],
ra.info[key][ent])
# Make sure concatenation works
raw_concat = concatenate_raws([ra.copy(), ra])
assert_equal(raw_concat.n_times, 2 * ra.n_times)
ra.save(tmp_raw_fname)
re = Raw(tmp_raw_fname)
print(re)
for key in ('dev_head_t', 'dev_ctf_t', 'ctf_head_t'):
assert_true(isinstance(re.info[key], dict))
this_t = re.info[key]['trans']
assert_equal(this_t.shape, (4, 4))
# cehck that matrix by is not identity
assert_true(not np.allclose(this_t, np.eye(4)))
os.remove(tmp_raw_fname)
开发者ID:jasmainak,项目名称:mne-python,代码行数:55,代码来源:test_bti.py
示例15: test_crop_append
def test_crop_append():
""" Test crop and append raw """
raw = read_raw_bti(pdf_fnames[0], config_fnames[0], hs_fnames[0])
raw.preload_data() # currently does nothing
y, t = raw[:]
t0, t1 = 0.25 * t[-1], 0.75 * t[-1]
mask = (t0 <= t) * (t <= t1)
raw_ = raw.crop(t0, t1)
y_, _ = raw_[:]
assert_true(y_.shape[1] == mask.sum())
assert_true(y_.shape[0] == y.shape[0])
raw2 = raw.copy()
assert_raises(RuntimeError, raw.append, raw2, preload=False)
raw.append(raw2)
assert_allclose(np.tile(raw2[:, :][0], (1, 2)), raw[:, :][0])
开发者ID:rajul,项目名称:mne-python,代码行数:16,代码来源:test_bti.py
示例16: test_plot_trans
def test_plot_trans():
"""Test plotting of -trans.fif files and MEG sensor layouts."""
from mayavi import mlab
evoked = read_evokeds(evoked_fname)[0]
with warnings.catch_warnings(record=True): # 4D weight tables
bti = read_raw_bti(pdf_fname, config_fname, hs_fname, convert=True,
preload=False).info
infos = dict(
Neuromag=evoked.info,
CTF=read_raw_ctf(ctf_fname).info,
BTi=bti,
KIT=read_raw_kit(sqd_fname).info,
)
for system, info in infos.items():
ref_meg = False if system == 'KIT' else True
plot_trans(info, trans_fname, subject='sample', meg_sensors=True,
subjects_dir=subjects_dir, ref_meg=ref_meg)
mlab.close(all=True)
# KIT ref sensor coil def is defined
plot_trans(infos['KIT'], None, meg_sensors=True, ref_meg=True)
mlab.close(all=True)
info = infos['Neuromag']
assert_raises(ValueError, plot_trans, info, trans_fname,
subject='sample', subjects_dir=subjects_dir,
ch_type='bad-chtype')
assert_raises(TypeError, plot_trans, 'foo', trans_fname,
subject='sample', subjects_dir=subjects_dir)
# no-head version
plot_trans(info, None, meg_sensors=True, dig=True, coord_frame='head')
mlab.close(all=True)
# all coord frames
for coord_frame in ('meg', 'head', 'mri'):
plot_trans(info, meg_sensors=True, dig=True, coord_frame=coord_frame,
trans=trans_fname, subject='sample',
subjects_dir=subjects_dir)
mlab.close(all=True)
# EEG only with strange options
evoked_eeg_ecog = evoked.copy().pick_types(meg=False, eeg=True)
evoked_eeg_ecog.info['projs'] = [] # "remove" avg proj
evoked_eeg_ecog.set_channel_types({'EEG 001': 'ecog'})
with warnings.catch_warnings(record=True) as w:
plot_trans(evoked_eeg_ecog.info, subject='sample', trans=trans_fname,
source='outer_skin', meg_sensors=True, skull=True,
eeg_sensors=['original', 'projected'], ecog_sensors=True,
brain='white', head=True, subjects_dir=subjects_dir)
mlab.close(all=True)
assert_true(['Cannot plot MEG' in str(ww.message) for ww in w])
开发者ID:hoechenberger,项目名称:mne-python,代码行数:47,代码来源:test_3d.py
示例17: test_transforms
def test_transforms():
""" Test transformations """
bti_trans = (0.0, 0.02, 0.11)
bti_dev_t = Transform("ctf_meg", "meg", _get_bti_dev_t(0.0, bti_trans))
for pdf, config, hs in zip(pdf_fnames, config_fnames, hs_fnames):
raw = read_raw_bti(pdf, config, hs)
dev_ctf_t = raw.info["dev_ctf_t"]
dev_head_t_old = raw.info["dev_head_t"]
ctf_head_t = raw.info["ctf_head_t"]
# 1) get BTI->Neuromag
bti_dev_t = Transform("ctf_meg", "meg", _get_bti_dev_t(0.0, bti_trans))
# 2) get Neuromag->BTI head
t = combine_transforms(invert_transform(bti_dev_t), dev_ctf_t, "meg", "ctf_head")
# 3) get Neuromag->head
dev_head_t_new = combine_transforms(t, ctf_head_t, "meg", "head")
assert_array_equal(dev_head_t_new["trans"], dev_head_t_old["trans"])
开发者ID:teonbrooks,项目名称:mne-python,代码行数:19,代码来源:test_bti.py
示例18: test_transforms
def test_transforms():
"""Test transformations."""
bti_trans = (0.0, 0.02, 0.11)
bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t(0.0, bti_trans))
for pdf, config, hs, in zip(pdf_fnames, config_fnames, hs_fnames):
raw = read_raw_bti(pdf, config, hs, preload=False)
dev_ctf_t = raw.info['dev_ctf_t']
dev_head_t_old = raw.info['dev_head_t']
ctf_head_t = raw.info['ctf_head_t']
# 1) get BTI->Neuromag
bti_dev_t = Transform('ctf_meg', 'meg', _get_bti_dev_t(0.0, bti_trans))
# 2) get Neuromag->BTI head
t = combine_transforms(invert_transform(bti_dev_t), dev_ctf_t,
'meg', 'ctf_head')
# 3) get Neuromag->head
dev_head_t_new = combine_transforms(t, ctf_head_t, 'meg', 'head')
assert_array_equal(dev_head_t_new['trans'], dev_head_t_old['trans'])
开发者ID:olafhauk,项目名称:mne-python,代码行数:20,代码来源:test_bti.py
示例19: test_pick_refs
def test_pick_refs():
"""Test picking of reference sensors."""
infos = list()
# KIT
kit_dir = op.join(io_dir, 'kit', 'tests', 'data')
sqd_path = op.join(kit_dir, 'test.sqd')
mrk_path = op.join(kit_dir, 'test_mrk.sqd')
elp_path = op.join(kit_dir, 'test_elp.txt')
hsp_path = op.join(kit_dir, 'test_hsp.txt')
raw_kit = read_raw_kit(sqd_path, mrk_path, elp_path, hsp_path)
infos.append(raw_kit.info)
# BTi
bti_dir = op.join(io_dir, 'bti', 'tests', 'data')
bti_pdf = op.join(bti_dir, 'test_pdf_linux')
bti_config = op.join(bti_dir, 'test_config_linux')
bti_hs = op.join(bti_dir, 'test_hs_linux')
raw_bti = read_raw_bti(bti_pdf, bti_config, bti_hs, preload=False)
infos.append(raw_bti.info)
# CTF
fname_ctf_raw = op.join(io_dir, 'tests', 'data', 'test_ctf_comp_raw.fif')
raw_ctf = read_raw_fif(fname_ctf_raw)
raw_ctf.apply_gradient_compensation(2)
for info in infos:
info['bads'] = []
pytest.raises(ValueError, pick_types, info, meg='foo')
pytest.raises(ValueError, pick_types, info, ref_meg='foo')
picks_meg_ref = pick_types(info, meg=True, ref_meg=True)
picks_meg = pick_types(info, meg=True, ref_meg=False)
picks_ref = pick_types(info, meg=False, ref_meg=True)
assert_array_equal(picks_meg_ref,
np.sort(np.concatenate([picks_meg, picks_ref])))
picks_grad = pick_types(info, meg='grad', ref_meg=False)
picks_ref_grad = pick_types(info, meg=False, ref_meg='grad')
picks_meg_ref_grad = pick_types(info, meg='grad', ref_meg='grad')
assert_array_equal(picks_meg_ref_grad,
np.sort(np.concatenate([picks_grad,
picks_ref_grad])))
picks_mag = pick_types(info, meg='mag', ref_meg=False)
picks_ref_mag = pick_types(info, meg=False, ref_meg='mag')
picks_meg_ref_mag = pick_types(info, meg='mag', ref_meg='mag')
assert_array_equal(picks_meg_ref_mag,
np.sort(np.concatenate([picks_mag,
picks_ref_mag])))
assert_array_equal(picks_meg,
np.sort(np.concatenate([picks_mag, picks_grad])))
assert_array_equal(picks_ref,
np.sort(np.concatenate([picks_ref_mag,
picks_ref_grad])))
assert_array_equal(picks_meg_ref, np.sort(np.concatenate(
[picks_grad, picks_mag, picks_ref_grad, picks_ref_mag])))
for pick in (picks_meg_ref, picks_meg, picks_ref,
picks_grad, picks_ref_grad, picks_meg_ref_grad,
picks_mag, picks_ref_mag, picks_meg_ref_mag):
if len(pick) > 0:
pick_info(info, pick)
# test CTF expected failures directly
info = raw_ctf.info
info['bads'] = []
picks_meg_ref = pick_types(info, meg=True, ref_meg=True)
picks_meg = pick_types(info, meg=True, ref_meg=False)
picks_ref = pick_types(info, meg=False, ref_meg=True)
picks_mag = pick_types(info, meg='mag', ref_meg=False)
picks_ref_mag = pick_types(info, meg=False, ref_meg='mag')
picks_meg_ref_mag = pick_types(info, meg='mag', ref_meg='mag')
for pick in (picks_meg_ref, picks_ref, picks_ref_mag, picks_meg_ref_mag):
if len(pick) > 0:
pick_info(info, pick)
for pick in (picks_meg, picks_mag):
if len(pick) > 0:
with catch_logging() as log:
pick_info(info, pick, verbose=True)
assert ('Removing {} compensators'.format(len(info['comps']))
in log.getvalue())
开发者ID:jhouck,项目名称:mne-python,代码行数:76,代码来源:test_pick.py
示例20: test_make_forward_solution_kit
def test_make_forward_solution_kit():
"""Test making fwd using KIT, BTI, and CTF (compensated) files
"""
fname_bem = op.join(subjects_dir, 'sample', 'bem',
'sample-5120-bem-sol.fif')
kit_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'kit',
'tests', 'data')
sqd_path = op.join(kit_dir, 'test.sqd')
mrk_path = op.join(kit_dir, 'test_mrk.sqd')
elp_path = op.join(kit_dir, 'test_elp.txt')
hsp_path = op.join(kit_dir, 'test_hsp.txt')
mri_path = op.join(kit_dir, 'trans-sample.fif')
fname_kit_raw = op.join(kit_dir, 'test_bin_raw.fif')
bti_dir = op.join(op.dirname(__file__), '..', '..', 'io', 'bti',
'tests', 'data')
bti_pdf = op.join(bti_dir, 'test_pdf_linux')
bti_config = op.join(bti_dir, 'test_config_linux')
bti_hs = op.join(bti_dir, 'test_hs_linux')
fname_bti_raw = op.join(bti_dir, 'exported4D_linux_raw.fif')
fname_ctf_raw = op.join(op.dirname(__file__), '..', '..', 'io', 'tests',
'data', 'test_ctf_comp_raw.fif')
# first set up a testing source space
fname_src = op.join(temp_dir, 'oct2-src.fif')
src = setup_source_space('sample', fname_src, 'oct2',
subjects_dir=subjects_dir)
# first use mne-C: convert file, make forward solution
fwd = do_forward_solution('sample', fname_kit_raw, src=fname_src,
mindist=0.0, bem=fname_bem, mri=mri_path,
eeg=False, meg=True, subjects_dir=subjects_dir)
assert_true(isinstance(fwd, Forward))
# now let's use python with the same raw file
fwd_py = make_forward_solution(fname_kit_raw, mindist=0.0,
src=src, eeg=False, meg=True,
bem=fname_bem, mri=mri_path)
_compare_forwards(fwd, fwd_py, 157, 108)
assert_true(isinstance(fwd_py, Forward))
# now let's use mne-python all the way
raw_py = read_raw_kit(sqd_path, mrk_path, elp_path, hsp_path)
# without ignore_ref=True, this should throw an error:
assert_raises(NotImplementedError, make_forward_solution, raw_py.info,
mindist=0.0, src=src, eeg=False, meg=True,
bem=fname_bem, mri=mri_path)
fwd_py = make_forward_solution(raw_py.info, mindist=0.0,
src=src, eeg=False, meg=True,
bem=fname_bem, mri=mri_path,
ignore_ref=True)
_compare_forwards(fwd, fwd_py, 157, 108,
meg_rtol=1e-3, meg_atol=1e-7)
# BTI python end-to-end versus C
fwd = do_forward_solution('sample', fname_bti_raw, src=fname_src,
mindist=0.0, bem=fname_bem, mri=mri_path,
eeg=False, meg=True, subjects_dir=subjects_dir)
raw_py = read_raw_bti(bti_pdf, bti_config, bti_hs)
fwd_py = make_forward_solution(raw_py.info, mindist=0.0,
src=src, eeg=False, meg=True,
bem=fname_bem, mri=mri_path)
_compare_forwards(fwd, fwd_py, 248, 108)
# now let's test CTF w/compensation
fwd_py = make_forward_solution(fname_ctf_raw, mindist=0.0,
src=src, eeg=False, meg=True,
|
请发表评论