def PyExec(self): tolerance = self.getProperty("Tolerance").value k = int(self.getProperty("NumOfQs").value) nuclear = self.getProperty("NuclearPeaks").value satellites = self.getProperty("SatellitePeaks").value cluster_threshold = self.getProperty("ClusterThreshold").value n_trunc_decimals = int(np.ceil(abs(np.log10(tolerance)))) if nuclear.getNumberPeaks() == 0: raise RuntimeError( "The NuclearPeaks parameter must have at least one peak") if satellites.getNumberPeaks() == 0: raise RuntimeError( "The SatellitePeaks parameter must have at least one peak") nuclear_hkls = indexing.get_hkls(nuclear) sats_hkls = indexing.get_hkls(satellites) qs = indexing.find_q_vectors(nuclear_hkls, sats_hkls) self.log().notice("K value is {}".format(k)) k = None if k == -1 else k clusters, k = indexing.cluster_qs(qs, k=k, threshold=cluster_threshold) qs = indexing.average_clusters(qs, clusters) qs = indexing.trunc_decimals(qs, n_trunc_decimals) qs = indexing.sort_vectors_by_norm(qs) self.log().notice("Q vectors are: \n{}".format(qs)) indices = indexing.index_q_vectors(qs, tolerance) ndim = indices.shape[1] + 3 hkls = indexing.find_nearest_integer_peaks(nuclear_hkls, sats_hkls) hklm = np.zeros((hkls.shape[0], ndim)) hklm[:, :3] = np.round(hkls) raw_qs = hkls - sats_hkls peak_map = KDTree(qs) for i, q in enumerate(raw_qs): distance, index = peak_map.query(q, k=1) hklm[i, 3:] = indices[index] indexed = self.create_indexed_peaksworkspace(satellites, qs, hklm) self.setProperty("OutputWorkspace", indexed)
def PyExec(self): tolerance = self.getProperty("Tolerance").value k = int(self.getProperty("NumOfQs").value) nuclear = self.getProperty("NuclearPeaks").value satellites = self.getProperty("SatellitePeaks").value cluster_threshold = self.getProperty("ClusterThreshold").value n_trunc_decimals = int(np.ceil(abs(np.log10(tolerance)))) if nuclear.getNumberPeaks() == 0: raise RuntimeError("The NuclearPeaks parameter must have at least one peak") if satellites.getNumberPeaks() == 0: raise RuntimeError("The SatellitePeaks parameter must have at least one peak") nuclear_hkls = indexing.get_hkls(nuclear) sats_hkls = indexing.get_hkls(satellites) qs = indexing.find_q_vectors(nuclear_hkls, sats_hkls) self.log().notice("K value is {}".format(k)) k = None if k == -1 else k clusters, k = indexing.cluster_qs(qs, k=k, threshold=cluster_threshold) qs = indexing.average_clusters(qs, clusters) qs = indexing.trunc_decimals(qs, n_trunc_decimals) qs = indexing.sort_vectors_by_norm(qs) self.log().notice("Q vectors are: \n{}".format(qs)) indices = indexing.index_q_vectors(qs, tolerance) ndim = indices.shape[1] + 3 hkls = indexing.find_nearest_integer_peaks(nuclear_hkls, sats_hkls) hklm = np.zeros((hkls.shape[0], ndim)) hklm[:, :3] = np.round(hkls) raw_qs = hkls - sats_hkls peak_map = KDTree(qs) for i, q in enumerate(raw_qs): distance, index = peak_map.query(q, k=1) hklm[i, 3:] = indices[index] indexed = self.create_indexed_workspace(satellites, ndim, hklm) self.setProperty("OutputWorkspace", indexed)
def test_find_indexing_with_non_orthogonal_cell(self): cell = UnitCell(1, 1, 1, 90, 95, 103) cart_cell = cell.getB() qs = np.array([ [.5, 0, 0], [0, .5, 0], [0, 0, .5], [0, 0, .25], ]) qs = np.dot(qs, cart_cell) indices = indexing.index_q_vectors(qs) expected_indexing = np.array([[0, 0, 1], [0, 1, 0], [2, 0, 0], [1, 0, 0]]) npt.assert_equal(indices, expected_indexing, err_msg="Indexing does not match expected.")
def test_index_with_modulation(self): qs = np.array([ [0, .1, .1], [0, -.1, 0], [0, 0, .1], [0, 0, -.1], [0, .1, .2], [0, 0, .45], ]) expected_indexing = np.array([ [-1, 1, 0], [ 1, 0, 0], [ 0, 1, 0], [ 0, -1, 0], [-1, 2, 0], [ 0, 0, 1] ]) actual_indexing = indexing.index_q_vectors(qs, tolerance=.03) npt.assert_array_equal(actual_indexing, expected_indexing)
def test_find_indexing_with_non_orthogonal_cell(self): cell = UnitCell(1, 1, 1, 90, 95, 103) cart_cell = cell.getB() qs = np.array([ [.5, 0, 0], [0, .5, 0], [0, 0, .5], [0, 0, .25], ]) qs = np.dot(qs, cart_cell) indices = indexing.index_q_vectors(qs) expected_indexing = np.array([ [0, 0, 1], [0, 1, 0], [2, 0, 0], [1, 0, 0] ]) npt.assert_equal(indices, expected_indexing, err_msg="Indexing does not match expected.")