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): raw_info, _ = get_info(pdf, config, hs, convert=False) 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)) nasion, lpa, rpa, hpi, dig_points = _read_head_shape(hs) dig, t, _ = _make_bti_dig_points(nasion, lpa, rpa, hpi, dig_points, 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 (not np.allclose(old['r'], con['r'])) if ii > 10: break ch_map = {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 (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)
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): raw_info, _ = get_info(pdf, config, hs, convert=False) 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)) idx_points, dig_points = _read_head_shape(hs) dig, t, _ = _make_bti_dig_points(idx_points, dig_points, 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 (not np.allclose(old['r'], con['r'])) if ii > 10: break ch_map = {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 (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)
def test_setup_headshape(): """Test reading bti headshape.""" for hs in hs_fnames: nasion, lpa, rpa, hpi, dig_points = _read_head_shape(hs) dig, t, _ = _make_bti_dig_points(nasion, lpa, rpa, hpi, dig_points) expected = {'kind', 'ident', 'r'} found = set( reduce(lambda x, y: list(x) + list(y), [d.keys() for d in dig])) assert (not expected - found)
def test_setup_headshape(): """Test reading bti headshape.""" for hs in hs_fnames: idx_points, dig_points = _read_head_shape(hs) dig, t, _ = _make_bti_dig_points(idx_points, dig_points) expected = {'kind', 'ident', 'r'} found = set(reduce(lambda x, y: list(x) + list(y), [d.keys() for d in dig])) assert (not expected - found)