def find_peaks_automatic(self, x, y, peak_ind): massif = Massif(self.img_data.img_data) cur_peak_points = massif.find_peaks([x, y]) if len(cur_peak_points): self.points.append(np.array(cur_peak_points)) self.points_index.append(peak_ind) return np.array(cur_peak_points)
def search_peaks_on_ring(self, peak_index, delta_tth=0.1, algorithm='Massif', min_mean_factor=1, upper_limit=55000): if not self.is_calibrated: return #transform delta from degree into radians delta_tth = delta_tth / 180.0 * np.pi # get appropiate two theta value for the ring number tth_calibrant_list = self.calibrant.get_2th() tth_calibrant = np.float(tth_calibrant_list[peak_index]) print tth_calibrant # get the calculated two theta values for the whole image if self.geometry._ttha is None: tth_array = self.geometry.twoThetaArray(self.img_data.img_data.shape) else: tth_array = self.geometry._ttha # create mask based on two_theta position mask = abs(tth_array - tth_calibrant) <= delta_tth # init the peak search algorithm if algorithm == 'Massif': peak_search_algorithm = Massif(self.img_data.img_data) elif algorithm == 'Blob': peak_search_algorithm = BlobDetection(self.img_data.img_data * mask) peak_search_algorithm.process() else: return # calculate the mean and standard deviation of this area sub_data = np.array(self.img_data.img_data.ravel()[np.where(mask.ravel())], dtype=np.float64) sub_data[np.where(sub_data > upper_limit)] = np.NaN mean = np.nanmean(sub_data) std = np.nanstd(sub_data) # set the threshold into the mask (don't detect very low intensity peaks) threshold = min_mean_factor * mean + std mask2 = np.logical_and(self.img_data.img_data > threshold, mask) mask2[np.where(self.img_data.img_data > upper_limit)] = False size2 = mask2.sum(dtype=int) keep = int(np.ceil(np.sqrt(size2))) try: res = peak_search_algorithm.peaks_from_area(mask2, Imin=mean - std, keep=keep) except IndexError: res = [] # Store the result if len(res): self.points.append(np.array(res)) self.points_index.append(peak_index)
def search_peaks_on_ring(self, peak_index, delta_tth=0.1, algorithm='Massif', min_mean_factor=1, upper_limit=55000): if not self.is_calibrated: return #transform delta from degree into radians delta_tth = delta_tth / 180.0 * np.pi # get appropiate two theta value for the ring number tth_calibrant_list = self.calibrant.get_2th() tth_calibrant = np.float(tth_calibrant_list[peak_index]) print tth_calibrant # get the calculated two theta values for the whole image if self.geometry._ttha is None: tth_array = self.geometry.twoThetaArray( self.img_data.img_data.shape) else: tth_array = self.geometry._ttha # create mask based on two_theta position mask = abs(tth_array - tth_calibrant) <= delta_tth # init the peak search algorithm if algorithm == 'Massif': peak_search_algorithm = Massif(self.img_data.img_data) elif algorithm == 'Blob': peak_search_algorithm = BlobDetection(self.img_data.img_data * mask) peak_search_algorithm.process() else: return # calculate the mean and standard deviation of this area sub_data = np.array(self.img_data.img_data.ravel()[np.where( mask.ravel())], dtype=np.float64) sub_data[np.where(sub_data > upper_limit)] = np.NaN mean = np.nanmean(sub_data) std = np.nanstd(sub_data) # set the threshold into the mask (don't detect very low intensity peaks) threshold = min_mean_factor * mean + std mask2 = np.logical_and(self.img_data.img_data > threshold, mask) mask2[np.where(self.img_data.img_data > upper_limit)] = False size2 = mask2.sum(dtype=int) keep = int(np.ceil(np.sqrt(size2))) try: res = peak_search_algorithm.peaks_from_area(mask2, Imin=mean - std, keep=keep) except IndexError: res = [] # Store the result if len(res): self.points.append(np.array(res)) self.points_index.append(peak_index)