Skip to content

Commit

Permalink
Merge pull request #1590 from SasView/ESS_GUI_1574_Invariant
Browse files Browse the repository at this point in the history
Ess gui 1574 invariant
  • Loading branch information
Wojciech Potrzebowski committed Jul 6, 2020
2 parents 222b136 + 4240977 commit f20e736
Show file tree
Hide file tree
Showing 21 changed files with 2,012 additions and 1,077 deletions.
43 changes: 29 additions & 14 deletions src/sas/qtgui/Perspectives/Invariant/InvariantDetails.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ def __init__(self, parent):

# invariant total
self.qstar_total = None
self.qdata = None
self.qhigh = None
self.qlow = None
self._model = None

self.progress_low_qstar = 0.0
self.progress_high_qstar = 0.0
self.progress_qstar = 100.0
self.progress_data_qstar = 100.0

def setModel(self, model):
""" """
Expand All @@ -77,13 +78,29 @@ def showDialog(self):
# Pull out data from the model
self.qstar_total = float(self._model.item(WIDGETS.W_INVARIANT).text())

self.txtQData.setText(str(self.qstar_total))
self.txtQDataErr.setText(self._model.item(WIDGETS.W_INVARIANT_ERR).text())

# Reset progress counters
self.progress_low_qstar = 0.0
self.progress_high_qstar = 0.0
self.progress_qstar = 100.0
self.progress_data_qstar = 100.0

# Reset numerical values
self.txtQData.setText(None)
self.txtQDataErr.setText(None)
self.txtQLowQ.setText(None)
self.txtQLowQErr.setText(None)
self.txtQHighQ.setText(None)
self.txtQHighQErr.setText(None)


# Q* from data
self.qdata = float(self._model.item(WIDGETS.D_DATA_QSTAR).text())

self.txtQData.setText(str(self.qdata))
self.txtQDataErr.setText(self._model.item(WIDGETS.D_DATA_QSTAR_ERR).text())
try:
self.progress_data_qstar = (self.qdata/self.qstar_total)*100.0
except:
self.progress_data_qstar = 'error'

# Low-Q
if self._model.item(WIDGETS.W_ENABLE_LOWQ).text() == "true":
Expand All @@ -107,11 +124,6 @@ def showDialog(self):
except:
self.progress_high_qstar = 'error'

try:
self.progress_qstar -= self.progress_low_qstar + self.progress_high_qstar
except:
self.progress_qstar = 'error'

# check values and display warning
if self.checkValues():
self.lblWarning.setText(self.checkValues())
Expand All @@ -127,10 +139,10 @@ def showDialog(self):
else:
self.progressBarHighQ.setValue(self.progress_high_qstar)

if self.progress_qstar == 'error':
if self.progress_data_qstar == 'error':
self.progressBarData.setValue(0)
else:
self.progressBarData.setValue(self.progress_qstar)
self.progressBarData.setValue(self.progress_data_qstar)

self.show()

Expand All @@ -149,10 +161,10 @@ def checkValues(self):
return warning_msg

msg = ''
if self.progress_qstar == 'error':
if self.progress_data_qstar == 'error':
msg += 'Error occurred when computing invariant from data.\n '
try:
if float(self.progress_qstar) > 100:
if float(self.progress_data_qstar) > 100:
msg += "Invariant Q contribution is greater than 100% .\n"
except ValueError:
# Text message, skip msg update
Expand Down Expand Up @@ -202,4 +214,7 @@ def checkValues(self):
msg += "The sum of all extrapolated contributions is higher " \
"than 5% of the invariant.\n"

if msg == '':
msg = "No Warnings to report\n"

return msg
27 changes: 16 additions & 11 deletions src/sas/qtgui/Perspectives/Invariant/InvariantPerspective.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# global
import sys
import os
import logging
import copy
import webbrowser
import numpy as np

from PyQt5 import QtCore
from PyQt5 import QtGui, QtWidgets
Expand All @@ -16,8 +14,6 @@
from sas.qtgui.Plotting.PlotterData import Data1D
import sas.qtgui.Utilities.GuiUtils as GuiUtils

# import sas.qtgui.Plotting.PlotHelper as PlotHelper

# local
from .UI.TabbedInvariantUI import Ui_tabbedInvariantUI
from .InvariantDetails import DetailsDialog
Expand Down Expand Up @@ -53,7 +49,7 @@ def __init__(self, parent=None):
# initial input params
self._background = 0.0
self._scale = 1.0
self._contrast = 1.0
self._contrast = 8.0e-6
self._porod = None

self.parent = parent
Expand Down Expand Up @@ -222,7 +218,6 @@ def plotResult(self, model):
# Set the button back to available
self.cmdCalculate.setEnabled(True)
self.cmdCalculate.setText("Calculate")
self.cmdStatus.setEnabled(True)

self.model = model
self.mapper.toFirst()
Expand Down Expand Up @@ -256,6 +251,8 @@ def calculateThread(self, extrapolation):
self.updateFromModel()
msg = ''

qstar_data = 0.0
qstar_data_err = 0.0
qstar_low = 0.0
qstar_low_err = 0.0
qstar_high = 0.0
Expand Down Expand Up @@ -292,7 +289,7 @@ def calculateThread(self, extrapolation):
calculation_failed = False

try:
qstar_total, qstar_total_error = inv.get_qstar_with_error()
qstar_data, qstar_data_err = inv.get_qstar_with_error()
except Exception as ex:
msg += str(ex)
calculation_failed = True
Expand All @@ -301,11 +298,10 @@ def calculateThread(self, extrapolation):
self.model.setItem(WIDGETS.W_INVARIANT, item)
item = QtGui.QStandardItem("ERROR")
self.model.setItem(WIDGETS.W_INVARIANT_ERR, item)

try:
volume_fraction, volume_fraction_error = \
inv.get_volume_fraction_with_error(self._contrast)

inv.get_volume_fraction_with_error(self._contrast,
extrapolation=extrapolation)
except Exception as ex:
calculation_failed = True
msg += str(ex)
Expand All @@ -331,8 +327,10 @@ def calculateThread(self, extrapolation):
surface = None

if (calculation_failed):
self.cmdStatus.setEnabled(False)
logging.warning('Calculation failed: {}'.format(msg))
return self.model
self.cmdStatus.setEnabled(True)

low_calculation_pass = True
high_calculation_pass = True
Expand Down Expand Up @@ -416,8 +414,15 @@ def calculateThread(self, extrapolation):
reactor.callFromThread(self.updateModelFromThread, WIDGETS.W_SPECIFIC_SURFACE_ERR,
surface_error)

qstar_total = qstar_data + qstar_low + qstar_high
qstar_total_error = np.sqrt(
qstar_data_err * qstar_data_err
+ qstar_low_err * qstar_low_err + qstar_high_err * qstar_high_err)

reactor.callFromThread(self.updateModelFromThread, WIDGETS.W_INVARIANT, qstar_total)
reactor.callFromThread(self.updateModelFromThread, WIDGETS.W_INVARIANT_ERR, qstar_total_error)
reactor.callFromThread(self.updateModelFromThread, WIDGETS.D_DATA_QSTAR, qstar_data)
reactor.callFromThread(self.updateModelFromThread, WIDGETS.D_DATA_QSTAR_ERR, qstar_data_err)
reactor.callFromThread(self.updateModelFromThread, WIDGETS.D_LOW_QSTAR, qstar_low)
reactor.callFromThread(self.updateModelFromThread, WIDGETS.D_LOW_QSTAR_ERR, qstar_low_err)
reactor.callFromThread(self.updateModelFromThread, WIDGETS.D_HIGH_QSTAR, qstar_high)
Expand Down
4 changes: 2 additions & 2 deletions src/sas/qtgui/Perspectives/Invariant/InvariantUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
'W_INVARIANT',
'W_INVARIANT_ERR',
# for the details widget
'D_TOTAL_QSTAR',
'D_TOTAL_QSTAR_ERR',
'D_DATA_QSTAR',
'D_DATA_QSTAR_ERR',
'D_LOW_QSTAR',
'D_LOW_QSTAR_ERR',
'D_HIGH_QSTAR',
Expand Down
18 changes: 18 additions & 0 deletions src/sas/qtgui/Perspectives/Invariant/UI/InvariantDetailsUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@
<property name="toolTip">
<string>Extrapolated invariant from low-Q range.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="2">
Expand All @@ -103,6 +106,9 @@
<property name="toolTip">
<string>Uncertainty on the invariant from low-Q range.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="4">
Expand All @@ -124,6 +130,9 @@
<property name="toolTip">
<string>Invariant in the data set's Q range.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
Expand All @@ -138,6 +147,9 @@
<property name="toolTip">
<string>Uncertainty on the invariant from data's range.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="4">
Expand All @@ -159,6 +171,9 @@
<property name="toolTip">
<string>Extrapolated invariant from high-Q range.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
Expand All @@ -173,6 +188,9 @@
<property name="toolTip">
<string>Uncertainty on the invariant from high-Q range.</string>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="4">
Expand Down
10 changes: 8 additions & 2 deletions src/sas/qtgui/Perspectives/Invariant/UI/TabbedInvariantUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>473</height>
<width>544</width>
<height>489</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -143,6 +143,9 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand All @@ -157,6 +160,9 @@
<property name="enabled">
<bool>true</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def testDefaults(self):
self.assertEqual(self.widget.txtTotalQMax.text(), '0.0')
self.assertEqual(self.widget.txtBackgd.text(), '0.0')
self.assertEqual(self.widget.txtScale.text(), '1.0')
self.assertEqual(self.widget.txtContrast.text(), '1.0')
self.assertEqual(self.widget.txtContrast.text(), '8e-06')
self.assertEqual(self.widget.txtExtrapolQMin.text(), '1e-05')
self.assertEqual(self.widget.txtExtrapolQMax.text(), '10')
self.assertEqual(self.widget.txtPowerLowQ.text(), '4')
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f20e736

Please sign in to comment.