本文整理汇总了Python中mne.io.Raw.apply_gradient_compensation方法的典型用法代码示例。如果您正苦于以下问题:Python Raw.apply_gradient_compensation方法的具体用法?Python Raw.apply_gradient_compensation怎么用?Python Raw.apply_gradient_compensation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mne.io.Raw
的用法示例。
在下文中一共展示了Raw.apply_gradient_compensation方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_evoked
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import apply_gradient_compensation [as 别名]
def make_evoked(fname, comp):
raw = Raw(fname)
if comp is not None:
raw.apply_gradient_compensation(comp)
picks = pick_types(raw.info, meg=True, ref_meg=True)
events = np.array([[0, 0, 1]], dtype=np.int)
evoked = Epochs(raw, events, 1, 0, 20e-3, picks=picks).average()
return evoked
示例2: test_compensation
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import apply_gradient_compensation [as 别名]
def test_compensation():
"""Test compensation"""
tempdir = _TempDir()
raw = Raw(ctf_comp_fname, compensation=None)
assert_equal(get_current_comp(raw.info), 3)
comp1 = make_compensator(raw.info, 3, 1, exclude_comp_chs=False)
assert_true(comp1.shape == (340, 340))
comp2 = make_compensator(raw.info, 3, 1, exclude_comp_chs=True)
assert_true(comp2.shape == (311, 340))
# round-trip
desired = np.eye(340)
for from_ in range(3):
for to in range(3):
if from_ == to:
continue
comp1 = make_compensator(raw.info, from_, to)
comp2 = make_compensator(raw.info, to, from_)
# To get 1e-12 here (instead of 1e-6) we must use the linalg.inv
# method mentioned in compensator.py
assert_allclose(np.dot(comp1, comp2), desired, atol=1e-12)
assert_allclose(np.dot(comp2, comp1), desired, atol=1e-12)
# make sure that changing the comp doesn't modify the original data
raw2 = Raw(ctf_comp_fname).apply_gradient_compensation(2)
assert_equal(get_current_comp(raw2.info), 2)
fname = op.join(tempdir, 'ctf-raw.fif')
raw2.save(fname)
raw2 = Raw(fname)
assert_equal(raw2.compensation_grade, 2)
raw2.apply_gradient_compensation(3)
assert_equal(raw2.compensation_grade, 3)
data, _ = raw[:, :]
data2, _ = raw2[:, :]
# channels have norm ~1e-12
assert_allclose(data, data2, rtol=1e-9, atol=1e-18)
for ch1, ch2 in zip(raw.info['chs'], raw2.info['chs']):
assert_true(ch1['coil_type'] == ch2['coil_type'])
示例3: test_other_systems
# 需要导入模块: from mne.io import Raw [as 别名]
# 或者: from mne.io.Raw import apply_gradient_compensation [as 别名]
def test_other_systems():
"""Test Maxwell filtering on KIT, BTI, and CTF files"""
# 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)
with warnings.catch_warnings(record=True): # head fit
assert_raises(RuntimeError, maxwell_filter, raw_kit)
raw_sss = maxwell_filter(raw_kit, origin=(0., 0., 0.04), ignore_ref=True)
_assert_n_free(raw_sss, 65, 65)
raw_sss_auto = maxwell_filter(raw_kit, origin=(0., 0., 0.04),
ignore_ref=True, mag_scale='auto')
assert_allclose(raw_sss._data, raw_sss_auto._data)
# XXX this KIT origin fit is terrible! Eventually we should get a
# corrected HSP file with proper coverage
with warnings.catch_warnings(record=True):
with catch_logging() as log_file:
assert_raises(RuntimeError, maxwell_filter, raw_kit,
ignore_ref=True, regularize=None) # bad condition
raw_sss = maxwell_filter(raw_kit, origin='auto',
ignore_ref=True, bad_condition='warning',
verbose='warning')
log_file = log_file.getvalue()
assert_true('badly conditioned' in log_file)
assert_true('more than 20 mm from' in log_file)
# fits can differ slightly based on scipy version, so be lenient here
_assert_n_free(raw_sss, 28, 34) # bad origin == brutal reg
# Let's set the origin
with warnings.catch_warnings(record=True):
with catch_logging() as log_file:
raw_sss = maxwell_filter(raw_kit, origin=(0., 0., 0.04),
ignore_ref=True, bad_condition='warning',
regularize=None, verbose='warning')
log_file = log_file.getvalue()
assert_true('badly conditioned' in log_file)
_assert_n_free(raw_sss, 80)
# Now with reg
with warnings.catch_warnings(record=True):
with catch_logging() as log_file:
raw_sss = maxwell_filter(raw_kit, origin=(0., 0., 0.04),
ignore_ref=True, verbose=True)
log_file = log_file.getvalue()
assert_true('badly conditioned' not in log_file)
_assert_n_free(raw_sss, 65)
# 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): # weght table
raw_bti = read_raw_bti(bti_pdf, bti_config, bti_hs, preload=False)
picks = pick_types(raw_bti.info, meg='mag', exclude=())
power = np.sqrt(np.sum(raw_bti[picks][0] ** 2))
raw_sss = maxwell_filter(raw_bti)
_assert_n_free(raw_sss, 70)
_assert_shielding(raw_sss, power, 0.5)
raw_sss_auto = maxwell_filter(raw_bti, mag_scale='auto', verbose=True)
_assert_shielding(raw_sss_auto, power, 0.7)
# CTF
raw_ctf = Raw(fname_ctf_raw)
assert_equal(raw_ctf.compensation_grade, 3)
assert_raises(RuntimeError, maxwell_filter, raw_ctf) # compensated
raw_ctf.apply_gradient_compensation(0)
assert_raises(ValueError, maxwell_filter, raw_ctf) # cannot fit headshape
raw_sss = maxwell_filter(raw_ctf, origin=(0., 0., 0.04))
_assert_n_free(raw_sss, 68)
_assert_shielding(raw_sss, raw_ctf, 1.8)
raw_sss = maxwell_filter(raw_ctf, origin=(0., 0., 0.04), ignore_ref=True)
_assert_n_free(raw_sss, 70)
_assert_shielding(raw_sss, raw_ctf, 12)
raw_sss_auto = maxwell_filter(raw_ctf, origin=(0., 0., 0.04),
ignore_ref=True, mag_scale='auto')
assert_allclose(raw_sss._data, raw_sss_auto._data)