rsmWidget.py 3.7 KB
Newer Older
Julia Garriga Ferrer's avatar
Julia Garriga Ferrer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/


__authors__ = ["J. Garriga"]
__license__ = "MIT"
29
__date__ = "16/07/2021"
30
31


Julia Garriga Ferrer's avatar
Julia Garriga Ferrer committed
32
from silx.gui import qt
33
from silx.utils.enum import Enum as _Enum
Julia Garriga Ferrer's avatar
Julia Garriga Ferrer committed
34
35


36
37
38
39
40
41
42
43
class PixelSize(_Enum):
    """
    Different pixel sizes
    """
    Basler = 0.051
    PcoEdge_2x = 0.00375
    PcoEdge_10x = 0.00075

44

Julia Garriga Ferrer's avatar
Julia Garriga Ferrer committed
45
46
class RSMWidget(qt.QMainWindow):
    """
47
    Widget to compute Reciprocal Space Map
Julia Garriga Ferrer's avatar
Julia Garriga Ferrer committed
48
49
50
51
52
53
    """
    sigComputed = qt.Signal()

    def __init__(self, parent=None):
        qt.QWidget.__init__(self, parent)

54
        self._rotate = False
55
        self._moments = None
56
        self._pixelSize = None
57
58

        widget = qt.QWidget()
59
        layout = qt.QGridLayout()
60

61
62
63
        pixelSizeLabel = qt.QLabel("Pixel size: ")
        self._pixelSizeCB = qt.QComboBox()
        self._pixelSizeCB.addItems(PixelSize.names())
64
        self._rotateCB = qt.QCheckBox("Rotate RSM", self)
65
66
67
        self._okButton = qt.QPushButton("Ok")
        self._okButton.setEnabled(False)
        self._okButton.pressed.connect(self._saveRSM)
68
69
        layout.addWidget(pixelSizeLabel, 0, 0)
        layout.addWidget(self._pixelSizeCB, 0, 1)
70
71
        layout.addWidget(self._rotateCB, 1, 1)
        layout.addWidget(self._okButton, 2, 0, 1, 2)
72
73
        widget.setLayout(layout)
        self.setCentralWidget(widget)
Julia Garriga Ferrer's avatar
Julia Garriga Ferrer committed
74
75
76
77
78
79
80
81
82
83
84

    def setDataset(self, dataset, indices=None, bg_indices=None, bg_dataset=None):
        """
        Dataset setter.

        :param Dataset dataset: dataset
        """
        self.dataset = dataset
        self.indices = indices
        self.bg_indices = bg_indices
        self.bg_dataset = bg_dataset
85
86
87
88
89
        self._okButton.setEnabled(True)

    def getDataset(self):
        return self.dataset, self.indices, self.bg_indices, self.bg_dataset

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
    @property
    def pixelSize(self):
        return self._pixelSize

    @pixelSize.setter
    def pixelSize(self, pixelSize):
        self._pixelSize = pixelSize
        self._pixelSizeCB.setCurrentText(str(pixelSize))

    @property
    def rotate(self):
        return self._rotate

    @rotate.setter
    def rotate(self, rotate):
        self._rotate = rotate
        self._rotateCB.setChecked(rotate)

108
    def _saveRSM(self):
109
110
111
        self._pixelSize = self._pixelSizeCB.currentText()
        self._rotate = self._rotateCB.isChecked()
        self.dataset.compute_transformation(PixelSize[self._pixelSize].value,
112
113
                                            kind="rsm",
                                            rotate=self._rotate)
114
        self.sigComputed.emit()