Changeset 0c468bf in sasview
- Timestamp:
- Oct 19, 2017 7:55:59 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, 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:
- 1420066
- Parents:
- f0bb711
- Location:
- src/sas/qtgui/Calculators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/DataOperationUtilityPanel.py
rf0bb711 r0c468bf 126 126 def onCompute(self): 127 127 """ perform calculation """ 128 # check compatibility of datasets before calculation 129 if self.onCheckChosenData(): 130 # set operator to be applied 131 operator = self.cbOperator.currentText() 132 # calculate and send data to DataExplorer 133 output = None 134 try: 135 data1 = self.data1 136 data2 = self.data2 137 exec "output = data1 %s data2" % operator 138 except: 139 raise 140 141 self.output = output 142 143 # if outputname was unused, write output result to it 144 # and display plot 145 if self.onCheckOutputName(): 146 # add outputname to self.filenames 147 self.list_data_items.append(str(self.txtOutputData.text())) 148 # send result to DataExplorer 149 self.onPrepareOutputData() 150 # plot result 151 self.updatePlot(self.graphOutput, self.layoutOutput, self.output) 128 # set operator to be applied 129 operator = self.cbOperator.currentText() 130 # calculate and send data to DataExplorer 131 output = None 132 try: 133 data1 = self.data1 134 data2 = self.data2 135 exec "output = data1 %s data2" % operator 136 except: 137 raise 138 139 self.output = output 140 141 # if outputname was unused, write output result to it 142 # and display plot 143 if self.onCheckOutputName(): 144 # add outputname to self.filenames 145 self.list_data_items.append(str(self.txtOutputData.text())) 146 # send result to DataExplorer 147 self.onPrepareOutputData() 148 # plot result 149 self.updatePlot(self.graphOutput, self.layoutOutput, self.output) 152 150 153 151 def onPrepareOutputData(self): … … 207 205 self.data1 = None 208 206 self.data1OK = False 209 self.cmdCompute.setEnabled(False) 210 self.onCheckChosenData() 207 self.cmdCompute.setEnabled(False) # self.onCheckChosenData()) 211 208 return 212 209 213 210 else: 214 # Enable Compute button only if Data2 is defined215 self.cmdCompute.setEnabled(self.data2OK)216 211 self.data1OK = True 217 self.onCheckChosenData()218 212 # get Data1 219 213 key_id1 = self._findId(choice_data1) … … 223 217 # plot default for output graph 224 218 self.newPlot(self.graphOutput, self.layoutOutput) 225 219 # Enable Compute button only if Data2 is defined and data compatible 220 self.cmdCompute.setEnabled(self.onCheckChosenData()) 226 221 227 222 def onSelectData2(self): … … 235 230 self.data2OK = False 236 231 self.onCheckChosenData() 232 self.cmdCompute.setEnabled(False) 237 233 return 238 234 … … 242 238 self.data2 = float(self.txtNumber.text()) 243 239 244 # Enable Compute button only if Data1 is defined245 self.cmdCompute.setEnabled(self. data1OK)240 # Enable Compute button only if Data1 defined and compatible data 241 self.cmdCompute.setEnabled(self.onCheckChosenData()) 246 242 # Display value of coefficient in graphData2 247 243 self.updatePlot(self.graphData2, self.layoutData2, self.data2) … … 251 247 252 248 else: 253 self. cmdCompute.setEnabled(self.data1OK)249 self.txtNumber.setEnabled(False) 254 250 self.data2OK = True 255 self.txtNumber.setEnabled(False)256 251 key_id2 = self._findId(choice_data2) 257 252 self.data2 = self._extractData(key_id2) 253 self.cmdCompute.setEnabled(self.onCheckChosenData()) 254 258 255 # plot Data2 259 256 self.updatePlot(self.graphData2, self.layoutData2, self.data2) 260 257 # plot default for output graph 261 258 self.newPlot(self.graphOutput, self.layoutOutput) 262 self.onCheckChosenData()263 259 264 260 def onInputCoefficient(self): … … 285 281 286 282 def onCheckChosenData(self): 287 """ Before running compute, check that data1 and 2 are compatible """ 288 289 if self.cbData2.currentText() == 'Number': 290 self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 291 self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 292 return True 293 294 elif self.data1.__class__.__name__ != self.data2.__class__.__name__: 295 self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 296 self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 297 logging.info('Cannot compute data of different dimensions') 283 """ check that data1 and data2 are compatible """ 284 285 if not all([self.data1OK, self.data2OK]): 298 286 return False 299 300 elif self.data1.__class__.__name__ == 'Data1D'\301 and (len(self.data2.x) != len(self.data1.x) or302 not all(i == j for i, j in zip(self.data1.x, self.data2.x))):303 logging.info('Cannot compute 1D data of different lengths')304 self.cbData1.setStyleSheet(QtCore.QString(BG_RED))305 self.cbData2.setStyleSheet(QtCore.QString(BG_RED))306 return False307 308 elif self.data1.__class__.__name__ == 'Data2D' \309 and (len(self.data2.qx_data) != len(self.data1.qx_data) \310 or len(self.data2.qy_data) != len(self.data1.qy_data)311 or not all(i == j for i, j in312 zip(self.data1.qx_data, self.data2.qx_data))313 or not all(i == j for i, j in314 zip(self.data1.qy_data, self.data2.qy_data))315 ):316 self.cbData1.setStyleSheet(QtCore.QString(BG_RED))317 self.cbData2.setStyleSheet(QtCore.QString(BG_RED))318 logging.info('Cannot compute 2D data of different lengths')319 return False320 321 287 else: 322 self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 323 self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 324 return True 288 if self.cbData2.currentText() == 'Number': 289 self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 290 self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 291 return True 292 293 elif self.data1.__class__.__name__ != self.data2.__class__.__name__: 294 self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 295 self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 296 print self.data1.__class__.__name__ != self.data2.__class__.__name__ 297 logging.info('Cannot compute data of different dimensions') 298 return False 299 300 elif self.data1.__class__.__name__ == 'Data1D'\ 301 and (len(self.data2.x) != len(self.data1.x) or 302 not all(i == j for i, j in zip(self.data1.x, self.data2.x))): 303 logging.info('Cannot compute 1D data of different lengths') 304 self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 305 self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 306 return False 307 308 elif self.data1.__class__.__name__ == 'Data2D' \ 309 and (len(self.data2.qx_data) != len(self.data1.qx_data) \ 310 or len(self.data2.qy_data) != len(self.data1.qy_data) 311 or not all(i == j for i, j in 312 zip(self.data1.qx_data, self.data2.qx_data)) 313 or not all(i == j for i, j in 314 zip(self.data1.qy_data, self.data2.qy_data)) 315 ): 316 self.cbData1.setStyleSheet(QtCore.QString(BG_RED)) 317 self.cbData2.setStyleSheet(QtCore.QString(BG_RED)) 318 logging.info('Cannot compute 2D data of different lengths') 319 return False 320 321 else: 322 self.cbData1.setStyleSheet(QtCore.QString(BG_WHITE)) 323 self.cbData2.setStyleSheet(QtCore.QString(BG_WHITE)) 324 return True 325 325 326 326 def onCheckOutputName(self): -
src/sas/qtgui/Calculators/UnitTesting/DataOperationUtilityTest.py
rd5c5d3d r0c468bf 135 135 136 136 137 # @patch('DataOperationUtilityPanel.')138 137 def testOnCompute(self): 139 138 """ Test onCompute function """ … … 163 162 164 163 self.assertTrue(self.widget.onPrepareOutputData.called_once()) 165 166 # GuiManager.updateModelFromDataOperationPanel167 164 168 165 def testOnSelectData1(self): … … 283 280 def testCheckChosenData(self): 284 281 """ Test check of data compatibility """ 282 # set the 2 following to True since we want to check 283 # the compatibility of dimensions 284 self.widget.data1OK = True 285 self.widget.data2OK = True 286 285 287 # Case 1: incompatible dimensions 286 288 self.widget.data1 = Data1D(x=[1.0, 2.0, 3.0], y=[11.0, 12.0, 13.0],
Note: See TracChangeset
for help on using the changeset viewer.