Changeset 66d4370 in sasview for src/sas/qtgui/Perspectives/Fitting
- Timestamp:
- Sep 6, 2018 9:03:25 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- 9d23e4c, 40975f8, 73665a8
- Parents:
- dda8f16
- git-author:
- Piotr Rozyczko <rozyczko@…> (09/06/18 09:01:55)
- git-committer:
- Piotr Rozyczko <rozyczko@…> (09/06/18 09:03:25)
- Location:
- src/sas/qtgui/Perspectives/Fitting
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
rf84d793 r66d4370 247 247 # copy of current kernel model 248 248 self.kernel_module_copy = None 249 250 # dictionaries of current params 251 self.poly_params = {} 252 self.magnet_params = {} 249 253 250 254 # Page id for fitting … … 1186 1190 # Update the sasmodel 1187 1191 # PD[ratio] -> width, npts -> npts, nsigs -> nsigmas 1188 self.kernel_module.setParam(parameter_name + '.' + delegate.columnDict()[model_column], value) 1192 #self.kernel_module.setParam(parameter_name + '.' + delegate.columnDict()[model_column], value) 1193 key = parameter_name + '.' + delegate.columnDict()[model_column] 1194 self.poly_params[key] = value 1189 1195 1190 1196 # Update plot 1191 1197 self.updateData() 1192 1193 # update in param model1194 if model_column in [delegate.poly_pd, delegate.poly_error, delegate.poly_min, delegate.poly_max]:1195 row = self.getRowFromName(parameter_name)1196 param_item = self._model_model.item(row)1197 param_item.child(0).child(0, model_column).setText(item.text())1198 1198 1199 1199 def onMagnetModelChange(self, item): … … 1224 1224 # Unparsable field 1225 1225 return 1226 1227 property_index = self._magnet_model.headerData(1, model_column)-1 # Value, min, max, etc. 1228 1229 # Update the parameter value - note: this supports +/-inf as well 1230 self.kernel_module.params[parameter_name] = value 1231 1232 # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 1233 self.kernel_module.details[parameter_name][property_index] = value 1234 1235 # Force the chart update when actual parameters changed 1236 if model_column == 1: 1226 delegate = self.lstMagnetic.itemDelegate() 1227 1228 if model_column > 1: 1229 if model_column == delegate.mag_min: 1230 pos = 1 1231 elif model_column == delegate.mag_max: 1232 pos = 2 1233 elif model_column == delegate.mag_unit: 1234 pos = 0 1235 else: 1236 raise AttributeError("Wrong column in magnetism table.") 1237 # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 1238 self.kernel_module.details[parameter_name][pos] = value 1239 else: 1240 self.magnet_params[parameter_name] = value 1241 #self.kernel_module.setParam(parameter_name) = value 1242 # Force the chart update when actual parameters changed 1237 1243 self.recalculatePlotData() 1238 1244 … … 1495 1501 # Data going in 1496 1502 data = self.logic.data 1497 model = self.kernel_module1503 model = copy.deepcopy(self.kernel_module) 1498 1504 qmin = self.q_range_min 1499 1505 qmax = self.q_range_max 1506 # add polydisperse/magnet parameters if asked 1507 self.updateKernelModelWithExtraParams(model) 1500 1508 1501 1509 params_to_fit = self.main_params_to_fit … … 1974 1982 1975 1983 # Add polydispersity to the model 1984 self.poly_params = {} 1976 1985 self.setPolyModel() 1977 1986 # Add magnetic parameters to the model 1987 self.magnet_params = {} 1978 1988 self.setMagneticModel() 1979 1989 … … 2237 2247 return self.completed1D if isinstance(self.data, Data1D) else self.completed2D 2238 2248 2249 def updateKernelModelWithExtraParams(self, model=None): 2250 """ 2251 Updates kernel model 'model' with extra parameters from 2252 the polydisp and magnetism tab, if the tabs are enabled 2253 """ 2254 if model is None: return 2255 if not hasattr(model, 'setParam'): return 2256 2257 # add polydisperse parameters if asked 2258 if self.chkPolydispersity.isChecked(): 2259 for key, value in self.poly_params.items(): 2260 model.setParam(key, value) 2261 # add magnetic params if asked 2262 if self.chkMagnetism.isChecked(): 2263 for key, value in self.magnet_params.items(): 2264 model.setParam(key, value) 2265 2239 2266 def calculateQGridForModelExt(self, data=None, model=None, completefn=None, use_threads=True): 2240 2267 """ … … 2244 2271 data = self.data 2245 2272 if model is None: 2246 model = self.kernel_module 2273 model = copy.deepcopy(self.kernel_module) 2274 self.updateKernelModelWithExtraParams(model) 2275 2247 2276 if completefn is None: 2248 2277 completefn = self.methodCompleteForData() … … 2338 2367 """ 2339 2368 fitted_data = self.logic.new2DPlot(return_data) 2340 self.calculateResiduals(fitted_data)2369 residuals = self.calculateResiduals(fitted_data) 2341 2370 self.model_data = fitted_data 2371 new_plots = [fitted_data] 2372 if residuals is not None: 2373 new_plots.append(residuals) 2374 2375 # Update/generate plots 2376 for plot in new_plots: 2377 self.communicate.plotUpdateSignal.emit([plot]) 2342 2378 2343 2379 def calculateResiduals(self, fitted_data): … … 2470 2506 _, min, max = self.kernel_module.details[param_name] 2471 2507 2508 # Update local param dict 2509 self.poly_params[param_name + '.width'] = width 2510 self.poly_params[param_name + '.npts'] = npts 2511 self.poly_params[param_name + '.nsigmas'] = nsigs 2512 2472 2513 # Construct a row with polydisp. related variable. 2473 2514 # This will get added to the polydisp. model … … 2643 2684 str(param.limits[1]), 2644 2685 param.units] 2686 2687 self.magnet_params[param.name] = param.default 2645 2688 2646 2689 FittingUtilities.addCheckedListToModel(model, checked_list) -
src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py
r605d944 r66d4370 445 445 self.assertEqual(self.widget.kernel_module.details['radius_bell'][1], 1.0) 446 446 447 #self.widget.show() 448 #QtWidgets.QApplication.exec_() 449 447 450 # Change the number of points 448 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 35)451 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 449 452 self.widget._poly_model.item(0,4).setText("22") 450 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 22)453 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 451 454 # try something stupid 452 455 self.widget._poly_model.item(0,4).setText("butt") 453 456 # see that this didn't annoy the control at all 454 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 22)457 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 455 458 456 459 # Change the number of sigmas 457 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 3)460 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 3) 458 461 self.widget._poly_model.item(0,5).setText("222") 459 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 222)462 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 460 463 # try something stupid again 461 464 self.widget._poly_model.item(0,4).setText("beer") 462 465 # no efect 463 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 222)466 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 464 467 465 468 def testOnPolyComboIndexChange(self): … … 482 485 self.widget.onPolyComboIndexChange('rectangle', 0) 483 486 # check values 484 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 35)485 self.assertAlmostEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 1.73205, 5)487 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 488 self.assertAlmostEqual(self.widget.poly_params['radius_bell.nsigmas'], 1.73205, 5) 486 489 # Change the index 487 490 self.widget.onPolyComboIndexChange('lognormal', 0) 488 491 # check values 489 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 80)490 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 8)492 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 493 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 491 494 # Change the index 492 495 self.widget.onPolyComboIndexChange('schulz', 0) 493 496 # check values 494 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.npts'), 80)495 self.assertEqual(self.widget. kernel_module.getParam('radius_bell.nsigmas'), 8)497 self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 498 self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 496 499 497 500 # mock up file load
Note: See TracChangeset
for help on using the changeset viewer.