def test_read_pdf(): """ Test read bti PDF file """ for pdf, config in zip(pdf_fnames, config_fnames): info = _read_bti_header(pdf, config) data = _read_data(info) shape = (info['total_chans'], info['total_slices']) assert_true(data.shape == shape)
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))
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)) 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)
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)
def test_nan_trans(): """Test unlikely case that the device to head transform is empty.""" for ii, pdf_fname in enumerate(pdf_fnames): bti_info = _read_bti_header(pdf_fname, config_fnames[ii], sort_by_ch_name=True) dev_ctf_t = Transform('ctf_meg', 'ctf_head', _correct_trans(bti_info['bti_transform'][0])) # reading params convert = True rotation_x = 0. translation = (0.0, 0.02, 0.11) bti_dev_t = _get_bti_dev_t(rotation_x, translation) bti_dev_t = Transform('ctf_meg', 'meg', bti_dev_t) ecg_ch = 'E31' eog_ch = ('E63', 'E64') # read parts of info to get trans bti_ch_names = list() for ch in bti_info['chs']: ch_name = ch['name'] if not ch_name.startswith('A'): ch_name = ch.get('chan_label', ch_name) bti_ch_names.append(ch_name) neuromag_ch_names = _rename_channels(bti_ch_names, ecg_ch=ecg_ch, eog_ch=eog_ch) ch_mapping = zip(bti_ch_names, neuromag_ch_names) # add some nan in some locations! dev_ctf_t['trans'][:, 3] = np.nan _check_nan_dev_head_t(dev_ctf_t) for idx, (chan_4d, chan_neuromag) in enumerate(ch_mapping): loc = bti_info['chs'][idx]['loc'] if loc is not None: if convert: t = _loc_to_coil_trans(bti_info['chs'][idx]['loc']) t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)
def test_nan_trans(): """Test unlikely case that the device to head transform is empty.""" for ii, pdf_fname in enumerate(pdf_fnames): bti_info = _read_bti_header( pdf_fname, config_fnames[ii], sort_by_ch_name=True) dev_ctf_t = Transform('ctf_meg', 'ctf_head', _correct_trans(bti_info['bti_transform'][0])) # reading params convert = True rotation_x = 0. translation = (0.0, 0.02, 0.11) bti_dev_t = _get_bti_dev_t(rotation_x, translation) bti_dev_t = Transform('ctf_meg', 'meg', bti_dev_t) ecg_ch = 'E31' eog_ch = ('E63', 'E64') # read parts of info to get trans bti_ch_names = list() for ch in bti_info['chs']: ch_name = ch['name'] if not ch_name.startswith('A'): ch_name = ch.get('chan_label', ch_name) bti_ch_names.append(ch_name) neuromag_ch_names = _rename_channels( bti_ch_names, ecg_ch=ecg_ch, eog_ch=eog_ch) ch_mapping = zip(bti_ch_names, neuromag_ch_names) # add some nan in some locations! dev_ctf_t['trans'][:, 3] = np.nan _check_nan_dev_head_t(dev_ctf_t) for idx, (chan_4d, chan_neuromag) in enumerate(ch_mapping): loc = bti_info['chs'][idx]['loc'] if loc is not None: if convert: t = _loc_to_coil_trans(bti_info['chs'][idx]['loc']) t = _convert_coil_trans(t, dev_ctf_t, bti_dev_t)