def test_quaternion(self, set_of_rotations, P, accept_homomorph): c = np.array([1, P * -1, P * -1, P * -1 ]) * (-1 if accept_homomorph else 1) for rot in set_of_rotations: m = rot.as_cubochoric() o = Rotation.from_quaternion(rot.as_quaternion() * c, accept_homomorph, P).as_cubochoric() ok = np.allclose(m, o, atol=atol) if np.count_nonzero(np.isclose(np.abs(o), np.pi**(2. / 3.) * .5)): ok |= np.allclose(m * -1., o, atol=atol) assert ok and o.max() < np.pi**( 2. / 3.) * 0.5 + 1.e-9, f'{m},{o},{rot.as_quaternion()}'
def test_quaternion(self, default, P, accept_homomorph): c = np.array([1, P * -1, P * -1, P * -1 ]) * (-1 if accept_homomorph else 1) for rot in default: m = rot.as_cubochoric() o = Rotation.from_quaternion(rot.as_quaternion() * c, accept_homomorph, P).as_cubochoric() ok = np.allclose(m, o, atol=atol) if np.count_nonzero(np.isclose(np.abs(o), np.pi**(2. / 3.) * .5)): ok = ok or np.allclose(m * -1., o, atol=atol) print(m, o, rot.as_quaternion()) assert ok and o.max() < np.pi**(2. / 3.) * 0.5 + 1.e-9
def set_of_rotations(set_of_quaternions): return [Rotation.from_quaternion(s) for s in set_of_quaternions]
def default(): """A set of n random rotations.""" specials = np.array([ [1.0, 0.0, 0.0, 0.0], #---------------------- [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0], [0.0, -1.0, 0.0, 0.0], [0.0, 0.0, -1.0, 0.0], [0.0, 0.0, 0.0, -1.0], #---------------------- [1.0, 1.0, 0.0, 0.0], [1.0, 0.0, 1.0, 0.0], [1.0, 0.0, 0.0, 1.0], [0.0, 1.0, 1.0, 0.0], [0.0, 1.0, 0.0, 1.0], [0.0, 0.0, 1.0, 1.0], #---------------------- [1.0, -1.0, 0.0, 0.0], [1.0, 0.0, -1.0, 0.0], [1.0, 0.0, 0.0, -1.0], [0.0, 1.0, -1.0, 0.0], [0.0, 1.0, 0.0, -1.0], [0.0, 0.0, 1.0, -1.0], #---------------------- [0.0, 1.0, -1.0, 0.0], [0.0, 1.0, 0.0, -1.0], [0.0, 0.0, 1.0, -1.0], #---------------------- [0.0, -1.0, -1.0, 0.0], [0.0, -1.0, 0.0, -1.0], [0.0, 0.0, -1.0, -1.0], #---------------------- [1.0, 1.0, 1.0, 0.0], [1.0, 1.0, 0.0, 1.0], [1.0, 0.0, 1.0, 1.0], [1.0, -1.0, 1.0, 0.0], [1.0, -1.0, 0.0, 1.0], [1.0, 0.0, -1.0, 1.0], [1.0, 1.0, -1.0, 0.0], [1.0, 1.0, 0.0, -1.0], [1.0, 0.0, 1.0, -1.0], [1.0, -1.0, -1.0, 0.0], [1.0, -1.0, 0.0, -1.0], [1.0, 0.0, -1.0, -1.0], #---------------------- [0.0, 1.0, 1.0, 1.0], [0.0, 1.0, -1.0, 1.0], [0.0, 1.0, 1.0, -1.0], [0.0, -1.0, 1.0, 1.0], [0.0, -1.0, -1.0, 1.0], [0.0, -1.0, 1.0, -1.0], [0.0, -1.0, -1.0, -1.0], #---------------------- [1.0, 1.0, 1.0, 1.0], [1.0, -1.0, 1.0, 1.0], [1.0, 1.0, -1.0, 1.0], [1.0, 1.0, 1.0, -1.0], [1.0, -1.0, -1.0, 1.0], [1.0, -1.0, 1.0, -1.0], [1.0, 1.0, -1.0, -1.0], [1.0, -1.0, -1.0, -1.0], ]) specials /= np.linalg.norm(specials, axis=1).reshape(-1, 1) specials_scatter = specials + np.broadcast_to( np.random.rand(4) * scatter, specials.shape) specials_scatter /= np.linalg.norm(specials_scatter, axis=1).reshape(-1, 1) specials_scatter[specials_scatter[:, 0] < 0] *= -1 return [Rotation.from_quaternion(s) for s in specials] + \ [Rotation.from_quaternion(s) for s in specials_scatter] + \ [Rotation.from_random() for _ in range(n-len(specials)-len(specials_scatter))]