def test_average(self, angle, lattice): R_1 = Orientation( Rotation.from_axis_angle([0, 0, 1, 10], degrees=True), lattice) R_2 = Orientation( Rotation.from_axis_angle([0, 0, 1, angle], degrees=True), lattice) avg_angle = R_1.average(R_2).rotation.as_axis_angle(degrees=True, pair=True)[1] assert np.isclose(avg_angle, 10 + (angle - 10) / 2.)
def test_matrix(self, set_of_rotations): for rot in set_of_rotations: m = rot.as_axis_angle() o = Rotation.from_axis_angle(rot.as_axis_angle()).as_axis_angle() ok = np.allclose(m, o, atol=atol) if np.isclose(m[3], np.pi, atol=atol): ok = ok or np.allclose( m * np.array([-1., -1., -1., 1.]), o, atol=atol) assert ok and np.isclose(np.linalg.norm(o[:3]),1.0) \ and o[3]<=np.pi+1.e-9, f'{m},{o},{rot.as_quaternion()}'
def test_matrix(self, default): for rot in default: m = rot.as_axis_angle() o = Rotation.from_axis_angle(rot.as_axis_angle()).as_axis_angle() ok = np.allclose(m, o, atol=atol) if np.isclose(m[3], np.pi, atol=atol): ok = ok or np.allclose( m * np.array([-1., -1., -1., 1.]), o, atol=atol) print(m, o, rot.as_quaternion()) assert ok and np.isclose(np.linalg.norm(o[:3]), 1.0) and o[3] <= np.pi + 1.e-9
def test_axis_angle(self, set_of_rotations, degrees, normalize, P): c = np.array([P * -1, P * -1, P * -1, 1.]) for rot in set_of_rotations: m = rot.as_Eulers() o = Rotation.from_axis_angle( rot.as_axis_angle(degrees) * c, degrees, normalize, P).as_Eulers() u = np.array([np.pi * 2, np.pi, np.pi * 2]) ok = np.allclose(m, o, atol=atol) ok |= np.allclose(np.where(np.isclose(m, u), m - u, m), np.where(np.isclose(o, u), o - u, o), atol=atol) if np.isclose(m[1], 0.0, atol=atol) or np.isclose( m[1], np.pi, atol=atol): sum_phi = np.unwrap([m[0] + m[2], o[0] + o[2]]) ok |= np.isclose(sum_phi[0], sum_phi[1], atol=atol) assert ok and (np.zeros(3)-1.e-9 <= o).all() \ and (o <= np.array([np.pi*2.,np.pi,np.pi*2.])+1.e-9).all(), f'{m},{o},{rot.as_quaternion()}'
def test_from_fiber_component(self, N, sigma): p = [] for run in range(5): alpha = np.random.random() * 2 * np.pi, np.arccos( np.random.random()) beta = np.random.random() * 2 * np.pi, np.arccos( np.random.random()) f_in_C = np.array([ np.sin(alpha[0]) * np.cos(alpha[1]), np.sin(alpha[0]) * np.sin(alpha[1]), np.cos(alpha[0]) ]) f_in_S = np.array([ np.sin(beta[0]) * np.cos(beta[1]), np.sin(beta[0]) * np.sin(beta[1]), np.cos(beta[0]) ]) ax = np.append(np.cross(f_in_C, f_in_S), -np.arccos(np.dot(f_in_C, f_in_S))) n = Rotation.from_axis_angle( ax if ax[3] > 0.0 else ax * -1.0, normalize=True ) # rotation to align fiber axis in crystal and sample system o = Rotation.from_fiber_component(alpha, beta, np.radians(sigma), N, False) angles = np.arccos( np.clip( np.dot(o @ np.broadcast_to(f_in_S, (N, 3)), n @ f_in_S), -1, 1)) dist = np.array(angles) * (np.random.randint(0, 2, N) * 2 - 1) p.append(stats.normaltest(dist)[1]) sigma_out = np.degrees(np.std(dist)) p = np.average(p) assert (.9 < sigma / sigma_out < 1.1) and p > 1e-2, f'{sigma/sigma_out},{p}'
def test_rotate360(self,default,axis_angle): modified = default.copy() for i in range(np.rint(360/axis_angle[3]).astype(int)): modified.rotate(Rotation.from_axis_angle(axis_angle,degrees=True)) assert grid_equal(default,modified)
def test_rotate360(self,default,axis_angle): modified = copy.deepcopy(default) for i in range(np.rint(360/axis_angle[3]).astype(int)): modified.rotate(Rotation.from_axis_angle(axis_angle,degrees=True)) assert geom_equal(modified,default)