Commit 82718d99 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[gui][rsm] Use widget to only obtain the transformation parameters

parent 439687ad
......@@ -26,20 +26,12 @@
__authors__ = ["J. Garriga"]
__license__ = "MIT"
__date__ = "01/06/2021"
__date__ = "04/06/2021"
import numpy
from silx.gui import qt
from silx.gui.plot import Plot2D
from silx.gui.colors import Colormap
from silx.utils.enum import Enum as _Enum
import darfix
from .operationThread import OperationThread
from darfix.core.dimension import POSITIONER_METADATA
class PixelSize(_Enum):
"""
......@@ -49,6 +41,7 @@ class PixelSize(_Enum):
PcoEdge_2x = 0.00375
PcoEdge_10x = 0.00075
class RSMWidget(qt.QMainWindow):
"""
Widget to compute Reciprocal Space Map
......@@ -67,20 +60,16 @@ class RSMWidget(qt.QMainWindow):
pixelSizeLabel = qt.QLabel("Pixel size: ")
self._pixelSizeCB = qt.QComboBox()
self._pixelSizeCB.addItems(PixelSize.names())
self._plotWidget = Plot2D()
self._plotWidget.setDefaultColormap(Colormap(name=darfix.config.DEFAULT_COLORMAP_NAME))
self._rotateCB = qt.QCheckBox("Rotate RSM", self)
self._centerDataCheckbox = qt.QCheckBox("Center angle values")
self._okButton = qt.QPushButton("Ok")
self._okButton.setEnabled(False)
self._okButton.pressed.connect(self._saveRSM)
layout.addWidget(pixelSizeLabel, 0, 0)
layout.addWidget(self._pixelSizeCB, 0, 1)
layout.addWidget(self._plotWidget, 1, 0, 1, 3)
layout.addWidget(self._rotateCB, 0, 2)
layout.addWidget(self._centerDataCheckbox, 2, 2)
layout.addWidget(self._okButton, 1, 0, 1, 2)
widget.setLayout(layout)
self.setCentralWidget(widget)
self._rotateCB.stateChanged.connect(self.__rotate)
self._pixelSizeCB.currentTextChanged.connect(self.addRSM)
self._centerDataCheckbox.stateChanged.connect(self.addRSM)
def setDataset(self, dataset, indices=None, bg_indices=None, bg_dataset=None):
"""
......@@ -92,41 +81,12 @@ class RSMWidget(qt.QMainWindow):
self.indices = indices
self.bg_indices = bg_indices
self.bg_dataset = bg_dataset
self._thread = OperationThread(self, self.dataset.apply_moments)
self._thread.setArgs(self.indices)
self._thread.finished.connect(self._updateData)
self._thread.start()
self.ffz = self.dataset.get_metadata_values(POSITIONER_METADATA, "ffz")
self.mainx = -self.dataset.get_metadata_values(POSITIONER_METADATA, "mainx")
def _updateData(self):
self._thread.finished.disconnect(self._updateData)
if self._thread.data is not None:
self._moments = self._thread.data
self.addRSM()
else:
print("\nComputation aborted")
def addRSM(self):
d = PixelSize[self._pixelSizeCB.currentText()].value
if self._moments is not None:
s, h, w = self.dataset.get_data().shape
X = numpy.arange(-int(h / 2), int(h / 2), dtype=numpy.float64) * d
Y = numpy.arange(-(w / 2), w / 2, dtype=numpy.float64) * d
teta_min = (180 / numpy.pi) * numpy.arctan2(self.ffz - d * h / 2, self.mainx)
teta_max = (180 / numpy.pi) * numpy.arctan2(self.ffz + d * h / 2, self.mainx)
sqrt = numpy.sqrt(self.ffz * self.ffz + self.mainx * self.mainx)
az_min = -(180 / numpy.pi) * numpy.arctan2(d * w / 2, sqrt)
az_max = (180 / numpy.pi) * numpy.arctan2(d * w / 2, sqrt)
xscale = (teta_max - teta_min) / h
yscale = (az_max - az_min) / w
com = (self._moments[0][0] - (numpy.min(self._moments[0][0]) + numpy.ptp(self._moments[0][0]) / 2)
if self._centerDataCheckbox.isChecked() else self._moments[0][0])
com = com.T if self._rotate else com
self._plotWidget.addImage(com, ylabel="2 theta", xlabel="Azimuth",
origin=(az_min, teta_min), scale=(yscale, xscale))
def __rotate(self, checked):
self._rotate = checked
self.addRSM()
self._okButton.setEnabled(True)
def getDataset(self):
return self.dataset, self.indices, self.bg_indices, self.bg_dataset
def _saveRSM(self):
self.dataset.compute_transformation(PixelSize[self._pixelSizeCB.currentText()].value,
self._rotateCB.isChecked())
self.sigComputed.emit()
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