source: sasview/src/sas/qtgui/Perspectives/Invariant/InvariantDetails.py @ f1f3e6a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalc
Last change on this file since f1f3e6a was f1f3e6a, checked in by Piotr Rozyczko <rozyczko@…>, 6 years ago

Initial commit of Celine's Invariant Perspective work SASVIEW-52

  • Property mode set to 100755
File size: 6.7 KB
Line 
1import sys
2import os
3from PyQt5 import QtCore
4from PyQt5 import QtGui, QtWidgets
5
6# local
7from .UI.InvariantDetailsUI import Ui_Dialog
8from .InvariantUtils import WIDGETS
9
10# ERROR_COLOR = wx.Colour(255, 0, 0, 128)
11# EXTRAPOLATION_COLOR = wx.Colour(169, 169, 168, 128)
12# INVARIANT_COLOR = wx.Colour(67, 208, 128, 128)
13
14class DetailsDialog(QtWidgets.QDialog, Ui_Dialog):
15    """
16    This class stores some values resulting from invariant calculations.
17    Given the value of total invariant, this class can also
18    determine the percentage of invariants resulting from extrapolation.
19    """
20    def __init__(self, parent):
21        super(DetailsDialog, self).__init__(parent)
22
23        self.setupUi(self)
24
25        DEFAULT_STYLE = """
26        QProgressBar{
27            border: 2px solid grey;
28            border-radius: 5px;
29            text-align: center
30        }
31
32        QProgressBar::chunk {
33            background-color: #b1daf9;
34            width: 10px;
35            margin: 1px;
36        }
37        """
38        self.progressBarLowQ.setStyleSheet(DEFAULT_STYLE)
39        self.progressBarData.setStyleSheet(DEFAULT_STYLE)
40        self.progressBarHighQ.setStyleSheet(DEFAULT_STYLE)
41
42        self.progressBarLowQ.setMinimum(0)
43        self.progressBarLowQ.setMaximum(100)
44
45        self.progressBarData.setMinimum(0)
46        self.progressBarData.setMaximum(100)
47
48        self.progressBarHighQ.setMinimum(0)
49        self.progressBarHighQ.setMaximum(100)
50
51        # Modify font in order to display Angstrom symbol correctly
52        new_font = 'font-family: -apple-system, "Helvetica Neue", "Ubuntu";'
53        self.lblQLowQUnits.setStyleSheet(new_font)
54        self.lblQDataUnits.setStyleSheet(new_font)
55        self.lblQHighQUnits.setStyleSheet(new_font)
56
57        self.cmdOK.clicked.connect(self.accept)
58
59        self.warning_msg = "No Details on calculations available...\n"
60
61        # invariant total
62        self.qstar_total = None
63        self.qhigh = None
64        self.qlow = None
65        self._model = None
66
67        self.progress_low_qstar = 0.0
68        self.progress_high_qstar = 0.0
69        self.progress_qstar = 100.0
70
71    def setModel(self, model):
72        """ """
73        self._model = model
74
75    def showDialog(self):
76        """ Fill the dialog with values of calculated Q, progress bars"""
77        # Pull out data from the model
78        self.qstar_total = float(self._model.item(WIDGETS.W_INVARIANT).text())
79
80        self.txtQData.setText(str(self.qstar_total))
81        self.txtQDataErr.setText(self._model.item(WIDGETS.W_INVARIANT_ERR).text())
82
83        # Low-Q
84        if self._model.item(WIDGETS.W_ENABLE_LOWQ).text() == "true":
85            self.qlow = float(self._model.item(WIDGETS.D_LOW_QSTAR).text())
86
87            self.txtQLowQ.setText(str(self.qlow))
88            self.txtQLowQErr.setText(self._model.item(WIDGETS.D_LOW_QSTAR_ERR).text())
89            try:
90                self.progress_low_qstar = (self.qlow/self.qstar_total)*100.0
91            except:
92                self.progress_low_qstar = 'error'
93
94        # High-Q
95        if self._model.item(WIDGETS.W_ENABLE_HIGHQ).text() == "true":
96            self.qhigh = float(self._model.item(WIDGETS.D_HIGH_QSTAR).text())
97
98            self.txtQHighQ.setText(str(self.qhigh))
99            self.txtQHighQErr.setText(self._model.item(WIDGETS.D_HIGH_QSTAR_ERR).text())
100            try:
101                self.progress_high_qstar = (self.qhigh/self.qstar_total)*100.0
102            except:
103                self.progress_high_qstar = 'error'
104
105        try:
106            self.progress_qstar -= self.progress_low_qstar + self.progress_high_qstar
107        except:
108            self.progress_qstar = 'error'
109
110        # check values and display warning
111        if self.checkValues():
112            self.lblWarning.setText(self.checkValues())
113
114        # update progress bars
115        if self.progress_low_qstar == 'error':
116            self.progressBarLowQ.setValue(0)
117        else:
118            self.progressBarLowQ.setValue(self.progress_low_qstar)
119
120        if self.progress_high_qstar == 'error':
121            self.progressBarHighQ.setValue(0)
122        else:
123            self.progressBarHighQ.setValue(self.progress_high_qstar)
124
125        if self.progress_qstar == 'error':
126            self.progressBarData.setValue(0)
127        else:
128            self.progressBarData.setValue(self.progress_qstar)
129
130        self.show()
131
132    def checkValues(self):
133        """
134        Create a warning message to be displayed in panel
135        if problems with values
136        """
137
138        if self.qstar_total is None:
139            warning_msg = "Invariant not calculated.\n"
140            return warning_msg
141        elif self.qstar_total == 0:
142            warning_msg = "Invariant is zero. \n " \
143                          "The calculations are likely to be unreliable!\n"
144            return warning_msg
145
146        msg = ''
147        if self.progress_qstar == 'error':
148            msg += 'Error occurred when computing invariant from data.\n '
149        if self.progress_qstar > 100:
150            msg += "Invariant Q contribution is greater than 100% .\n"
151
152        if self.progress_low_qstar == 'error':
153            try:
154                float(self.qlow)
155            except:
156                msg += "Error occurred when computing extrapolated invariant"
157                msg += " at low-Q region.\n"
158
159        elif self.progress_low_qstar is not None:
160            if self.progress_low_qstar >= 5:
161                msg += "Extrapolated contribution at Low Q is higher "
162                msg += "than 5% of the invariant.\n"
163            elif self.progress_low_qstar < 0:
164                msg += "Extrapolated contribution at Low Q < 0.\n"
165            elif self.progress_low_qstar > 100:
166                msg += "Extrapolated contribution at Low Q is greater "
167                msg += "than 100% .\n"
168
169        # High-Q
170        if self.progress_high_qstar == 'error':
171            try:
172                float(self.qhigh)
173            except:
174                msg += 'Error occurred when computing extrapolated'
175                msg += ' invariant at high-Q region.\n'
176
177        elif self.progress_high_qstar is not None:
178            if self.progress_high_qstar >= 5:
179                msg += "Extrapolated contribution at High Q is higher " \
180                       "than 5% of the invariant.\n"
181            elif self.progress_high_qstar < 0:
182
183                msg += "Extrapolated contribution at High Q < 0.\n"
184            elif self.progress_high_qstar > 100:
185
186                msg += "Extrapolated contribution at High Q is greater " \
187                       "than 100% .\n"
188
189        if (self.progress_low_qstar not in [None, "error"]) and \
190            (self.progress_high_qstar not in [None, "error"])\
191            and self.progress_low_qstar + self.progress_high_qstar >= 5:
192
193            msg += "The sum of all extrapolated contributions is higher " \
194                   "than 5% of the invariant.\n"
195
196        return msg
Note: See TracBrowser for help on using the repository browser.