diff options
Diffstat (limited to 'silx/gui/plot/StackView.py')
-rw-r--r-- | silx/gui/plot/StackView.py | 72 |
1 files changed, 58 insertions, 14 deletions
diff --git a/silx/gui/plot/StackView.py b/silx/gui/plot/StackView.py index 1fb188c..d1e8e3c 100644 --- a/silx/gui/plot/StackView.py +++ b/silx/gui/plot/StackView.py @@ -69,16 +69,18 @@ Example:: __authors__ = ["P. Knobel", "H. Payno"] __license__ = "MIT" -__date__ = "15/02/2018" +__date__ = "26/04/2018" import numpy +import logging +import silx from silx.gui import qt from .. import icons from . import items, PlotWindow, actions -from .Colormap import Colormap -from .Colors import cursorColorForColormap -from .PlotTools import LimitsToolBar +from ..colors import Colormap +from ..colors import cursorColorForColormap +from .tools import LimitsToolBar from .Profile import Profile3DToolBar from ..widgets.FrameBrowser import HorizontalSliderWithBrowser @@ -96,6 +98,8 @@ except ImportError: else: from silx.io.utils import is_dataset +_logger = logging.getLogger(__name__) + class StackView(qt.QMainWindow): """Stack view widget, to display and browse through stack of @@ -156,6 +160,12 @@ class StackView(qt.QMainWindow): integer. """ + sigFrameChanged = qt.Signal(int) + """Signal emitter when the frame number has changed. + + This signal provides the current frame number. + """ + def __init__(self, parent=None, resetzoom=True, backend=None, autoScale=False, logScale=False, grid=False, colormap=True, aspectRatio=True, yinverted=True, @@ -206,6 +216,9 @@ class StackView(qt.QMainWindow): self.sigActiveImageChanged = self._plot.sigActiveImageChanged self.sigPlotSignal = self._plot.sigPlotSignal + if silx.config.DEFAULT_PLOT_IMAGE_Y_AXIS_ORIENTATION == 'downward': + self._plot.getYAxis().setInverted(True) + self._addColorBarAction() self._plot.profile = Profile3DToolBar(parent=self._plot, @@ -221,6 +234,7 @@ class StackView(qt.QMainWindow): self._browser_label = qt.QLabel("Image index (Dim0):") self._browser = HorizontalSliderWithBrowser(central_widget) + self._browser.setRange(0, 0) self._browser.valueChanged[int].connect(self.__updateFrameNumber) self._browser.setEnabled(False) @@ -313,7 +327,7 @@ class StackView(qt.QMainWindow): assert self._stack is not None assert 0 <= self._perspective < 3 - # ensure we have the stack encapsulated in an array like object + # ensure we have the stack encapsulated in an array-like object # having a transpose() method if isinstance(self._stack, numpy.ndarray): self.__transposed_view = self._stack @@ -324,7 +338,7 @@ class StackView(qt.QMainWindow): elif isinstance(self._stack, ListOfImages): self.__transposed_view = ListOfImages(self._stack) - # transpose the array like object if necessary + # transpose the array-like object if necessary if self._perspective == 1: self.__transposed_view = self.__transposed_view.transpose((1, 0, 2)) elif self._perspective == 2: @@ -338,13 +352,16 @@ class StackView(qt.QMainWindow): :param index: index of the frame to be displayed """ - assert self.__transposed_view is not None + if self.__transposed_view is None: + # no data set + return self._plot.addImage(self.__transposed_view[index, :, :], origin=self._getImageOrigin(), scale=self._getImageScale(), legend=self.__imageLegend, - resetzoom=False, replace=False) + resetzoom=False) self._updateTitle() + self.sigFrameChanged.emit(index) def _set3DScaleAndOrigin(self, calibrations): """Set scale and origin for all 3 axes, to be used when plotting @@ -358,7 +375,7 @@ class StackView(qt.QMainWindow): calibration.NoCalibration()) else: self.calibrations3D = [] - for calib in calibrations: + for i, calib in enumerate(calibrations): if hasattr(calib, "__len__") and len(calib) == 2: calib = calibration.LinearCalibration(calib[0], calib[1]) elif calib is None: @@ -367,9 +384,19 @@ class StackView(qt.QMainWindow): raise TypeError("calibration must be a 2-tuple, None or" + " an instance of an AbstractCalibration " + "subclass") + elif not calib.is_affine(): + _logger.warning( + "Calibration for dimension %d is not linear, " + "it will be ignored for scaling the graph axes.", + i) self.calibrations3D.append(calib) def _getXYZCalibs(self): + """Return calibrations sorted in the XYZ graph order. + + If the X or Y calibration is not linear, it will be replaced + with a :class:`calibration.NoCalibration` object + and as a result the corresponding axis will not be scaled.""" xy_dims = [0, 1, 2] xy_dims.remove(self._perspective) @@ -377,6 +404,12 @@ class StackView(qt.QMainWindow): ycalib = self.calibrations3D[min(xy_dims)] zcalib = self.calibrations3D[self._perspective] + # filter out non-linear calibration for graph axes + if not xcalib.is_affine(): + xcalib = calibration.NoCalibration() + if not ycalib.is_affine(): + ycalib = calibration.NoCalibration() + return xcalib, ycalib, zcalib def _getImageScale(self): @@ -469,6 +502,7 @@ class StackView(qt.QMainWindow): colormap=self.getColormap(), origin=self._getImageOrigin(), scale=self._getImageScale(), + replace=True, resetzoom=False) self._plot.setActiveImage(self.__imageLegend) self._plot.setGraphTitle("Image z=%g" % self._getImageZ(0)) @@ -586,6 +620,14 @@ class StackView(qt.QMainWindow): """ self._browser.setValue(number) + def getFrameNumber(self): + """Set the frame selection to a specific value + + :return: Index of currently displayed frame + :rtype: int + """ + return self._browser.value() + def setFirstStackDimension(self, first_stack_dimension): """When viewing the last 3 dimensions of an n-D array (n>3), you can use this method to change the text in the combobox. @@ -641,6 +683,8 @@ class StackView(qt.QMainWindow): self.__transposed_view = None self._perspective = 0 self._browser.setEnabled(False) + # reset browser range + self._browser.setRange(0, 0) self._plot.clear() def setLabels(self, labels=None): @@ -1101,17 +1145,17 @@ class StackViewMainWindow(StackView): self.statusBar() menu = self.menuBar().addMenu('File') - menu.addAction(self._plot.saveAction) - menu.addAction(self._plot.printAction) + menu.addAction(self._plot.getOutputToolBar().getSaveAction()) + menu.addAction(self._plot.getOutputToolBar().getPrintAction()) menu.addSeparator() action = menu.addAction('Quit') action.triggered[bool].connect(qt.QApplication.instance().quit) menu = self.menuBar().addMenu('Edit') - menu.addAction(self._plot.copyAction) + menu.addAction(self._plot.getOutputToolBar().getCopyAction()) menu.addSeparator() - menu.addAction(self._plot.resetZoomAction) - menu.addAction(self._plot.colormapAction) + menu.addAction(self._plot.getResetZoomAction()) + menu.addAction(self._plot.getColormapAction()) menu.addAction(self.getColorBarAction()) menu.addAction(actions.control.KeepAspectRatioAction(self._plot, self)) |