def test_make_dig_points(): """Test application of Polhemus HSP to info.""" extra_points = _read_dig_points(hsp_fname) info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert info['dig'] is None info['dig'] = _make_dig_points(extra_points=extra_points) assert (info['dig']) assert_allclose(info['dig'][0]['r'], [-.10693, .09980, .06881]) elp_points = _read_dig_points(elp_fname) nasion, lpa, rpa = elp_points[:3] info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert info['dig'] is None info['dig'] = _make_dig_points(nasion, lpa, rpa, elp_points[3:], None) assert (info['dig']) idx = [d['ident'] for d in info['dig']].index(FIFF.FIFFV_POINT_NASION) assert_array_equal(info['dig'][idx]['r'], np.array([.0013930, .0131613, -.0046967])) pytest.raises(ValueError, _make_dig_points, nasion[:2]) pytest.raises(ValueError, _make_dig_points, None, lpa[:2]) pytest.raises(ValueError, _make_dig_points, None, None, rpa[:2]) pytest.raises(ValueError, _make_dig_points, None, None, None, elp_points[:, :2]) pytest.raises(ValueError, _make_dig_points, None, None, None, None, elp_points[:, :2])
def test_make_dig_points(): """Test application of Polhemus HSP to info""" dig_points = _read_dig_points(hsp_fname) info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert_false(info['dig']) info['dig'] = _make_dig_points(dig_points=dig_points) assert_true(info['dig']) assert_array_equal(info['dig'][0]['r'], [-106.93, 99.80, 68.81]) dig_points = _read_dig_points(elp_fname) nasion, lpa, rpa = dig_points[:3] info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert_false(info['dig']) info['dig'] = _make_dig_points(nasion, lpa, rpa, dig_points[3:], None) assert_true(info['dig']) idx = [d['ident'] for d in info['dig']].index(FIFF.FIFFV_POINT_NASION) assert_array_equal(info['dig'][idx]['r'], np.array([1.3930, 13.1613, -4.6967])) assert_raises(ValueError, _make_dig_points, nasion[:2]) assert_raises(ValueError, _make_dig_points, None, lpa[:2]) assert_raises(ValueError, _make_dig_points, None, None, rpa[:2]) assert_raises(ValueError, _make_dig_points, None, None, None, dig_points[:, :2]) assert_raises(ValueError, _make_dig_points, None, None, None, None, dig_points[:, :2])
def test_make_dig_points(): """Test application of Polhemus HSP to info""" dig_points = _read_dig_points(hsp_fname) info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert_false(info['dig']) info['dig'] = _make_dig_points(dig_points=dig_points) assert_true(info['dig']) assert_array_equal(info['dig'][0]['r'], [-106.93, 99.80, 68.81]) dig_points = _read_dig_points(elp_fname) nasion, lpa, rpa = dig_points[:3] info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert_false(info['dig']) info['dig'] = _make_dig_points(nasion, lpa, rpa, dig_points[3:], None) assert_true(info['dig']) idx = [d['ident'] for d in info['dig']].index(FIFF.FIFFV_POINT_NASION) assert_array_equal(info['dig'][idx]['r'], np.array([1.3930, 13.1613, -4.6967])) assert_raises(ValueError, _make_dig_points, nasion[:2]) assert_raises(ValueError, _make_dig_points, None, lpa[:2]) assert_raises(ValueError, _make_dig_points, None, None, rpa[:2]) assert_raises(ValueError, _make_dig_points, None, None, None, dig_points[:, :2]) assert_raises(ValueError, _make_dig_points, None, None, None, None, dig_points[:, :2])
def test_make_dig_points(): """Test application of Polhemus HSP to info.""" extra_points = _read_dig_points(hsp_fname) info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert info['dig'] is None info['dig'] = _make_dig_points(extra_points=extra_points) assert (info['dig']) assert_allclose(info['dig'][0]['r'], [-.10693, .09980, .06881]) elp_points = _read_dig_points(elp_fname) nasion, lpa, rpa = elp_points[:3] info = create_info(ch_names=['Test Ch'], sfreq=1000., ch_types=None) assert info['dig'] is None info['dig'] = _make_dig_points(nasion, lpa, rpa, elp_points[3:], None) assert (info['dig']) idx = [d['ident'] for d in info['dig']].index(FIFF.FIFFV_POINT_NASION) assert_array_equal(info['dig'][idx]['r'], np.array([.0013930, .0131613, -.0046967])) pytest.raises(ValueError, _make_dig_points, nasion[:2]) pytest.raises(ValueError, _make_dig_points, None, lpa[:2]) pytest.raises(ValueError, _make_dig_points, None, None, rpa[:2]) pytest.raises(ValueError, _make_dig_points, None, None, None, elp_points[:, :2]) pytest.raises(ValueError, _make_dig_points, None, None, None, None, elp_points[:, :2])
def replace_fiducials(info, fiducials): """Replace initial fiducial measuremnt with new estimates CTF systems measure fiducial location at the beginning of the measurement. When used with online head loc over multiple sessions these measurements are not accurate. This is because subjects are guided to the head position of previous sessions. Args: info: MNE info structure fiducials: dict Dictionary that contains fiducial positions, e.g. see output of get_ref_head_pos. Returns: Info structure with updated head position. """ from mne.io import meas_info fids = meas_info._make_dig_points(**fiducials) info = info.copy() dig = info['dig'] for i, d in enumerate(dig): if d['kind'] == 3: if d['ident'] == 3: dig[i]['r'] = fids[2]['r'] elif d['ident'] == 2: dig[i]['r'] = fids[1]['r'] elif d['ident'] == 1: dig[i]['r'] = fids[0]['r'] info['dig'] = dig return info
def test_make_dig_points(): """Test application of Polhemus HSP to info.""" extra_points = _read_dig_points(hsp_fname) info = create_info(ch_names=["Test Ch"], sfreq=1000.0, ch_types=None) assert_false(info["dig"]) info["dig"] = _make_dig_points(extra_points=extra_points) assert_true(info["dig"]) assert_allclose(info["dig"][0]["r"], [-0.10693, 0.09980, 0.06881]) elp_points = _read_dig_points(elp_fname) nasion, lpa, rpa = elp_points[:3] info = create_info(ch_names=["Test Ch"], sfreq=1000.0, ch_types=None) assert_false(info["dig"]) info["dig"] = _make_dig_points(nasion, lpa, rpa, elp_points[3:], None) assert_true(info["dig"]) idx = [d["ident"] for d in info["dig"]].index(FIFF.FIFFV_POINT_NASION) assert_array_equal(info["dig"][idx]["r"], np.array([0.0013930, 0.0131613, -0.0046967])) assert_raises(ValueError, _make_dig_points, nasion[:2]) assert_raises(ValueError, _make_dig_points, None, lpa[:2]) assert_raises(ValueError, _make_dig_points, None, None, rpa[:2]) assert_raises(ValueError, _make_dig_points, None, None, None, elp_points[:, :2]) assert_raises(ValueError, _make_dig_points, None, None, None, None, elp_points[:, :2])
def replace_fiducials(info, fiducials): from mne.io import meas_info fids = meas_info._make_dig_points(**fiducials) info = info.copy() dig = info['dig'] for i, d in enumerate(dig): if d['kind'] == 3: if d['ident'] == 3: dig[i]['r'] = fids[2]['r'] elif d['ident'] == 2: dig[i]['r'] = fids[1]['r'] elif d['ident'] == 1: dig[i]['r'] = fids[0]['r'] info['dig'] = dig return info