def __plotClicked(self, x, y): image = self.model().experimentSettingsModel().image().value() massif = pyFAI.massif.Massif(image) points = massif.find_peaks([y, x], stdout=_DummyStdOut()) if len(points) == 0: # toleration toleration = 3 # clamp min to avoid negative values ymin = y - toleration if ymin < 0: ymin = 0 ymax = y + toleration + 1 xmin = x - toleration if xmin < 0: xmin = 0 xmax = x + toleration + 1 data = image[ymin:ymax, xmin:xmax] coord = numpy.argmax(data) coord = numpy.unravel_index(coord, data.shape) y, x = ymin + coord[0], xmin + coord[1] points = massif.find_peaks([y, x], stdout=_DummyStdOut()) # filter peaks from the mask mask = self.model().experimentSettingsModel().mask().value() if mask is not None: points = filter( lambda coord: mask[int(coord[0]), int(coord[1])] != 1, points) points = list(points) if len(points) > 0: # reach bigger ring selection = self.model().peakSelectionModel() ringNumbers = [p.ringNumber() for p in selection] if ringNumbers == []: lastRingNumber = 0 else: lastRingNumber = max(ringNumbers) if self._ringSelectionMode.isChecked(): ringNumber = lastRingNumber + 1 elif self._peakSelectionMode.isChecked(): ringNumber = lastRingNumber points = points[0:1] else: raise ValueError("Picking mode unknown") peakModel = self.__createNewPeak(points) peakModel.setRingNumber(ringNumber) oldState = self.__copyPeaks(self.__undoStack) self.model().peakSelectionModel().append(peakModel) newState = self.__copyPeaks(self.__undoStack) command = _PeakSelectionUndoCommand( None, self.model().peakSelectionModel(), oldState, newState) command.setText("add peak %s" % peakModel.name()) command.setRedoInhibited(True) self.__undoStack.push(command) command.setRedoInhibited(False)
def __plotClicked(self, x, y): image = self.model().experimentSettingsModel().image().value() massif = pyFAI.massif.Massif(image) points = massif.find_peaks([y, x], stdout=_DummyStdOut()) if len(points) == 0: # toleration toleration = 3 # clamp min to avoid negative values ymin = y - toleration if ymin < 0: ymin = 0 ymax = y + toleration + 1 xmin = x - toleration if xmin < 0: xmin = 0 xmax = x + toleration + 1 data = image[ymin:ymax, xmin:xmax] coord = numpy.argmax(data) coord = numpy.unravel_index(coord, data.shape) y, x = ymin + coord[0], xmin + coord[1] points = massif.find_peaks([y, x], stdout=_DummyStdOut()) # filter peaks from the mask mask = self.model().experimentSettingsModel().mask().value() if mask is not None: points = filter(lambda coord: mask[int(coord[0]), int(coord[1])] != 1, points) points = list(points) if len(points) > 0: # reach bigger ring selection = self.model().peakSelectionModel() ringNumbers = [p.ringNumber() for p in selection] if ringNumbers == []: lastRingNumber = 0 else: lastRingNumber = max(ringNumbers) if self._ringSelectionMode.isChecked(): ringNumber = lastRingNumber + 1 elif self._peakSelectionMode.isChecked(): ringNumber = lastRingNumber points = points[0:1] else: raise ValueError("Picking mode unknown") peakModel = self.__createNewPeak(points) peakModel.setRingNumber(ringNumber) oldState = self.__copyPeaks(self.__undoStack) self.model().peakSelectionModel().append(peakModel) newState = self.__copyPeaks(self.__undoStack) command = _PeakSelectionUndoCommand(None, self.model().peakSelectionModel(), oldState, newState) command.setText("add peak %s" % peakModel.name()) command.setRedoInhibited(True) self.__undoStack.push(command) command.setRedoInhibited(False)
def __plotClicked(self, x, y): image = self.model().experimentSettingsModel().image().value() massif = pyFAI.massif.Massif(image) points = massif.find_peaks([y, x], stdout=_DummyStdOut()) if len(points) == 0: # toleration toleration = 3 # clamp min to avoid negative values ymin = y - toleration if ymin < 0: ymin = 0 ymax = y + toleration + 1 xmin = x - toleration if xmin < 0: xmin = 0 xmax = x + toleration + 1 data = image[ymin:ymax, xmin:xmax] coord = numpy.argmax(data) coord = numpy.unravel_index(coord, data.shape) y, x = ymin + coord[0], xmin + coord[1] points = massif.find_peaks([y, x], stdout=_DummyStdOut()) if len(points) > 0: if self._ringSelectionMode.isChecked(): pass elif self._peakSelectionMode.isChecked(): points = points[0:1] else: raise ValueError("Picking mode unknown") peakModel = self.__createNewPeak(points) oldState = self.__copyPeaks(self.__undoStack) self.model().peakSelectionModel().append(peakModel) newState = self.__copyPeaks(self.__undoStack) command = _PeakSelectionUndoCommand(None, self.model().peakSelectionModel(), oldState, newState) command.setText("add peak %s" % peakModel.name()) command.setRedoInhibited(True) self.__undoStack.push(command) command.setRedoInhibited(False)