def test_vector_indexation_generator_index_vectors(vector_match_peaks, vector_library): # vectors not used directly vectors = DiffractionVectors(np.array(vector_match_peaks[:, :2])) vectors.cartesian = DiffractionVectors(np.array(vector_match_peaks)) gen = VectorIndexationGenerator(vectors, vector_library) indexation = gen.index_vectors(mag_tol=0.1, angle_tol=6, index_error_tol=0.3, n_peaks_to_index=2, n_best=5) # Values are tested directly on the match_vector in the util tests assert isinstance(indexation.vectors, DiffractionVectors) # (n_best=1, 5 result values from each) np.testing.assert_equal(indexation.data.shape, (5, )) # n_best=1, 3 peaks with hkl) np.testing.assert_equal(indexation.hkls.shape, (1, 3, 3)) refined1 = gen.refine_n_best_orientations(indexation, 1.0, 1.0, n_best=0) assert isinstance(refined1.vectors, DiffractionVectors) np.testing.assert_equal(refined1.data.shape, (5, )) refined2 = gen.refine_best_orientation(indexation, 1.0, 1.0) assert isinstance(refined2.vectors, DiffractionVectors) np.testing.assert_equal(refined2.data.shape, (1, )) assert isinstance(refined2.data[0], OrientationResult) assert refined2.data[0].phase_index == indexation.data[0].phase_index assert refined2.data[0].match_rate == indexation.data[0].match_rate # Must use a large tolerance here, because there are only 3 vectors np.testing.assert_almost_equal( np.diag(refined1.data[0].rotation_matrix), np.diag(indexation.data[0].rotation_matrix), 1, ) np.testing.assert_almost_equal( np.diag(refined2.data[0].rotation_matrix), np.diag(indexation.data[0].rotation_matrix), 1, )
def test_vector_indexation_generator_index_vectors(vector_match_peaks, vector_library): # vectors not used directly vectors = DiffractionVectors(np.array(vector_match_peaks[:, :2])) vectors.cartesian = DiffractionVectors(np.array(vector_match_peaks)) gen = VectorIndexationGenerator(vectors, vector_library) indexation = gen.index_vectors(mag_tol=0.1, angle_tol=6, index_error_tol=0.3, n_peaks_to_index=2, n_best=1) # Values are tested directly on the match_vector in the util tests assert isinstance(indexation.vectors, DiffractionVectors) # (n_best=1, 5 result values from each) np.testing.assert_equal(indexation.data.shape, (1, 5)) # n_best=1, 3 peaks with hkl) np.testing.assert_equal(indexation.hkls.shape, (1, 3, 3))
def get_vector_match_results(structure, rot_list, edc): diffraction_library = get_template_library(structure, rot_list, edc) peak_lists = [] for pixel_coords in diffraction_library['A']['pixel_coords']: peak_lists.append(pixel_coords) peaks = DiffractionVectors((np.array([peak_lists, peak_lists]) - half_side_length) / half_side_length) peaks.axes_manager.set_signal_dimension(2) peaks.calculate_cartesian_coordinates(200, 0.2) peaks.cartesian.axes_manager.set_signal_dimension(2) structure_library = StructureLibrary(['A'], [structure], [[]]) library_generator = VectorLibraryGenerator(structure_library) vector_library = library_generator.get_vector_library(1) indexation_generator = VectorIndexationGenerator(peaks, vector_library) indexation = indexation_generator.index_vectors( mag_tol=1.5 / half_side_length, angle_tol=1, index_error_tol=0.2, n_peaks_to_index=5, n_best=2) return diffraction_library, indexation