Commit 2462b59a authored by Thomas Vincent's avatar Thomas Vincent

Update fitwidget to use new range slider and to select bin edges rather

than centers
parent 0549d273
......@@ -30,6 +30,7 @@ __license__ = "MIT"
__date__ = "15/09/2016"
from collections import OrderedDict
import logging
import numpy as np
from matplotlib import cm
......@@ -45,6 +46,9 @@ from ..widgets.Input import StyledLineEdit
from ...process.fit.peak_fit import PeakFitter, FitTypes
_logger = logging.getLogger(__name__)
class Roi3DSelectorWidget(Qt.QWidget):
"""
Widget displaying three RoiAxisWidgets, one for each axis.
......@@ -96,15 +100,15 @@ class Roi3DSelectorWidget(Qt.QWidget):
sender = self.sender()
if sender == self.__xRoiWid:
xState = sliderEvt
yState = self.__yRoiWid.slider().getSliderState()
zState = self.__zRoiWid.slider().getSliderState()
yState = self.__yRoiWid.getSliderState()
zState = self.__zRoiWid.getSliderState()
elif sender == self.__yRoiWid:
xState = self.__xRoiWid.slider().getSliderState()
xState = self.__xRoiWid.getSliderState()
yState = sliderEvt
zState = self.__zRoiWid.slider().getSliderState()
zState = self.__zRoiWid.getSliderState()
elif sender == self.__zRoiWid:
xState = self.__xRoiWid.slider().getSliderState()
yState = self.__yRoiWid.slider().getSliderState()
xState = self.__xRoiWid.getSliderState()
yState = self.__yRoiWid.getSliderState()
zState = sliderEvt
elif sender == self.__grpBox:
return
......@@ -235,9 +239,25 @@ class FitWidget(Qt.QWidget):
qy = qspaceH5.qy
qz = qspaceH5.qz
roiWidget.xSlider().setRange([qx[0], qx[-1]])
roiWidget.ySlider().setRange([qy[0], qy[-1]])
roiWidget.zSlider().setRange([qz[0], qz[-1]])
qxMin, qxMax = np.min(qx), np.max(qx)
qyMin, qyMax = np.min(qy), np.max(qy)
qzMin, qzMax = np.min(qz), np.max(qz)
qxScale = (qxMax - qxMin) / (len(qx) - 1)
qyScale = (qyMax - qyMin) / (len(qy) - 1)
qzScale = (qzMax - qzMin) / (len(qz) - 1)
self.roiWidget().xSlider().setNumberOfSteps(len(qx) + 1)
self.roiWidget().xSlider().setRange(qxMin - qxScale/2.,
qxMax + qxScale/2.)
self.roiWidget().ySlider().setNumberOfSteps(len(qy) + 1)
self.roiWidget().ySlider().setRange(qyMin - qyScale/2.,
qyMax + qyScale/2.)
self.roiWidget().zSlider().setNumberOfSteps(len(qz) + 1)
self.roiWidget().zSlider().setRange(qzMin - qzScale/2.,
qzMax + qzScale/2.)
self.__sigFitDone.connect(self.__slotFitDone)
......@@ -265,13 +285,10 @@ class FitWidget(Qt.QWidget):
y_sum = cube_sum_z.sum(axis=0)
x_sum = cube_sum_z.sum(axis=1)
colors = cm.jet(np.arange(255))
cmap = [Qt.QColor.fromRgbF(*c).rgba() for c in colors]
roiWidget = self.__roiWidget
roiWidget.xSlider().setSliderProfile(x_sum, colormap=cmap)
roiWidget.ySlider().setSliderProfile(y_sum, colormap=cmap)
roiWidget.zSlider().setSliderProfile(z_sum, colormap=cmap)
for profile, slider in ((x_sum, self.roiWidget().xSlider()),
(y_sum, self.roiWidget().ySlider()),
(z_sum, self.roiWidget().zSlider())):
slider.setGroovePixmapFromProfile(profile, colormap='jet')
def setOutputFile(self, outputFile):
self.__outputFile = outputFile
......@@ -322,11 +339,18 @@ class FitWidget(Qt.QWidget):
self.__progBar.setValue(0)
fitType = FitWidget.FitTypes[self.__fitTypeCb.currentText()]
if self.__roiWidget.isActive():
x0, x1 = self.__roiWidget.xSlider().getSliderIndices()
y0, y1 = self.__roiWidget.ySlider().getSliderIndices()
z0, z1 = self.__roiWidget.zSlider().getSliderIndices()
roiIndices = [[x0, x1 + 1], [y0, y1 + 1], [z0, z1 + 1]]
if self.roiWidget().isActive():
x0, x1 = self.roiWidget().xSlider().getPositions()
y0, y1 = self.roiWidget().ySlider().getPositions()
z0, z1 = self.roiWidget().zSlider().getPositions()
if x0 == x1 or y0 == y1 or z0 == z1:
message = "QSpace ROI is void: cannot perform fit"
_logger.error(message)
Qt.QMessageBox.critical(self, "QSpace ROI Error", message)
self.__lock(False)
return
roiIndices = [[x0, x1], [y0, y1], [z0, z1]]
else:
roiIndices = None
......
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