def test_misorientation_matrix(self): for test_euler in self.test_eulers: o = Orientation.from_euler(test_euler) g = o.orientation_matrix() delta = np.dot(g, g.T) self.assertEqual( Orientation.misorientation_angle_from_delta(delta), 0.0)
def poll_system(g_list, dis_tol=1.0, verbose=False): """ Poll system to sort a series of orientation matrices determined by the indexation procedure. For each orientation matrix, check if it corresponds to an existing solution, if so: vote for it, if not add a new solution to the list :param list g_list: the list of orientation matrices (should be in the fz) :param float dis_tol: angular tolerance (degrees) :param bool verbose: activate verbose mode (False by default) :return: a tuple composed by the most popular orientation matrix, the corresponding vote number and the confidence index """ solution_indices = [0] votes = [0] vote_index = np.zeros(len(g_list), dtype=int) dis_tol_rad = dis_tol * pi / 180 from pymicro.crystal.microstructure import Orientation for i in range(len(g_list)): g = g_list[i] # rotations are already in the fundamental zone for j in range(len(solution_indices)): index = solution_indices[j] delta = np.dot(g, g_list[index].T) # compute misorientation angle in radians angle = Orientation.misorientation_angle_from_delta(delta) if verbose: print('j=%d -- angle=%f' % (j, angle)) if angle <= dis_tol_rad: votes[j] += 1 vote_index[i] = j if verbose: print('angle (deg) is %.2f' % (180 / pi * angle)) print('vote list is now %s' % votes) print('solution_indices list is now %s' % solution_indices) break elif j == len(solution_indices) - 1: solution_indices.append(i) votes.append(1) vote_index[i] = len(votes) - 1 if verbose: print('vote list is now %s' % votes) print('solution_indices list is now %s' % solution_indices) break index_result = np.argwhere(votes == np.amax(votes)).flatten() if verbose: print('Max vote =', np.amax(votes)) print('index result:', index_result) print('Number of equivalent solutions :', len(index_result)) print(type(index_result)) print(index_result.shape) final_orientation_matrix = [] for n in range(len(index_result)): solutions = g_list[solution_indices[index_result[n]]] if verbose: print('Solution number {0:d} is'.format(n+1), solutions) final_orientation_matrix.append(solutions) result_vote = max(votes) ci = confidence_index(votes) vote_field = [votes[i] for i in vote_index] return final_orientation_matrix, result_vote, ci, vote_field
def test_small_disorientation(self): o_ref = Orientation(np.array([[-0.03454188, 0.05599919, -0.99783313], [-0.01223192, -0.99837784, -0.05560633], [-0.99932839, 0.01028467, 0.03517083]])) o_12 = Orientation(np.array([[-0.03807341, -0.06932796, -0.99686712], [-0.0234124, -0.99725469, 0.07024911], [-0.99900064, 0.02601367, 0.03634576]])) (angle, axis, axis_xyz) = o_ref.disorientation(o_12, crystal_structure=Symmetry.cubic) self.assertAlmostEqual(angle * 180 / np.pi, 7.24, 2) o_ref_fz = o_ref.move_to_FZ(symmetry=Symmetry.cubic, verbose=False) o_12_fz = o_12.move_to_FZ(symmetry=Symmetry.cubic, verbose=False) delta = np.dot(o_ref_fz.orientation_matrix(), o_12_fz.orientation_matrix().T) mis_angle = Orientation.misorientation_angle_from_delta(delta) self.assertAlmostEqual(mis_angle * 180 / np.pi, 7.24, 2)