Commit 7a87dc71 authored by Thomas Vincent's avatar Thomas Vincent

Ad option to change displayed data (except in Points view)

parent 6de26540
......@@ -60,6 +60,9 @@ class ShiftSubject(Qt.QObject):
Value passed : an instance of ShiftValue.
"""
sigDataChanged = Qt.Signal()
"""Signal emitted when the displayed data has changed"""
def __init__(self,
iGroup,
shiftItem,
......@@ -69,6 +72,7 @@ class ShiftSubject(Qt.QObject):
self.__iGroup = iGroup
self.__shiftItem = shiftItem
self.__roi = None
self.__displayedDataName = None
self.__xsocsH5 = iGroup.xsocsH5
entries = self.__xsocsH5.entries()
......@@ -111,6 +115,22 @@ class ShiftSubject(Qt.QObject):
dy,
gridShift)
def displayedDataName(self):
"""Returns the name of the data to display or None for intensity
:rtype: Union[str,None]
"""
return self.__displayedDataName
def setDisplayedDataName(self, name):
"""Set the data to display
:param Union[str,None] name:
"""
if name != self.__displayedDataName:
self.__displayedDataName = name
self.sigDataChanged.emit()
def scanShift(self):
"""Returns this ShiftSubject's instance of ScanShift
......@@ -373,11 +393,16 @@ class ShiftSubject(Qt.QObject):
:rtype: PlotData
"""
iItem = self.__iGroup.getIntensityItem(entry)
intensity, positions = iItem.getScatterData()
data, positions = iItem.getScatterData()
if self.displayedDataName() is not None:
# Read data from measurements
data = self.xsocsH5().measurement(
entry=entry, measurement=self.displayedDataName())
return PlotData(x=positions.pos_0,
y=positions.pos_1,
z=intensity,
z=data,
idx=None)
def getRoiData(self, entry, shifted=True, centered=False):
......@@ -396,20 +421,19 @@ class ShiftSubject(Qt.QObject):
if roi is None:
return None
iItem = self.__iGroup.getIntensityItem(entry)
intensity, positions = iItem.getScatterData()
fullData = self.getFullData(entry)
pos_0 = fullData.x
pos_1 = fullData.y
data = fullData.z
if shifted:
shift = self.getShift(entry)
roi += np.array([shift.dx, shift.dx, shift.dy, shift.dy])
pos_0 = positions.pos_0
pos_1 = positions.pos_1
dataIdx = np.where((pos_0 >= roi[0]) & (pos_0 <= roi[1]) &
(pos_1 >= roi[2]) & (pos_1 <= roi[3]))
data = intensity[dataIdx]
data = data[dataIdx]
pos_0 = pos_0[dataIdx]
pos_1 = pos_1[dataIdx]
......
......@@ -138,7 +138,8 @@ class ShiftNode(Node):
if column == ModelColumns.ValueColumn:
return [self.subject.sigRoiChanged,
self.subject.sigReferenceControlPointChanged,
self.subject.sigShiftChanged]
self.subject.sigShiftChanged,
self.subject.sigDataChanged]
return []
def filterEvent(self, column, event):
......@@ -223,6 +224,7 @@ class ShiftSelectorPanel(Qt.QWidget):
shiftSubject.sigRoiChanged.connect(self.__slotSubjectChanged)
shiftSubject.sigReferenceControlPointChanged.connect(
self.__slotSubjectChanged)
shiftSubject.sigDataChanged.connect(self.__slotSubjectChanged)
self.__refreshBn.clicked.connect(self.__slotRefreshClicked)
......@@ -514,6 +516,13 @@ class ShiftAreaSelectorWidget(Qt.QWidget):
self.__plotWid.comboBox().setCurrentIndex(0)
self.__plotWid.comboBox().currentIndexChanged.emit(0)
def shiftPlotWidget(self):
"""Returns ShiftPlotWidget used within this widget
:rtype: ShiftPlotWidget
"""
return self.__plotWid
def __slotSelectionChanged(self, node):
"""
Slot Called when the selection changes in the ShitPlotWidget combobox.
......@@ -699,6 +708,8 @@ class ShiftWidget(Qt.QMainWindow):
layout = Qt.QVBoxLayout(refSubGroup)
layout.addWidget(self.__refPanel)
self.__refPanel.plot().setPointSelectionEnabled(True)
self.__shiftSubject.sigDataChanged.connect(
self.__refPanel.refreshPlotData)
# "Set" panel
self.__setPanel = ShiftPlotWidget(treeView.model(),
......@@ -707,6 +718,8 @@ class ShiftWidget(Qt.QMainWindow):
showSelection=True)
self.__setPanel.setSnapToPoint(True)
self.__setPanel.plot().setPointSelectionEnabled(True)
self.__shiftSubject.sigDataChanged.connect(
self.__setPanel.refreshPlotData)
self.__linearShiftBn = Qt.QPushButton('Apply linear shift')
self.__linearShiftWholeRangeBn = Qt.QPushButton('Apply linear shift on whole range')
......@@ -731,8 +744,26 @@ class ShiftWidget(Qt.QMainWindow):
# ROI panel
self.__areaPlot = ShiftAreaSelectorWidget(
treeView.model(), treeView.rootIndex())
roiSubGroup = GroupBox('Area selection')
self.__shiftSubject.sigDataChanged.connect(
self.__areaPlot.shiftPlotWidget().refreshPlotData)
roiSubGroup = GroupBox('Selection')
layout = Qt.QVBoxLayout(roiSubGroup)
# Select displayed value
dataComboBox = Qt.QComboBox()
dataComboBox.setToolTip('Select displayed data')
dataComboBox.addItem('Intensity')
for name in self.__shiftSubject.xsocsH5().normalizers():
dataComboBox.addItem(name)
dataComboBox.currentIndexChanged.connect(self.__dataChanged)
dataSelectLayout = Qt.QHBoxLayout()
dataSelectLayout.addStretch(1)
dataSelectLayout.addWidget(Qt.QLabel('Displayed data:'))
dataSelectLayout.addWidget(dataComboBox)
dataSelectLayout.addStretch(1)
layout.addLayout(dataSelectLayout)
layout.addWidget(self.__areaPlot)
# X and Y shift plot
......@@ -760,10 +791,8 @@ class ShiftWidget(Qt.QMainWindow):
buttonsLayout.addWidget(self.__saveProgBar)
centralLayout.addWidget(roiSubGroup, 0, 0, 4, 1)
# centralLayout.addWidget(optionsSubGroup, 0, 1)
centralLayout.addWidget(refSubGroup, 0, 1)
centralLayout.addWidget(setSubGroup, 1, 1)
# centralLayout.addWidget(tabWidget, 0, 2, 3, 1)
centralLayout.addWidget(shiftSubGroup, 2, 1)
centralLayout.addLayout(buttonsLayout, 3, 1, Qt.Qt.AlignLeft)
......@@ -804,6 +833,19 @@ class ShiftWidget(Qt.QMainWindow):
"""Returns the ShiftModel"""
return self.__selector.treeView().model()
def __dataChanged(self, index):
"""Handle change of data in data QComboBox
:param int index:
"""
if index == 0:
name = None # To select intensity
else:
comboBox = self.sender()
name = comboBox.currentText()
self.__shiftSubject.setDisplayedDataName(name)
def __slotAccepted(self):
"""Slot called when the "save" button is clicked"""
self.__shiftSubject.writeToShiftH5(
......
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