diff options
Diffstat (limited to 'silx/gui/plot/StackView.py')
-rw-r--r-- | silx/gui/plot/StackView.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/silx/gui/plot/StackView.py b/silx/gui/plot/StackView.py index 2a3d7e8..7e4c389 100644 --- a/silx/gui/plot/StackView.py +++ b/silx/gui/plot/StackView.py @@ -85,6 +85,8 @@ from .Profile import Profile3DToolBar from ..widgets.FrameBrowser import HorizontalSliderWithBrowser from silx.gui.plot.actions import control as actions_control +from silx.gui.plot.actions import io as silx_io +from silx.io.nxdata import save_NXdata from silx.utils.array_like import DatasetView, ListOfImages from silx.math import calibration from silx.utils.deprecation import deprecated_warning @@ -160,6 +162,9 @@ class StackView(qt.QMainWindow): This signal provides the current frame number. """ + IMAGE_STACK_FILTER_NXDATA = 'Stack of images as NXdata (%s)' % silx_io._NEXUS_HDF5_EXT_STR + + def __init__(self, parent=None, resetzoom=True, backend=None, autoScale=False, logScale=False, grid=False, colormap=True, aspectRatio=True, yinverted=True, @@ -226,6 +231,7 @@ class StackView(qt.QMainWindow): self._plot.getXAxis().setLabel('Columns') self._plot.getYAxis().setLabel('Rows') self._plot.sigPlotSignal.connect(self._plotCallback) + self._plot.getSaveAction().setFileFilter('image', self.IMAGE_STACK_FILTER_NXDATA, func=self._saveImageStack, appendToFile=True) self.__planeSelection = PlanesWidget(self._plot) self.__planeSelection.sigPlaneSelectionChanged.connect(self.setPerspective) @@ -253,6 +259,25 @@ class StackView(qt.QMainWindow): self.__planeSelection.sigPlaneSelectionChanged.connect( self._plot.profile.clearProfile) + def _saveImageStack(self, plot, filename, nameFilter): + """Save all images from the stack into a volume. + + :param str filename: The name of the file to write + :param str nameFilter: The selected name filter + :return: False if format is not supported or save failed, + True otherwise. + :raises: ValueError if nameFilter is invalid + """ + if not nameFilter == self.IMAGE_STACK_FILTER_NXDATA: + raise ValueError('Wrong callback') + entryPath = silx_io.SaveAction._selectWriteableOutputGroup(filename, parent=self) + if entryPath is None: + return False + return save_NXdata(filename, + nxentry_name=entryPath, + signal=self.getStack(copy=False, returnNumpyArray=True)[0], + signal_name="image_stack") + def _addColorBarAction(self): self._plot.getColorBarWidget().setVisible(True) actions = self._plot.toolBar().actions() @@ -517,7 +542,12 @@ class StackView(qt.QMainWindow): # This call to setColormap redefines the meaning of autoscale # for 3D volume: take global min/max rather than frame min/max if self.__autoscaleCmap: - self.setColormap(autoscale=True) + # note: there is no real autoscale in the stack widget, it is more + # like a hack computing stack min and max + colormap = self.getColormap() + _vmin, _vmax = colormap.getColormapRange(data=self._stack) + colormap.setVRange(_vmin, _vmax) + self.setColormap(colormap=colormap) # init plot self._plot.addImage(self.__transposed_view[0, :, :], |