def test_quaternions(): """Test quaternion calculations """ rots = [np.eye(3)] for fname in [test_fif_fname, ctf_fname, hp_fif_fname]: rots += [read_info(fname)['dev_head_t']['trans'][:3, :3]] for rot in rots: assert_allclose(rot, _quat_to_rot(_rot_to_quat(rot)), rtol=1e-5, atol=1e-5) rot = rot[np.newaxis, np.newaxis, :, :] assert_allclose(rot, _quat_to_rot(_rot_to_quat(rot)), rtol=1e-5, atol=1e-5) # let's make sure our angle function works in some reasonable way for ii in range(3): for jj in range(3): a = np.zeros(3) b = np.zeros(3) a[ii] = 1. b[jj] = 1. expected = np.pi if ii != jj else 0. assert_allclose(_angle_between_quats(a, b), expected, atol=1e-5)
def test_quaternions(): """Test quaternion calculations """ rots = [np.eye(3)] for fname in [test_fif_fname, ctf_fname, hp_fif_fname]: rots += [read_info(fname)['dev_head_t']['trans'][:3, :3]] # nasty numerical cases rots += [ np.array([ [-0.99978541, -0.01873462, -0.00898756], [-0.01873462, 0.62565561, 0.77987608], [-0.00898756, 0.77987608, -0.62587152], ]) ] rots += [ np.array([ [0.62565561, -0.01873462, 0.77987608], [-0.01873462, -0.99978541, -0.00898756], [0.77987608, -0.00898756, -0.62587152], ]) ] rots += [ np.array([ [-0.99978541, -0.00898756, -0.01873462], [-0.00898756, -0.62587152, 0.77987608], [-0.01873462, 0.77987608, 0.62565561], ]) ] for rot in rots: assert_allclose(rot, _quat_to_rot(_rot_to_quat(rot)), rtol=1e-5, atol=1e-5) rot = rot[np.newaxis, np.newaxis, :, :] assert_allclose(rot, _quat_to_rot(_rot_to_quat(rot)), rtol=1e-5, atol=1e-5) # let's make sure our angle function works in some reasonable way for ii in range(3): for jj in range(3): a = np.zeros(3) b = np.zeros(3) a[ii] = 1. b[jj] = 1. expected = np.pi if ii != jj else 0. assert_allclose(_angle_between_quats(a, b), expected, atol=1e-5)
def test_get_chpi(): """Test CHPI position computation """ trans0, rot0, _, quat0 = get_chpi_positions(hp_fname, return_quat=True) assert_allclose(rot0[0], _quat_to_rot(quat0[0])) trans0, rot0 = trans0[:-1], rot0[:-1] raw = Raw(hp_fif_fname) out = get_chpi_positions(raw) trans1, rot1, t1 = out trans1, rot1 = trans1[2:], rot1[2:] # these will not be exact because they don't use equiv. time points assert_allclose(trans0, trans1, atol=1e-5, rtol=1e-1) assert_allclose(rot0, rot1, atol=1e-6, rtol=1e-1) # run through input checking assert_raises(TypeError, get_chpi_positions, 1) assert_raises(ValueError, get_chpi_positions, hp_fname, [1]) raw_no_chpi = Raw(test_fif_fname) assert_raises(RuntimeError, get_chpi_positions, raw_no_chpi) assert_raises(ValueError, get_chpi_positions, raw, t_step='foo') assert_raises(IOError, get_chpi_positions, 'foo')