Changeset 672b8ab in sasview for src/sas/qtgui/Perspectives/Fitting
- Timestamp:
- May 10, 2017 9:36:13 AM (8 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:
- 1bc27f1
- Parents:
- 2da5759
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FitPage.py
rf7f5796 r672b8ab 23 23 24 24 self.page_id = 0 25 self. is_data_loaded = False25 self.data_is_loaded = False 26 26 self.filename = "" 27 self.data = None 28 self.parameters_to_fit = [] 27 29 28 30 # QModels … … 45 47 self.smearing_options = {} 46 48 49 def save(self): 50 """ 51 Serialize the current state 52 """ 53 pass 54 55 def load(self, location): 56 """ 57 Retrieve serialized state from specified location 58 """ 59 pass 60 61 def saveAsXML(self): 62 """ 63 Serialize the current state 64 """ 65 # Connect to PageState.to_xml(), which serializes 66 # to the existing XML with file I(Q) 67 pass 68 -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r2da5759 r672b8ab 358 358 self.createDefaultDataset() 359 359 360 #state = self.currentState()360 state = self.currentState() 361 361 362 362 def onSelectStructureFactor(self): … … 1149 1149 self.current_shell_displayed = index 1150 1150 1151 def readFitPage(self, fp): 1152 """ 1153 Read in state from a fitpage object and update GUI 1154 """ 1155 assert isinstance(fp, FitPage) 1156 # Main tab info 1157 self.logic.data.filename = fp.filename 1158 self.data_is_loaded = fp.data_is_loaded 1159 self.chkPolydispersity.setCheckState(fp.is_polydisperse) 1160 self.chkMagnetism.setCheckState(fp.is_magnetic) 1161 self.chk2DView.setCheckState(fp.is2D) 1162 1163 # Update the comboboxes 1164 self.cbCategory.setCurrentIndex(self.cbCategory.findText(fp.current_category)) 1165 self.cbModel.setCurrentIndex(self.cbModel.findText(fp.current_model)) 1166 if fp.current_factor: 1167 self.cbStructureFactor.setCurrentIndex(self.cbStructureFactor.findText(fp.current_factor)) 1168 1169 self.chi2 = fp.chi2 1170 1171 # Options tab 1172 self.q_range_min = fp.fit_options[fp.MIN_RANGE] 1173 self.q_range_max = fp.fit_options[fp.MAX_RANGE] 1174 self.npts = fp.fit_options[fp.NPTS] 1175 #fp.fit_options[fp.NPTS_FIT] = self.npts_fit 1176 self.log_points = fp.fit_options[fp.LOG_POINTS] 1177 self.weighting = fp.fit_options[fp.WEIGHTING] 1178 1179 # Models 1180 #self._model_model = fp.model_model 1181 #self._poly_model = fp.poly_model 1182 #self._magnet_model = fp.magnetism_model 1183 1184 # Resolution tab 1185 smearing = fp.smearing_options[fp.SMEARING_OPTION] 1186 accuracy = fp.smearing_options[fp.SMEARING_ACCURACY] 1187 smearing_min = fp.smearing_options[fp.SMEARING_MIN] 1188 smearing_max = fp.smearing_options[fp.SMEARING_MAX] 1189 self.smearing_widget.setState(smearing, accuracy, smearing_min, smearing_max) 1190 1191 # TODO: add polidyspersity and magnetism 1192 1193 def saveToFitPage(self, fp): 1194 """ 1195 Write current state to the given fitpage 1196 """ 1197 assert isinstance(fp, FitPage) 1198 1199 # Main tab info 1200 fp.filename = self.logic.data.filename 1201 fp.data_is_loaded = self.data_is_loaded 1202 fp.is_polydisperse = self.chkPolydispersity.isChecked() 1203 fp.is_magnetic = self.chkMagnetism.isChecked() 1204 fp.is2D = self.chk2DView.isChecked() 1205 fp.data = self.data 1206 1207 # Use current models - they contain all the required parameters 1208 fp.model_model = self._model_model 1209 fp.poly_model = self._poly_model 1210 fp.magnetism_model = self._magnet_model 1211 1212 if self.cbCategory.currentIndex() != 0: 1213 fp.current_category = str(self.cbCategory.currentText()) 1214 fp.current_model = str(self.cbModel.currentText()) 1215 1216 if self.cbStructureFactor.isEnabled() and self.cbStructureFactor.currentIndex() != 0: 1217 fp.current_factor = str(self.cbStructureFactor.currentText()) 1218 else: 1219 fp.current_factor = '' 1220 1221 fp.chi2 = self.chi2 1222 fp.parameters_to_fit = self.parameters_to_fit 1223 1224 # Options tab 1225 fp.fit_options[fp.MIN_RANGE] = self.q_range_min 1226 fp.fit_options[fp.MAX_RANGE] = self.q_range_max 1227 fp.fit_options[fp.NPTS] = self.npts 1228 #fp.fit_options[fp.NPTS_FIT] = self.npts_fit 1229 fp.fit_options[fp.LOG_POINTS] = self.log_points 1230 fp.fit_options[fp.WEIGHTING] = self.weighting 1231 1232 # Resolution tab 1233 smearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state() 1234 fp.smearing_options[fp.SMEARING_OPTION] = smearing 1235 fp.smearing_options[fp.SMEARING_ACCURACY] = accuracy 1236 fp.smearing_options[fp.SMEARING_MIN] = smearing_min 1237 fp.smearing_options[fp.SMEARING_MAX] = smearing_max 1238 1239 # TODO: add polidyspersity and magnetism 1240 1241 def currentState(self): 1242 """ 1243 Return fit page with current state 1244 """ 1245 new_page = FitPage() 1246 self.saveToFitPage(new_page) 1247 1248 return new_page 1249 1250 def pushFitPage(self, new_page): 1251 """ 1252 Add a new fit page object with current state 1253 """ 1254 #page_stack.append(new_page) 1255 pass 1256 1257 def popFitPage(self): 1258 """ 1259 Remove top fit page from stack 1260 """ 1261 #if page_stack: 1262 # page_stack.pop() 1263 pass 1264 -
src/sas/qtgui/Perspectives/Fitting/SmearingWidget.py
r180bd54 r672b8ab 180 180 181 181 return (smearing, accuracy, d_down, d_up) 182 183 def setState(self, smearing, accuracy, d_down, d_up): 184 """ 185 Sets new values for the controls 186 """ 187 # Update the model -> controls update automatically 188 if smearing is not None: 189 self.model.item(MODEL.index('SMEARING')).setText(smearing) 190 if accuracy is not None: 191 self.model.item(MODEL.index('ACCURACY')).setText(accuracy) 192 if d_down is not None: 193 self.model.item(MODEL.index('PINHOLE_MIN')).setText(d_down) 194 if d_up is not None: 195 self.model.item(MODEL.index('PINHOLE_MAX')).setText(d_up) 196 -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r2add354 r672b8ab 301 301 self.widget.calculateResiduals(test_data) 302 302 # Now, the difference is non-zero 303 self.assertEqual(float(self.widget.lblChi2Value.text()), 1.715 )303 self.assertEqual(float(self.widget.lblChi2Value.text()), 1.7151) 304 304 305 305 def testSetPolyModel(self): … … 550 550 self.assertEqual(update_spy.count(), 1) 551 551 552 def testReadFitPage(self): 553 """ 554 Read in the fitpage object and restore state 555 """ 556 # Set data 557 test_data = Data1D(x=[1,2], y=[1,2]) 558 559 # Force same data into logic 560 self.widget.logic.data = test_data 561 self.widget.data_is_loaded = True 562 category_index = self.widget.cbCategory.findText('Sphere') 563 self.widget.cbCategory.setCurrentIndex(category_index) 564 self.widget.parameters_to_fit = ['scale'] 565 # Invoke the tested method 566 fp = self.widget.currentState() 567 568 # Prepare modified fit page 569 fp.current_model = 'onion' 570 fp.is_polydisperse = True 571 572 # Read in modified state 573 self.widget.readFitPage(fp) 574 575 # Check if the widget got updated accordingly 576 self.assertEqual(self.widget.cbModel.currentText(), 'onion') 577 self.assertTrue(self.widget.chkPolydispersity.isChecked()) 578 579 def testCurrentState(self): 580 """ 581 Set up the fitpage with current state 582 """ 583 # Set data 584 test_data = Data1D(x=[1,2], y=[1,2]) 585 586 # Force same data into logic 587 self.widget.logic.data = test_data 588 self.widget.data_is_loaded = True 589 category_index = self.widget.cbCategory.findText("Sphere") 590 self.widget.cbCategory.setCurrentIndex(category_index) 591 self.widget.parameters_to_fit = ['scale'] 592 593 # Invoke the tested method 594 fp = self.widget.currentState() 595 596 # Test some entries. (Full testing of fp is done in FitPageTest) 597 self.assertIsInstance(fp.data, Data1D) 598 self.assertListEqual(list(fp.data.x), [1,2]) 599 self.assertTrue(fp.data_is_loaded) 600 self.assertEqual(fp.current_category, "Sphere") 601 self.assertEqual(fp.current_model, "adsorbed_layer") 602 self.assertListEqual(fp.parameters_to_fit, ['scale']) 603 604 def testPushFitPage(self): 605 """ 606 Push current state of fitpage onto stack 607 """ 608 pass 609 610 def testPopFitPage(self): 611 """ 612 Pop current state of fitpage from stack 613 """ 614 pass 552 615 553 616 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.