Commit 65c5bfdc authored by Carsten Richter's avatar Carsten Richter

Merge branch 'qspace-view-histo' into 'master'

Add a plot of a histogram of the QSpace values in QSpaceView

Closes #50

See merge request !108
parents a4b26cf4 45be90ac
Pipeline #6974 passed with stages
in 4 minutes and 15 seconds
......@@ -36,7 +36,7 @@ import numpy as np
from silx.utils.weakref import WeakMethodProxy
from silx.gui import qt as Qt
from silx.gui.plot import actions, PlotToolButtons, PlotWidget
from silx.gui.plot import actions, items, PlotToolButtons, PlotWidget
from silx.gui.icons import getQIcon
from silx.gui.plot.StackView import StackView
from silx.math.combo import min_max
......@@ -247,6 +247,63 @@ class CutPlanePlotWindow(PlotWidget):
return Qt.QSize(200, 200)
class _QSpaceHistogram(PlotWidget):
"""Display histogram of QSpace data
:param parent: See QWiget
"""
def __init__(self, parent=None):
super(_QSpaceHistogram, self).__init__(parent=parent)
self.setMinimumSize(150, 150)
# Create toolbar
toolbar = Qt.QToolBar('Cut Plane Plot', self)
self.addToolBar(toolbar)
for action in (
actions.control.ResetZoomAction(parent=self, plot=self),
actions.control.YAxisLogarithmicAction(parent=self, plot=self)):
toolbar.addAction(action)
toolbar.addSeparator()
for action in (
actions.io.CopyAction(parent=self, plot=self),
actions.io.SaveAction(parent=self, plot=self),
actions.io.PrintAction(parent=self, plot=self)):
toolbar.addAction(action)
self.setKeepDataAspectRatio(False)
self.setActiveCurveHandling(False)
self.setDataMargins(yMinMargin=0.05, yMaxMargin=0.05)
self.getXAxis().setScale(items.Axis.LOGARITHMIC)
def setData(self, data):
"""Set data from which to compute the histogram
:param numpy.ndarray data:
"""
self.clear()
if data is not None:
data = data[data > 0]
result = min_max(data, min_positive=True, finite=True)
if result.min_positive is None:
return # No strictly positive finite data
edges = np.logspace(
np.log10(result.min_positive), np.log10(result.maximum), 128)
hist, edges = np.histogram(data, bins=edges)
self.addHistogram(hist, edges,
legend='QSpace Histogram',
color='blue',
fill=True,
copy=False)
def sizeHint(self):
return Qt.QSize(200, 200)
class QSpaceView(Qt.QMainWindow):
"""Window displaying the 3D Q space isosurfaces.
......@@ -288,6 +345,9 @@ class QSpaceView(Qt.QMainWindow):
self.__roiPlotWindow.setPointSelectionEnabled(True)
self.__roiPlotWindow.sigPointSelected.connect(self.__pointSelected)
self.__plotHistogram = _QSpaceHistogram(parent=self)
self.__plotHistogram.setToolTip('Histogram of QSpace values')
with self.__projectItem.qspaceH5 as qspaceH5:
sampleX = qspaceH5.sample_x
sampleY = qspaceH5.sample_y
......@@ -378,22 +438,22 @@ class QSpaceView(Qt.QMainWindow):
fitDock.setFeatures(features)
self.addDockWidget(Qt.Qt.RightDockWidgetArea, fitDock)
roiPlotDock = Qt.QDockWidget('ROI Intensity', self)
roiPlotDock.setWidget(self.__roiPlotWindow)
features = roiPlotDock.features() ^ Qt.QDockWidget.DockWidgetClosable
roiPlotDock.setFeatures(features)
if self.__view3d is not None:
self.tabifyDockWidget(planePlotDock, roiPlotDock)
else:
self.addDockWidget(Qt.Qt.LeftDockWidgetArea, roiPlotDock)
self.__lockWidgets.append(roiPlotDock)
plotDock = Qt.QDockWidget('Intensity', self)
plotDock.setWidget(self.__plotWindow)
features = plotDock.features() ^ Qt.QDockWidget.DockWidgetClosable
plotDock.setFeatures(features)
self.tabifyDockWidget(roiPlotDock, plotDock)
self.__lockWidgets.append(plotDock)
# Add Plots to tabbed dock widgets
previousDock = None if self.__view3d is None else planePlotDock
for title, widget in (('Histogram', self.__plotHistogram),
('ROI Intensity', self.__roiPlotWindow),
('Intensity', self.__plotWindow)):
dock = Qt.QDockWidget(title, self)
dock.setWidget(widget)
features = dock.features() ^ Qt.QDockWidget.DockWidgetClosable
dock.setFeatures(features)
self.__lockWidgets.append(dock)
if previousDock is None:
self.addDockWidget(Qt.Qt.LeftDockWidgetArea, dock)
else:
self.tabifyDockWidget(previousDock, dock)
previousDock = dock
self.__showIsoView(firstX, firstY)
......@@ -514,8 +574,8 @@ class QSpaceView(Qt.QMainWindow):
# For spherical, swap from (pitch, roll, radial) to (radial, roll, pitch).
qspace = qspace.swapaxes(0, 2)
for widget, label in zip(self.__fitWidget.roiWidget().roiAxisWidgets(),
axisNames):
for widget, label in zip(
self.__fitWidget.roiWidget().roiAxisWidgets(), axisNames):
widget.setText(label)
if self.__view3d is not None:
......@@ -546,6 +606,8 @@ class QSpaceView(Qt.QMainWindow):
if not wasStack:
self.__stackView.resetZoom()
self.__plotHistogram.setData(qspace)
# Update sliders histograms
self.__fitWidget.setQSpaceIndex(idx)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment