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

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 50bfab0 was 7c487846, checked in by Piotr Rozyczko <rozyczko@…>, 7 years ago

Fixes to the Invariant perspective

  • Property mode set to 100755
File size: 7.0 KB
RevLine 
[f721030]1import sys
2import os
[4992ff2]3from PyQt5 import QtCore
[f1f3e6a]4from PyQt5 import QtGui, QtWidgets
[f721030]5
6# local
[b3e8629]7from .UI.InvariantDetailsUI import Ui_Dialog
8from .InvariantUtils import WIDGETS
[f721030]9
[f1f3e6a]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
[4992ff2]14class DetailsDialog(QtWidgets.QDialog, Ui_Dialog):
[f721030]15    """
[f1f3e6a]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.
[f721030]19    """
20    def __init__(self, parent):
[83eb5208]21        super(DetailsDialog, self).__init__(parent)
22
[60af928]23        self.setupUi(self)
[f721030]24
[f1f3e6a]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)
[f721030]44
[f1f3e6a]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)
[f721030]56
[f1f3e6a]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
[f721030]70
71    def setModel(self, model):
[f1f3e6a]72        """ """
[f721030]73        self._model = model
74
75    def showDialog(self):
[f1f3e6a]76        """ Fill the dialog with values of calculated Q, progress bars"""
[f721030]77        # Pull out data from the model
[f1f3e6a]78        self.qstar_total = float(self._model.item(WIDGETS.W_INVARIANT).text())
[f721030]79
[f1f3e6a]80        self.txtQData.setText(str(self.qstar_total))
81        self.txtQDataErr.setText(self._model.item(WIDGETS.W_INVARIANT_ERR).text())
[f721030]82
[7c487846]83        # Reset progress counters
84        self.progress_low_qstar = 0.0
85        self.progress_high_qstar = 0.0
86        self.progress_qstar = 100.0
87
[f1f3e6a]88        # Low-Q
[f721030]89        if self._model.item(WIDGETS.W_ENABLE_LOWQ).text() == "true":
[f1f3e6a]90            self.qlow = float(self._model.item(WIDGETS.D_LOW_QSTAR).text())
[f721030]91
[f1f3e6a]92            self.txtQLowQ.setText(str(self.qlow))
93            self.txtQLowQErr.setText(self._model.item(WIDGETS.D_LOW_QSTAR_ERR).text())
94            try:
95                self.progress_low_qstar = (self.qlow/self.qstar_total)*100.0
96            except:
97                self.progress_low_qstar = 'error'
[f721030]98
[f1f3e6a]99        # High-Q
100        if self._model.item(WIDGETS.W_ENABLE_HIGHQ).text() == "true":
101            self.qhigh = float(self._model.item(WIDGETS.D_HIGH_QSTAR).text())
102
103            self.txtQHighQ.setText(str(self.qhigh))
104            self.txtQHighQErr.setText(self._model.item(WIDGETS.D_HIGH_QSTAR_ERR).text())
105            try:
106                self.progress_high_qstar = (self.qhigh/self.qstar_total)*100.0
107            except:
108                self.progress_high_qstar = 'error'
109
110        try:
111            self.progress_qstar -= self.progress_low_qstar + self.progress_high_qstar
112        except:
113            self.progress_qstar = 'error'
114
115        # check values and display warning
116        if self.checkValues():
117            self.lblWarning.setText(self.checkValues())
118
119        # update progress bars
120        if self.progress_low_qstar == 'error':
121            self.progressBarLowQ.setValue(0)
122        else:
123            self.progressBarLowQ.setValue(self.progress_low_qstar)
124
125        if self.progress_high_qstar == 'error':
126            self.progressBarHighQ.setValue(0)
127        else:
128            self.progressBarHighQ.setValue(self.progress_high_qstar)
129
130        if self.progress_qstar == 'error':
131            self.progressBarData.setValue(0)
132        else:
133            self.progressBarData.setValue(self.progress_qstar)
[f721030]134
[f1f3e6a]135        self.show()
[457d961]136
[f1f3e6a]137    def checkValues(self):
138        """
139        Create a warning message to be displayed in panel
140        if problems with values
141        """
[f721030]142
[f1f3e6a]143        if self.qstar_total is None:
144            warning_msg = "Invariant not calculated.\n"
145            return warning_msg
146        elif self.qstar_total == 0:
147            warning_msg = "Invariant is zero. \n " \
148                          "The calculations are likely to be unreliable!\n"
149            return warning_msg
150
151        msg = ''
152        if self.progress_qstar == 'error':
153            msg += 'Error occurred when computing invariant from data.\n '
[7c487846]154        try:
155            if float(self.progress_qstar) > 100:
156                msg += "Invariant Q contribution is greater than 100% .\n"
157        except ValueError:
158            # Text message, skip msg update
159            pass
[f1f3e6a]160
161        if self.progress_low_qstar == 'error':
162            try:
163                float(self.qlow)
164            except:
165                msg += "Error occurred when computing extrapolated invariant"
166                msg += " at low-Q region.\n"
167
168        elif self.progress_low_qstar is not None:
169            if self.progress_low_qstar >= 5:
170                msg += "Extrapolated contribution at Low Q is higher "
171                msg += "than 5% of the invariant.\n"
172            elif self.progress_low_qstar < 0:
173                msg += "Extrapolated contribution at Low Q < 0.\n"
174            elif self.progress_low_qstar > 100:
175                msg += "Extrapolated contribution at Low Q is greater "
176                msg += "than 100% .\n"
177
178        # High-Q
179        if self.progress_high_qstar == 'error':
180            try:
181                float(self.qhigh)
182            except:
183                msg += 'Error occurred when computing extrapolated'
184                msg += ' invariant at high-Q region.\n'
185
186        elif self.progress_high_qstar is not None:
187            if self.progress_high_qstar >= 5:
188                msg += "Extrapolated contribution at High Q is higher " \
189                       "than 5% of the invariant.\n"
190            elif self.progress_high_qstar < 0:
191
192                msg += "Extrapolated contribution at High Q < 0.\n"
193            elif self.progress_high_qstar > 100:
194
195                msg += "Extrapolated contribution at High Q is greater " \
196                       "than 100% .\n"
197
198        if (self.progress_low_qstar not in [None, "error"]) and \
199            (self.progress_high_qstar not in [None, "error"])\
200            and self.progress_low_qstar + self.progress_high_qstar >= 5:
201
202            msg += "The sum of all extrapolated contributions is higher " \
203                   "than 5% of the invariant.\n"
204
205        return msg
Note: See TracBrowser for help on using the repository browser.