def test_make_forward_solution_kit(): """Test making fwd using KIT, BTI, and CTF (compensated) files.""" 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') trans_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 small testing source space temp_dir = _TempDir() fname_src_small = op.join(temp_dir, 'sample-oct-2-src.fif') src = setup_source_space('sample', 'oct2', subjects_dir=subjects_dir, add_dist=False) write_source_spaces(fname_src_small, src) # to enable working with MNE-C n_src = 108 # this is the resulting # of verts in fwd # first use mne-C: convert file, make forward solution fwd = _do_forward_solution('sample', fname_kit_raw, src=fname_src_small, bem=fname_bem_meg, mri=trans_path, eeg=False, meg=True, subjects_dir=subjects_dir) assert (isinstance(fwd, Forward)) # now let's use python with the same raw file fwd_py = make_forward_solution(fname_kit_raw, trans_path, src, fname_bem_meg, eeg=False, meg=True) _compare_forwards(fwd, fwd_py, 157, n_src) assert (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: pytest.raises(NotImplementedError, make_forward_solution, raw_py.info, src=src, eeg=False, meg=True, bem=fname_bem_meg, trans=trans_path) # check that asking for eeg channels (even if they don't exist) is handled meg_only_info = pick_info(raw_py.info, pick_types(raw_py.info, meg=True, eeg=False)) fwd_py = make_forward_solution(meg_only_info, src=src, meg=True, eeg=True, bem=fname_bem_meg, trans=trans_path, ignore_ref=True) _compare_forwards(fwd, fwd_py, 157, n_src, 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_small, bem=fname_bem_meg, mri=trans_path, eeg=False, meg=True, subjects_dir=subjects_dir) raw_py = read_raw_bti(bti_pdf, bti_config, bti_hs, preload=False) fwd_py = make_forward_solution(raw_py.info, src=src, eeg=False, meg=True, bem=fname_bem_meg, trans=trans_path) _compare_forwards(fwd, fwd_py, 248, n_src) # now let's test CTF w/compensation fwd_py = make_forward_solution(fname_ctf_raw, fname_trans, src, fname_bem_meg, eeg=False, meg=True) fwd = _do_forward_solution('sample', fname_ctf_raw, mri=fname_trans, src=fname_src_small, bem=fname_bem_meg, eeg=False, meg=True, subjects_dir=subjects_dir) _compare_forwards(fwd, fwd_py, 274, n_src) # CTF with compensation changed in python ctf_raw = read_raw_fif(fname_ctf_raw) ctf_raw.info['bads'] = ['MRO24-2908'] # test that it works with some bads ctf_raw.apply_gradient_compensation(2) fwd_py = make_forward_solution(ctf_raw.info, fname_trans, src, fname_bem_meg, eeg=False, meg=True) fwd = _do_forward_solution('sample', ctf_raw, mri=fname_trans, src=fname_src_small, bem=fname_bem_meg, eeg=False, meg=True, subjects_dir=subjects_dir) _compare_forwards(fwd, fwd_py, 274, n_src) temp_dir = _TempDir() fname_temp = op.join(temp_dir, 'test-ctf-fwd.fif') write_forward_solution(fname_temp, fwd_py) fwd_py2 = read_forward_solution(fname_temp) _compare_forwards(fwd_py, fwd_py2, 274, n_src) repr(fwd_py)
def test_make_forward_solution_kit(): """Test making fwd using KIT, BTI, and CTF (compensated) files.""" 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') trans_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 small testing source space temp_dir = _TempDir() fname_src_small = op.join(temp_dir, 'sample-oct-2-src.fif') src = setup_source_space('sample', 'oct2', subjects_dir=subjects_dir, add_dist=False) write_source_spaces(fname_src_small, src) # to enable working with MNE-C n_src = 108 # this is the resulting # of verts in fwd # first use mne-C: convert file, make forward solution fwd = _do_forward_solution('sample', fname_kit_raw, src=fname_src_small, bem=fname_bem_meg, mri=trans_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, trans_path, src, fname_bem_meg, eeg=False, meg=True) _compare_forwards(fwd, fwd_py, 157, n_src) 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, src=src, eeg=False, meg=True, bem=fname_bem_meg, trans=trans_path) # check that asking for eeg channels (even if they don't exist) is handled meg_only_info = pick_info(raw_py.info, pick_types(raw_py.info, meg=True, eeg=False)) fwd_py = make_forward_solution(meg_only_info, src=src, meg=True, eeg=True, bem=fname_bem_meg, trans=trans_path, ignore_ref=True) _compare_forwards(fwd, fwd_py, 157, n_src, 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_small, bem=fname_bem_meg, mri=trans_path, eeg=False, meg=True, subjects_dir=subjects_dir) with warnings.catch_warnings(record=True): # weight tables raw_py = read_raw_bti(bti_pdf, bti_config, bti_hs, preload=False) fwd_py = make_forward_solution(raw_py.info, src=src, eeg=False, meg=True, bem=fname_bem_meg, trans=trans_path) _compare_forwards(fwd, fwd_py, 248, n_src) # now let's test CTF w/compensation fwd_py = make_forward_solution(fname_ctf_raw, fname_trans, src, fname_bem_meg, eeg=False, meg=True) fwd = _do_forward_solution('sample', fname_ctf_raw, mri=fname_trans, src=fname_src_small, bem=fname_bem_meg, eeg=False, meg=True, subjects_dir=subjects_dir) _compare_forwards(fwd, fwd_py, 274, n_src) # CTF with compensation changed in python ctf_raw = read_raw_fif(fname_ctf_raw) ctf_raw.apply_gradient_compensation(2) fwd_py = make_forward_solution(ctf_raw.info, fname_trans, src, fname_bem_meg, eeg=False, meg=True) with warnings.catch_warnings(record=True): fwd = _do_forward_solution('sample', ctf_raw, mri=fname_trans, src=fname_src_small, bem=fname_bem_meg, eeg=False, meg=True, subjects_dir=subjects_dir) _compare_forwards(fwd, fwd_py, 274, n_src)
def test_make_forward_solution_kit(): """Test making fwd using KIT, BTI, and CTF (compensated) files """ 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") trans_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 small testing source space temp_dir = _TempDir() fname_src_small = op.join(temp_dir, "sample-oct-2-src.fif") src = setup_source_space("sample", fname_src_small, "oct2", subjects_dir=subjects_dir, add_dist=False) n_src = 108 # this is the resulting # of verts in fwd # first use mne-C: convert file, make forward solution fwd = _do_forward_solution( "sample", fname_kit_raw, src=fname_src_small, bem=fname_bem_meg, mri=trans_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, trans_path, src, fname_bem_meg, eeg=False, meg=True) _compare_forwards(fwd, fwd_py, 157, n_src) 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, src=src, eeg=False, meg=True, bem=fname_bem_meg, trans=trans_path, ) # check that asking for eeg channels (even if they don't exist) is handled meg_only_info = pick_info(raw_py.info, pick_types(raw_py.info, meg=True, eeg=False)) fwd_py = make_forward_solution( meg_only_info, src=src, meg=True, eeg=True, bem=fname_bem_meg, trans=trans_path, ignore_ref=True ) _compare_forwards(fwd, fwd_py, 157, n_src, 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_small, bem=fname_bem_meg, mri=trans_path, eeg=False, meg=True, subjects_dir=subjects_dir, ) with warnings.catch_warnings(record=True): # weight tables raw_py = read_raw_bti(bti_pdf, bti_config, bti_hs, preload=False) fwd_py = make_forward_solution(raw_py.info, src=src, eeg=False, meg=True, bem=fname_bem_meg, trans=trans_path) _compare_forwards(fwd, fwd_py, 248, n_src) # now let's test CTF w/compensation fwd_py = make_forward_solution(fname_ctf_raw, fname_trans, src, fname_bem_meg, eeg=False, meg=True) fwd = _do_forward_solution( "sample", fname_ctf_raw, mri=fname_trans, src=fname_src_small, bem=fname_bem_meg, eeg=False, meg=True, subjects_dir=subjects_dir, ) _compare_forwards(fwd, fwd_py, 274, n_src) # CTF with compensation changed in python ctf_raw = Raw(fname_ctf_raw, compensation=2) fwd_py = make_forward_solution(ctf_raw.info, fname_trans, src, fname_bem_meg, eeg=False, meg=True) with warnings.catch_warnings(record=True): fwd = _do_forward_solution( "sample", ctf_raw, mri=fname_trans, src=fname_src_small, bem=fname_bem_meg, eeg=False, meg=True, subjects_dir=subjects_dir, ) _compare_forwards(fwd, fwd_py, 274, n_src)