- Timestamp:
- May 28, 2018 8:08:36 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 3010f68
- Parents:
- c389557
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r87dfca4 r9a7c81c 400 400 self.onSelectModel() 401 401 # Smearing tab 402 self.smearing_widget.update Smearing(self.data)402 self.smearing_widget.updateData(self.data) 403 403 404 404 def acceptsData(self): … … 472 472 self.lblChi2Value.setText("---") 473 473 # Smearing tab 474 self.smearing_widget.update Smearing(self.data)474 self.smearing_widget.updateData(self.data) 475 475 # Line edits in the option tab 476 476 self.updateQRange() … … 515 515 self.communicate.customModelDirectoryChanged.connect(self.onCustomModelChange) 516 516 self.communicate.saveAnalysisSignal.connect(self.savePageState) 517 self.smearing_widget.smearingChangedSignal.connect(self.onSmearingOptionsUpdate) 517 518 #self.communicate.saveReportSignal.connect(self.saveReport) 518 519 … … 1441 1442 raise ValueError('Fitting requires at least one parameter to optimize.') 1442 1443 1443 # Potential weights added directly to data1444 self.addWeightingToData(data)1445 1446 1444 # Potential smearing added 1447 1445 # Remember that smearing_min/max can be None -> 1448 1446 # deal with it until Python gets discriminated unions 1449 s mearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state()1447 self.addWeightingToData(data) 1450 1448 1451 1449 # Get the constraints. … … 1455 1453 constraints = self.getConstraintsForFitting() 1456 1454 1457 smearer = None1455 smearer = self.smearing_widget.smearer() 1458 1456 handler = None 1459 1457 batch_inputs = {} … … 1464 1462 fitter_single = Fit() if fitter is None else fitter 1465 1463 data = GuiUtils.dataFromItem(fit_index) 1464 # Potential weights added directly to data 1465 self.addWeightingToData(data) 1466 1466 try: 1467 1467 fitter_single.set_model(model, fit_id, params_to_fit, data=data, … … 1703 1703 self.showPlot() 1704 1704 1705 def onSmearingOptionsUpdate(self): 1706 """ 1707 React to changes in the smearing widget 1708 """ 1709 self.calculateQGridForModel() 1710 1705 1711 def recalculatePlotData(self): 1706 1712 """ … … 1834 1840 # Send original data for weighting 1835 1841 weight = FittingUtilities.getWeight(data=data, is2d=self.is2D, flag=self.weighting) 1836 update_module = data.err_data if self.is2D else data.dy 1837 # Overwrite relevant values in data 1838 update_module = weight 1842 if self.is2D: 1843 data.err_data = weight 1844 else: 1845 data.dy = weight 1846 pass 1839 1847 1840 1848 def updateQRange(self): … … 1889 1897 # Change the model name to a monicker 1890 1898 self.kernel_module.name = self.modelName() 1899 # Update the smearing tab 1900 self.smearing_widget.updateKernelModel(kernel_model=self.kernel_module) 1891 1901 1892 1902 # (Re)-create headers … … 2106 2116 if completefn is None: 2107 2117 completefn = self.methodCompleteForData() 2108 2118 smearer = self.smearing_widget.smearer() 2109 2119 # Awful API to a backend method. 2110 2120 calc_thread = self.methodCalculateForData()(data=data, … … 2113 2123 qmin=self.q_range_min, 2114 2124 qmax=self.q_range_max, 2115 smearer= None,2125 smearer=smearer, 2116 2126 state=None, 2117 2127 weight=None, -
src/sas/qtgui/Perspectives/Fitting/OptionsWidget.py
r87dfca4 r9a7c81c 141 141 button_id = button.group().checkedId() 142 142 self.weighting = abs(button_id + 2) 143 #self.fitPage.weighting = button_id143 self.plot_signal.emit() 144 144 145 145 def onModelChange(self, top, bottom): -
src/sas/qtgui/Perspectives/Fitting/SmearingWidget.py
rd6b8a1d r9a7c81c 2 2 Widget/logic for smearing data. 3 3 """ 4 import copy 5 import numpy as np 4 6 from PyQt5 import QtCore 5 7 from PyQt5 import QtGui 6 8 from PyQt5 import QtWidgets 7 9 10 from sas.sascalc.fit.qsmearing import smear_selection 8 11 from sas.qtgui.Plotting.PlotterData import Data1D 9 12 from sas.qtgui.Plotting.PlotterData import Data2D … … 36 39 'PINHOLE_MAX', 37 40 'ACCURACY'] 41 ACCURACY_DICT={'Low': 'low', 42 'Medium': 'med', 43 'High': 'high', 44 'Extra high': 'xhigh'} 45 46 DEFAULT_PINHOLE_UP=0.0 47 DEFAULT_PINHOLE_DOWN=0.0 38 48 39 49 class SmearingWidget(QtWidgets.QWidget, Ui_SmearingWidgetUI): 50 smearingChangedSignal = QtCore.pyqtSignal() 40 51 def __init__(self, parent=None): 41 52 super(SmearingWidget, self).__init__() … … 43 54 self.setupUi(self) 44 55 45 # Have we loaded data yet? If so, what kind46 self.have_data = None47 56 # Local model for holding data 48 57 self.model = None 49 58 # Mapper for model update 50 59 self.mapper = None 51 52 self.parent = parent 60 # Data from the widget 61 self.data = None 62 self.current_smearer = None 63 53 64 # Let only floats in the line edits 54 65 self.txtSmearDown.setValidator(GuiUtils.DoubleValidator()) … … 58 69 self.cbSmearing.currentIndexChanged.connect(self.onIndexChange) 59 70 self.cbSmearing.setCurrentIndex(0) 71 self.txtSmearUp.setText(str(DEFAULT_PINHOLE_UP)) 72 self.txtSmearDown.setText(str(DEFAULT_PINHOLE_DOWN)) 60 73 61 74 self.initModel() … … 83 96 self.mapper.addMapping(self.txtSmearUp, MODEL.index('PINHOLE_MIN')) 84 97 self.mapper.addMapping(self.txtSmearDown, MODEL.index('PINHOLE_MAX')) 85 self.mapper.addMapping(self.cbSmearing, MODEL.index('SMEARING'))86 98 self.mapper.addMapping(self.cbAccuracy, MODEL.index('ACCURACY')) 87 99 88 # FIXME DOESNT WORK WITH QT5 89 #self.mapper.toFirst() 90 91 def updateSmearing(self, data=None): 92 """ 93 Update control elements based on data passed 100 self.mapper.toFirst() 101 102 def updateData(self, data=None): 103 """ 104 Update control elements based on data and model passed 94 105 """ 95 106 self.cbSmearing.clear() 96 107 self.cbSmearing.addItem("None") 97 self. cbAccuracy.setVisible(False)98 108 self.gAccuracy.setVisible(False) 109 self.data = data 99 110 if data is None: 100 111 self.setElementsVisibility(False) 101 112 elif isinstance(data, Data1D): 102 113 self.cbSmearing.addItems(SMEARING_1D) 103 self.have_data = Data1D104 114 else: 105 115 self.cbSmearing.addItems(SMEARING_2D) 106 self.have_data = Data2D107 116 self.cbSmearing.setCurrentIndex(0) 117 118 def updateKernelModel(self, kernel_model=None): 119 """ 120 Update the model 121 """ 122 self.kernel_model = kernel_model 123 124 def smearer(self): 125 """ Returns the current smearer """ 126 return self.current_smearer 108 127 109 128 def onIndexChange(self, index): … … 113 132 if index == 0: 114 133 self.setElementsVisibility(False) 115 return134 self.current_smearer = None 116 135 elif index == 1: 117 136 self.setElementsVisibility(True) 118 137 self.setPinholeLabels() 138 self.onPinholeSmear() 119 139 elif index == 2: 120 140 self.setElementsVisibility(True) 121 141 self.setSlitLabels() 122 123 def onModelChange(self, top, bottom): 124 """ 125 Respond to model change by updating 126 """ 127 #print "MODEL CHANGED for property: %s. The value is now: %s" % \ 128 # (MODEL[top.row()], str(self.model.item(top.row()).text())) 129 pass 142 self.onSlitSmear() 143 self.smearingChangedSignal.emit() 144 145 def onModelChange(self): 146 """ 147 Respond to model change by notifying any listeners 148 """ 149 # Recalculate the smearing 150 index = self.cbSmearing.currentIndex() 151 self.onIndexChange(index) 130 152 131 153 def setElementsVisibility(self, visible): … … 137 159 self.txtSmearDown.setVisible(visible) 138 160 self.txtSmearUp.setVisible(visible) 139 self.l abel_14.setVisible(visible)140 self.l abel_15.setVisible(visible)161 self.lblUnitUp.setVisible(visible) 162 self.lblUnitDown.setVisible(visible) 141 163 self.setAccuracyVisibility() 142 164 … … 145 167 Accuracy combobox visibility 146 168 """ 147 if self.have_data == Data2Dand self.cbSmearing.currentIndex() == 1:148 self. cbAccuracy.setVisible(True)149 else: 150 self. cbAccuracy.setVisible(False)169 if isinstance(self.data, Data2D) and self.cbSmearing.currentIndex() == 1: 170 self.gAccuracy.setVisible(True) 171 else: 172 self.gAccuracy.setVisible(False) 151 173 152 174 def setPinholeLabels(self): … … 154 176 Use pinhole labels 155 177 """ 156 self.lblSmearUp.setText('<html><head/><body><p>dQ<span style=" vertical-align:sub;">low</span></p></body></html>') 157 self.lblSmearDown.setText('<html><head/><body><p>dQ<span style=" vertical-align:sub;">high</span></p></body></html>') 178 self.txtSmearDown.setVisible(False) 179 self.lblSmearDown.setText('') 180 self.lblUnitDown.setText('') 181 if isinstance(self.data, Data2D): 182 self.lblUnitUp.setText('<html><head/><body><p>Ã 183 <span style=" vertical-align:super;">-1</span></p></body></html>') 184 self.lblSmearUp.setText('<html><head/><body><p><dQ<span style=" vertical-align:sub;">low</span>></p></body></html>') 185 else: 186 self.lblSmearUp.setText('<html><head/><body><p>dQ<span style=" vertical-align:sub;">%</span></p></body></html>') 187 self.lblUnitUp.setText('%') 158 188 159 189 def setSlitLabels(self): … … 163 193 self.lblSmearUp.setText('Slit height') 164 194 self.lblSmearDown.setText('Slit width') 195 self.lblUnitUp.setText('<html><head/><body><p>Ã 196 <span style=" vertical-align:super;">-1</span></p></body></html>') 197 self.lblUnitDown.setText('<html><head/><body><p>Ã 198 <span style=" vertical-align:super;">-1</span></p></body></html>') 165 199 166 200 def state(self): … … 168 202 Returns current state of controls 169 203 """ 170 # or model-held values 171 smearing = str(self.model.item(MODEL.index('SMEARING')).text()) 204 smearing = self.cbSmearing.currentText() 172 205 accuracy = "" 173 206 d_down = None … … 191 224 """ 192 225 # Update the model -> controls update automatically 193 if smearing is not None:194 self.model.item(MODEL.index('SMEARING')).setText(smearing)226 #if smearing is not None: 227 #self.model.item(MODEL.index('SMEARING')).setText(smearing) 195 228 if accuracy is not None: 196 229 self.model.item(MODEL.index('ACCURACY')).setText(accuracy) … … 200 233 self.model.item(MODEL.index('PINHOLE_MAX')).setText(d_up) 201 234 235 def onPinholeSmear(self): 236 """ 237 Create a custom pinhole smear object that will change the way residuals 238 are compute when fitting 239 """ 240 _, accuracy, d_percent, _ = self.state() 241 if d_percent is None or d_percent == 0.0: 242 self.current_smearer=None 243 return 244 percent = d_percent/100.0 245 # copy data 246 data = copy.deepcopy(self.data) 247 if isinstance(self.data, Data2D): 248 len_data = len(data.data) 249 data.dqx_data = np.zeros(len_data) 250 data.dqy_data = np.zeros(len_data) 251 data.dqx_data[data.dqx_data == 0] = percent * data.qx_data 252 data.dqy_data[data.dqy_data == 0] = percent * data.qy_data 253 else: 254 len_data = len(data.x) 255 data.dx = np.zeros(len_data) 256 data.dx = percent * data.x 257 data.dxl = None 258 data.dxw = None 259 260 self.current_smearer = smear_selection(data, self.kernel_model) 261 # need to set accuracy for 2D 262 if isinstance(self.data, Data2D): 263 backend_accuracy = ACCURACY_DICT.get(accuracy) 264 if backend_accuracy: 265 self.current_smearer.set_accuracy(accuracy=backend_accuracy) 266 267 def onSlitSmear(self): 268 """ 269 Create a custom slit smear object that will change the way residuals 270 are compute when fitting 271 """ 272 _, accuracy, d_height, d_width = self.state() 273 # Check changes in slit width 274 if d_width is None: 275 d_width = 0.0 276 if d_height is None: 277 d_height = 0.0 278 279 if isinstance(self.data, Data2D): 280 return 281 # make sure once more if it is smearer 282 data = copy.deepcopy(self.data) 283 data_len = len(data.x) 284 data.dx = None 285 data.dxl = None 286 data.dxw = None 287 288 try: 289 self.dxl = d_height 290 data.dxl = self.dxl * np.ones(data_len) 291 except: 292 self.dxl = None 293 data.dxl = np.zeros(data_len) 294 try: 295 self.dxw = d_width 296 data.dxw = self.dxw * np.ones(data_len) 297 except: 298 self.dxw = None 299 data.dxw = np.zeros(data_len) 300 301 self.current_smearer = smear_selection(data, self.kernel_model) -
src/sas/qtgui/Perspectives/Fitting/UI/SmearingWidgetUI.ui
re1e3e09 r9a7c81c 7 7 <x>0</x> 8 8 <y>0</y> 9 <width> 542</width>10 <height>2 70</height>9 <width>702</width> 10 <height>242</height> 11 11 </rect> 12 12 </property> … … 14 14 <string>Form</string> 15 15 </property> 16 <layout class="QGridLayout" name="gridLayout_ 2">16 <layout class="QGridLayout" name="gridLayout_4"> 17 17 <item row="0" column="0"> 18 18 <widget class="QGroupBox" name="groupBox_4"> 19 19 <property name="sizePolicy"> 20 <sizepolicy hsizetype="Preferred" vsizetype=" Minimum">20 <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> 21 21 <horstretch>0</horstretch> 22 22 <verstretch>0</verstretch> … … 26 26 <string>Instrumental Smearing</string> 27 27 </property> 28 <layout class="QGridLayout" name="gridLayout ">28 <layout class="QGridLayout" name="gridLayout_3"> 29 29 <item row="0" column="0"> 30 <widget class="QComboBox" name="cbSmearing"> 31 <property name="currentIndex"> 32 <number>0</number> 33 </property> 34 <property name="sizeAdjustPolicy"> 35 <enum>QComboBox::AdjustToContents</enum> 36 </property> 37 <item> 38 <property name="text"> 39 <string>None</string> 40 </property> 41 </item> 42 <item> 43 <property name="text"> 44 <string>Use dQ Data</string> 45 </property> 46 </item> 47 <item> 48 <property name="text"> 49 <string>Custom Pinhole Smear</string> 50 </property> 51 </item> 52 <item> 53 <property name="text"> 54 <string>Custom Slit Smear</string> 55 </property> 56 </item> 57 </widget> 58 </item> 59 <item row="0" column="1"> 60 <layout class="QGridLayout" name="gridLayout_11"> 30 <layout class="QGridLayout" name="gridLayout_2"> 61 31 <item row="0" column="0"> 62 <widget class="Q Label" name="lblSmearUp">63 <property name=" text">64 < string><html><head/><body><p>dQ<span style=" vertical-align:sub;">low</span></p></body></html></string>32 <widget class="QComboBox" name="cbSmearing"> 33 <property name="currentIndex"> 34 <number>0</number> 65 35 </property> 36 <property name="sizeAdjustPolicy"> 37 <enum>QComboBox::AdjustToContents</enum> 38 </property> 39 <item> 40 <property name="text"> 41 <string>None</string> 42 </property> 43 </item> 44 <item> 45 <property name="text"> 46 <string>Use dQ Data</string> 47 </property> 48 </item> 49 <item> 50 <property name="text"> 51 <string>Custom Pinhole Smear</string> 52 </property> 53 </item> 54 <item> 55 <property name="text"> 56 <string>Custom Slit Smear</string> 57 </property> 58 </item> 66 59 </widget> 67 60 </item> 68 <item row="0" column="1"> 69 <widget class="QLineEdit" name="txtSmearUp"/> 61 <item row="0" column="1" rowspan="2"> 62 <layout class="QGridLayout" name="gridLayout_11"> 63 <item row="0" column="0"> 64 <widget class="QLabel" name="lblSmearUp"> 65 <property name="text"> 66 <string><html><head/><body><p>dQ<span style=" vertical-align:sub;">low</span></p></body></html></string> 67 </property> 68 </widget> 69 </item> 70 <item row="0" column="1"> 71 <widget class="QLineEdit" name="txtSmearUp"/> 72 </item> 73 <item row="0" column="2"> 74 <widget class="QLabel" name="lblUnitUp"> 75 <property name="text"> 76 <string><html><head/><body><p>Ã 77 <span style=" vertical-align:super;">-1</span></p></body></html></string> 78 </property> 79 </widget> 80 </item> 81 <item row="1" column="0"> 82 <widget class="QLabel" name="lblSmearDown"> 83 <property name="text"> 84 <string><html><head/><body><p>dQ<span style=" vertical-align:sub;">high</span></p></body></html></string> 85 </property> 86 </widget> 87 </item> 88 <item row="1" column="1"> 89 <widget class="QLineEdit" name="txtSmearDown"/> 90 </item> 91 <item row="1" column="2"> 92 <widget class="QLabel" name="lblUnitDown"> 93 <property name="text"> 94 <string><html><head/><body><p>Ã 95 <span style=" vertical-align:super;">-1</span></p></body></html></string> 96 </property> 97 </widget> 98 </item> 99 </layout> 70 100 </item> 71 <item row="0" column="2"> 72 <widget class="QLabel" name="label_14"> 73 <property name="text"> 74 <string><html><head/><body><p>Ã 75 <span style=" vertical-align:super;">-1</span></p></body></html></string> 101 <item row="0" column="2" rowspan="2"> 102 <widget class="QGroupBox" name="gAccuracy"> 103 <property name="title"> 104 <string>Accuracy</string> 76 105 </property> 106 <layout class="QGridLayout" name="gridLayout"> 107 <item row="0" column="0"> 108 <widget class="QComboBox" name="cbAccuracy"> 109 <item> 110 <property name="text"> 111 <string>Low</string> 112 </property> 113 </item> 114 <item> 115 <property name="text"> 116 <string>Medium</string> 117 </property> 118 </item> 119 <item> 120 <property name="text"> 121 <string>High</string> 122 </property> 123 </item> 124 <item> 125 <property name="text"> 126 <string>Extra high</string> 127 </property> 128 </item> 129 </widget> 130 </item> 131 </layout> 77 132 </widget> 78 133 </item> 79 134 <item row="1" column="0"> 80 < widget class="QLabel" name="lblSmearDown">81 <property name=" text">82 < string><html><head/><body><p>dQ<span style=" vertical-align:sub;">high</span></p></body></html></string>135 <spacer name="verticalSpacer_2"> 136 <property name="orientation"> 137 <enum>Qt::Vertical</enum> 83 138 </property> 84 </widget> 85 </item> 86 <item row="1" column="1"> 87 <widget class="QLineEdit" name="txtSmearDown"/> 88 </item> 89 <item row="1" column="2"> 90 <widget class="QLabel" name="label_15"> 91 <property name="text"> 92 <string><html><head/><body><p>Ã 93 <span style=" vertical-align:super;">-1</span></p></body></html></string> 139 <property name="sizeHint" stdset="0"> 140 <size> 141 <width>20</width> 142 <height>18</height> 143 </size> 94 144 </property> 95 </ widget>145 </spacer> 96 146 </item> 97 147 </layout> 98 148 </item> 99 <item row="0" column="2">100 <widget class="QComboBox" name="cbAccuracy">101 <item>102 <property name="text">103 <string>Low</string>104 </property>105 </item>106 <item>107 <property name="text">108 <string>Medium</string>109 </property>110 </item>111 <item>112 <property name="text">113 <string>High</string>114 </property>115 </item>116 <item>117 <property name="text">118 <string>Extra high</string>119 </property>120 </item>121 </widget>122 </item>123 <item row="0" column="3">124 <spacer name="horizontalSpacer_2">125 <property name="orientation">126 <enum>Qt::Horizontal</enum>127 </property>128 <property name="sizeHint" stdset="0">129 <size>130 <width>71</width>131 <height>20</height>132 </size>133 </property>134 </spacer>135 </item>136 149 </layout> 137 150 </widget> 151 </item> 152 <item row="0" column="1"> 153 <spacer name="horizontalSpacer_2"> 154 <property name="orientation"> 155 <enum>Qt::Horizontal</enum> 156 </property> 157 <property name="sizeHint" stdset="0"> 158 <size> 159 <width>71</width> 160 <height>20</height> 161 </size> 162 </property> 163 </spacer> 138 164 </item> 139 165 <item row="1" column="0">
Note: See TracChangeset
for help on using the changeset viewer.