Commit 31386782 authored by Julia Garriga Ferrer's avatar Julia Garriga Ferrer
Browse files

[gui][rsm] Add center values checkbox

parent cf49b212
......@@ -33,14 +33,25 @@ 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):
"""
Different pixel sizes
"""
Basler = 0.051
PcoEdge_2x = 0.00375
PcoEdge_10x = 0.00075
class RSMWidget(qt.QMainWindow):
"""
Widget to apply PCA to a set of images and plot the eigenvalues found.
Widget to compute Reciprocal Space Map
"""
sigComputed = qt.Signal()
......@@ -48,17 +59,28 @@ class RSMWidget(qt.QMainWindow):
qt.QWidget.__init__(self, parent)
self._rotate = False
self._moments = None
widget = qt.QWidget()
layout = qt.QVBoxLayout()
layout = qt.QGridLayout()
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)
layout.addWidget(self._plotWidget)
layout.addWidget(self._rotateCB)
self._centerDataCheckbox = qt.QCheckBox("Center angle values")
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)
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):
"""
......@@ -74,28 +96,37 @@ class RSMWidget(qt.QMainWindow):
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
ffz = self.dataset.get_metadata_values(POSITIONER_METADATA, "ffz")
mainx = -self.dataset.get_metadata_values(POSITIONER_METADATA, "mainx")
d = 0.051
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(ffz - d * h / 2, mainx)
teta_max = (180 / numpy.pi) * numpy.arctan2(ffz + d * h / 2, mainx)
az_min = -(180 / numpy.pi) * numpy.arctan2(d * w / 2, numpy.sqrt(ffz * ffz + mainx * mainx))
az_max = (180 / numpy.pi) * numpy.arctan2(d * w / 2, numpy.sqrt(ffz * ffz + mainx * mainx))
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
self._plotWidget.addImage(self._moments[0][0], ylabel="2 theta", xlabel="Azimuth",
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))
else:
print("\nComputation aborted")
def __rotate(self, checked):
self._rotate = checked
self.addRSM()
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