def test_from_neo_euler_symmetry(self): v = AxAngle.from_axes_angles(axes=Vector3d.zvector(), angles=np.pi / 2) o1 = Orientation.from_neo_euler(v) assert np.allclose(o1.data, [0.7071, 0, 0, 0.7071]) assert o1.symmetry.name == "1" o2 = Orientation.from_neo_euler(v, symmetry=Oh) assert np.allclose(o2.data, [-1, 0, 0, 0]) assert o2.symmetry.name == "m-3m" o3 = o1.set_symmetry(Oh) assert np.allclose(o3.data, o2.data)
def test_from_euler_symmetry(self): euler = np.deg2rad([90, 45, 90]) o1 = Orientation.from_euler(euler) assert np.allclose(o1.data, [0, -0.3827, 0, -0.9239], atol=1e-4) assert o1.symmetry.name == "1" o2 = Orientation.from_euler(euler, symmetry=Oh) assert np.allclose(o2.data, [0.9239, 0, 0.3827, 0], atol=1e-4) assert o2.symmetry.name == "m-3m" o3 = o1.set_symmetry(Oh) assert np.allclose(o3.data, o2.data)
def test_orientation_persistence(symmetry, vector): v = symmetry.outer(vector).flatten() o = Orientation.random() oc = o.set_symmetry(symmetry) v1 = o * v v1 = Vector3d(v1.data.round(4)) v2 = oc * v v2 = Vector3d(v2.data.round(4)) assert v1._tuples == v2._tuples
def test_from_matrix_symmetry(self): om = np.array( [np.eye(3), np.eye(3), np.diag([1, -1, -1]), np.diag([1, -1, -1])]) o1 = Orientation.from_matrix(om) assert np.allclose( o1.data, np.array([1, 0, 0, 0] * 2 + [0, 1, 0, 0] * 2).reshape((4, 4))) assert o1.symmetry.name == "1" o2 = Orientation.from_matrix(om, symmetry=Oh) assert np.allclose( o2.data, np.array([1, 0, 0, 0] * 2 + [-1, 0, 0, 0] * 2).reshape((4, 4))) assert o2.symmetry.name == "m-3m" o3 = o1.set_symmetry(Oh) assert np.allclose(o3.data, o2.data)
def test_orientations_symmetry(self, point_group, rotation, expected_orientation): r = Rotation(rotation) cm = CrystalMap(rotations=r, phase_id=np.array([0])) cm.phases = PhaseList(Phase("a", point_group=point_group)) o = cm.orientations assert np.allclose( o.data, Orientation(r).set_symmetry(point_group).data, atol=1e-3 ) assert np.allclose(o.data, expected_orientation, atol=1e-3)
def test_get_orientations_array(self, crystal_map_input, phase_list): cm = CrystalMap(**crystal_map_input) cm[:2, 0].phase_id = 1 # Test code assumption id1 = 0 id2 = 1 assert np.allclose(np.unique(cm.phase_id), np.array([id1, id2])) cm.phases = phase_list # Get all with string o = cm.get_map_data("orientations") # Get per phase with string cm1 = cm[cm.phase_id == id1] cm2 = cm[cm.phase_id == id2] o1 = cm1.get_map_data("orientations") o2 = cm2.get_map_data("orientations") expected_o1 = cm1.orientations.to_euler() expected_shape = expected_o1.shape assert np.allclose( o1[~np.isnan(o1)].reshape(expected_shape), expected_o1, atol=1e-3 ) expected_o2 = cm2.orientations.to_euler() expected_shape = expected_o2.shape assert np.allclose( o2[~np.isnan(o2)].reshape(expected_shape), expected_o2, atol=1e-3 ) # Do calculations "manually" data_shape = (cm.size, 3) array = np.zeros(data_shape) if cm.rotations_per_point > 1: rotations = cm.rotations[:, 0] else: rotations = cm.rotations for i, phase in cm.phases_in_data: phase_mask = cm._phase_id == i phase_mask_in_data = cm.phase_id == i array[phase_mask] = ( Orientation(rotations[phase_mask_in_data]) .set_symmetry(phase.point_group) .to_euler() ) assert np.allclose(o, array.reshape(o.shape), atol=1e-3)
def orientations(self): """Rotations, respecting symmetry, in data.""" # TODO: Consider whether orientations should be calculated upon # loading since computing orientations are slow (should benefit # from dask!) phases = self.phases_in_data if phases.size == 1: # Extract top matching rotations per point, if more than one if self.rotations_per_point > 1: rotations = self.rotations[:, 0] else: rotations = self.rotations return Orientation(rotations).set_symmetry(phases[:].point_group) else: raise ValueError( f"Data has the phases {phases.names}, however, you are executing a " "command that only permits one phase." )
def test_sub_orientation_and_other(): m = Orientation([1, 1, 1, 1]) # any will do mis = m - 3
def orientation(request): return Orientation(request.param)
def test_sub(): m = Orientation([1, 1, 1, 1]) # any will do m.set_symmetry(C4) # only one as it a O mis = m - m # this should give a set of zeroes return None
def test_coverage_on_faces(): o = OrientationRegion(Orientation([1, 1, 1, 1])) f = o.faces() return None
def test_sub_orientation_and_other(): m = Orientation([1, 1, 1, 1]) # any will do with pytest.raises(TypeError): _ = m - 3
def test_sub(): m = Orientation([1, 1, 1, 1]) # any will do m.set_symmetry(C4) # only one as it a O assert np.allclose((m - m).data, [1, 0, 0, 0])