def setPosition(self, pos): """Set the position of this ROI :param numpy.ndarray pos: 2d-coordinate of this point """ self.__position = pos with utils.blockSignals(self.__handle): self.__handle.setPosition(*pos) with utils.blockSignals(self.__handleLabel): self.__handleLabel.setPosition(*pos) self.sigRegionChanged.emit()
def __axisNameChanged(self, axis, name): """Called when an axis name change. :param _Axis axis: The changed axis :param str name: The new name of the axis """ names = [x.axisName() for x in self.__axis] missingName = set(self.__axisNames) - set(names) - set("") if len(missingName) == 0: missingName = None elif len(missingName) == 1: missingName = list(missingName)[0] else: raise Exception("Unexpected state") axisChanged = True if axis.axisName() == "": # set the removed label to another widget if it is possible availableWidget = None for widget in self.__axis: if widget is axis: continue if widget.axisName() == "": availableWidget = widget break if availableWidget is None: # If there is no other solution we set the name at the same place axisChanged = False availableWidget = axis with blockSignals(availableWidget): availableWidget.setAxisName(missingName) else: # there is a duplicated name somewhere # we swap it with the missing name or with nothing dupWidget = None for widget in self.__axis: if widget is axis: continue if widget.axisName() == axis.axisName(): dupWidget = widget break if missingName is None: missingName = "" with blockSignals(dupWidget): dupWidget.setAxisName(missingName) if self.__data is None: return if axisChanged: self.selectedAxisChanged.emit() self.__updateSelectedData()
def setAxisNames(self, axesNames): """Set the axis names of the output selected data. Axis names are defined from slower to faster axis. The size of the list will constrain the dimension of the resulting array. :param List[str] axesNames: List of distinct strings identifying axis names """ self.__axisNames = list(axesNames) assert len(set(self.__axisNames)) == len(self.__axisNames),\ "Non-unique axes names: %s" % self.__axisNames delta = len(self.__axis) - len(self.__axisNames) if delta < 0: delta = 0 for index, axis in enumerate(self.__axis): with blockSignals(axis): axis.setAxisNames(self.__axisNames) if index >= delta and index - delta < len(self.__axisNames): axis.setAxisName(self.__axisNames[index - delta]) else: axis.setAxisName("") self.__updateSelectedData()
def setAxisNames(self, axesNames): """Set the available list of names for the axis. :param List[str] axesNames: List of available names """ self.__axes.clear() with blockSignals(self.__axes): self.__axes.addItem(" ", "") for axis in axesNames: self.__axes.addItem(axis, axis) self.__updateSliderVisibility()
def __updateNumpySelectionAxis(self): """ Update the numpy-selector according to the needed axis names """ with blockSignals(self.__numpySelection): previousPermutation = self.__numpySelection.permutation() previousSelection = self.__numpySelection.selection() self.__numpySelection.clear() info = self._getInfo() axisNames = self.__currentView.axesNames(self.__data, info) if (info.isArray and info.size != 0 and self.__data is not None and axisNames is not None): self.__useAxisSelection = True self.__numpySelection.setAxisNames(axisNames) self.__numpySelection.setCustomAxis( self.__currentView.customAxisNames()) data = self.normalizeData(self.__data) self.__numpySelection.setData(data) # Try to restore previous permutation and selection try: self.__numpySelection.setSelection(previousSelection, previousPermutation) except ValueError as e: _logger.info("Not restoring selection because: %s", e) if hasattr(data, "shape"): isVisible = not (len(axisNames) == 1 and len(data.shape) == 1) else: isVisible = True self.__axisSelection.setVisible(isVisible) else: self.__useAxisSelection = False self.__axisSelection.setVisible(False)
def setEditorData(self, roi): with blockSignals(self._nPoints): self._nPoints.setValue(roi.getNPoints())
def setEditorData(self, roi): super(_DefaultImageStackProfileRoiEditor, self).setEditorData(roi) with blockSignals(self._profileDim): kind = roi.getProfileType() dim = {"1D": 1, "2D": 2}[kind] self._profileDim.setDimension(dim)
def setSelection(self, selection, permutation=None): """Set the selection along each dimension. tuple returned by :meth:`selection` can be provided as input, provided that it is for the same the number of axes and the same number of dimensions of the data. :param List[Union[int,slice,None]] selection: The selection tuple with as one element for each dimension of the data. If an element is None, then the whole dimension is selected. :param Union[List[int],None] permutation: The data axes indices to transpose. If not given, no permutation is applied :raise ValueError: When the selection does not match current data shape and number of axes. """ data_shape = self.__data.shape if self.__data is not None else () # Check selection if len(selection) != len(data_shape): raise ValueError( "Selection length (%d) and data ndim (%d) mismatch" % (len(selection), len(data_shape))) # Check selection type selectedDataNDim = 0 for element, size in zip(selection, data_shape): if isinstance(element, int): if not 0 <= element < size: raise ValueError( "Selected index (%d) outside data dimension range [0-%d]" % (element, size)) elif element is None or element == slice(None): selectedDataNDim += 1 else: raise ValueError("Unsupported element in selection: %s" % element) ndim = len(self.__axisNames) if selectedDataNDim != ndim: raise ValueError( "Selection dimensions (%d) and number of axes (%d) mismatch" % (selectedDataNDim, ndim)) # check permutation if permutation is None: permutation = tuple(range(ndim)) if set(permutation) != set(range(ndim)): raise ValueError( "Error in provided permutation: " "Wrong size, elements out of range or duplicates") inversePermutation = numpy.argsort(permutation) axisNameChanged = False customValueChanged = [] with blockSignals(*self.__axis): index = 0 for element, axis in zip(selection, self.__axis): if isinstance(element, int): name = "" else: name = self.__axisNames[inversePermutation[index]] index += 1 if axis.axisName() != name: axis.setAxisName(name) axisNameChanged = True for element, axis in zip(selection, self.__axis): value = element if isinstance(element, int) else 0 if axis.value() != value: axis.setValue(value) name = axis.axisName() if name in self.__customAxisNames: customValueChanged.append((name, value)) # Send signals that where disabled if axisNameChanged: self.selectedAxisChanged.emit() for name, value in customValueChanged: self.customAxisChanged.emit(name, value) self.__updateSelectedData()