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 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_trunc_decimals(self): reference = np.array([0, 0, 0.1]) test_input = reference + np.random.random(3) * 0.1 result = indexing.trunc_decimals(test_input, 1) npt.assert_array_equal(result, reference)
def test_trunc_decimals(self): reference = np.array([0, 0, 0.1]) test_input = reference + np.random.random(3) * 0.1 result = indexing.trunc_decimals(test_input, 1) npt.assert_array_equal(result, reference)