Changeset 180bd54 in sasview for src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
- Timestamp:
- Apr 27, 2017 8:39:35 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:
- 0215e0a
- Parents:
- 98b13f72
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
- Property mode changed from 100755 to 100644
r98b13f72 r180bd54 2 2 import json 3 3 import os 4 import numpy 4 import numpy as np 5 5 from collections import defaultdict 6 6 from itertools import izip … … 31 31 from sas.qtgui.Perspectives.Fitting import FittingUtilities 32 32 from SmearingWidget import SmearingWidget 33 from OptionsWidget import OptionsWidget 33 34 34 35 TAB_MAGNETISM = 4 … … 37 38 CATEGORY_STRUCTURE = "Structure Factor" 38 39 STRUCTURE_DEFAULT = "None" 39 QMIN_DEFAULT = 0.000540 QMAX_DEFAULT = 0.541 NPTS_DEFAULT = 5042 40 43 41 class FittingWidget(QtGui.QWidget, Ui_FittingWidgetUI): … … 69 67 # Parameters to fit 70 68 self.parameters_to_fit = None 71 # Weight radio box group 72 self.weightingGroup = QtGui.QButtonGroup() 69 # Fit options 70 self.q_range_min = 0.005 71 self.q_range_max = 0.1 72 self.npts = 25 73 self.log_points = False 74 self.weighting = 0 73 75 74 76 # Which tab is this widget displayed in? … … 78 80 self.current_shell_displayed = 0 79 81 self.has_error_column = False 80 81 # Range parameters82 self.q_range_min = QMIN_DEFAULT83 self.q_range_max = QMAX_DEFAULT84 self.npts = NPTS_DEFAULT85 82 86 83 # Main Data[12]D holder … … 92 89 self.communicate = self.parent.communicate 93 90 91 # Options widget 92 layout = QtGui.QGridLayout() 93 self.options_widget = OptionsWidget(self, self.logic) 94 layout.addWidget(self.options_widget) 95 self.tabOptions.setLayout(layout) 96 94 97 # Smearing widget 95 98 layout = QtGui.QGridLayout() 96 99 self.smearing_widget = SmearingWidget(self) 97 100 layout.addWidget(self.smearing_widget) 98 #self.tabFitting.removeTab(2) 99 self.tabFitting.insertTab(2, self.smearing_widget, "Resolution") 101 self.tabResolution.setLayout(layout) 100 102 101 103 # Define bold font for use in various controls … … 186 188 self.updateQRange() 187 189 self.cmdFit.setEnabled(True) 188 self.boxWeighting.setEnabled(True)189 self.cmdMaskEdit.setEnabled(True)190 # Switch off txtNpts related controls191 self.txtNpts.setEnabled(False)192 self.txtNptsFit.setEnabled(False)193 self.chkLogData.setEnabled(False)194 190 # Switch off Data2D control 195 191 self.chk2DView.setEnabled(False) 196 192 self.chk2DView.setVisible(False) 197 193 self.chkMagnetism.setEnabled(True) 198 199 # Weighting controls 200 if self.is2D: 201 if self.logic.data.err_data is None or\ 202 numpy.all(err == 1 for err in self.logic.data.err_data) or \ 203 not numpy.any(self.logic.data.err_data): 204 self.rbWeighting2.setEnabled(False) 205 self.rbWeighting1.setChecked(True) 206 else: 207 self.rbWeighting2.setEnabled(True) 208 self.rbWeighting2.setChecked(True) 209 else: 210 if self.logic.data.dy is None or\ 211 numpy.all(self.logic.data.dy == 1) or\ 212 not numpy.any(self.logic.data.dy): 213 self.rbWeighting2.setEnabled(False) 214 self.rbWeighting1.setChecked(True) 215 else: 216 self.rbWeighting2.setEnabled(True) 217 self.rbWeighting2.setChecked(True) 194 # Similarly on other tabs 195 self.options_widget.setEnablementOnDataLoad() 218 196 219 197 # Smearing tab … … 260 238 self.onSelectModel() 261 239 262 def toggleLogData(self, isChecked):263 """ Toggles between log and linear data sets """264 pass265 266 240 def initializeControls(self): 267 241 """ … … 270 244 self.cmdFit.setEnabled(False) 271 245 self.cmdPlot.setEnabled(True) 272 self. cmdComputePoints.setVisible(False) # probably redundant246 self.options_widget.cmdComputePoints.setVisible(False) # probably redundant 273 247 self.chkPolydispersity.setEnabled(True) 274 248 self.chkPolydispersity.setCheckState(False) … … 281 255 self.tabFitting.setTabEnabled(TAB_MAGNETISM, False) 282 256 self.lblChi2Value.setText("---") 283 # Group boxes284 self.boxWeighting.setEnabled(False)285 self.cmdMaskEdit.setEnabled(False)286 # Button groups287 self.weightingGroup.addButton(self.rbWeighting1)288 self.weightingGroup.addButton(self.rbWeighting2)289 self.weightingGroup.addButton(self.rbWeighting3)290 self.weightingGroup.addButton(self.rbWeighting4)291 257 # Smearing tab 292 258 self.smearing_widget.updateSmearing(self.data) 259 # Line edits in the option tab 260 self.updateQRange() 293 261 294 262 def initializeSignals(self): … … 304 272 self.chkPolydispersity.toggled.connect(self.togglePoly) 305 273 self.chkMagnetism.toggled.connect(self.toggleMagnetism) 306 self.chkLogData.toggled.connect(self.toggleLogData)307 274 # Buttons 308 275 self.cmdFit.clicked.connect(self.onFit) 309 276 self.cmdPlot.clicked.connect(self.onPlot) 310 self.cmdMaskEdit.clicked.connect(self.onMaskEdit)311 self.cmdReset.clicked.connect(self.onReset)312 # Line edits313 self.txtNpts.editingFinished.connect(self.onNpts)314 self.txtMinRange.editingFinished.connect(self.onMinRange)315 self.txtMaxRange.editingFinished.connect(self.onMaxRange)316 # Button groups317 self.weightingGroup.buttonClicked.connect(self.onWeightingChoice)318 277 319 278 # Respond to change in parameters from the UI … … 322 281 # TODO after the poly_model prototype accepted 323 282 #self._magnet_model.itemChanged.connect(self.onMagneticModelChange) 283 284 # Signals from separate tabs asking for replot 285 self.options_widget.plot_signal.connect(self.onOptionsUpdate) 324 286 325 287 def onSelectModel(self): … … 391 353 # Populate the models combobox 392 354 self.cbModel.addItems(sorted([model for (model, _) in model_list])) 393 394 def onWeightingChoice(self, button):395 """396 Update weighting in the fit state397 """398 button_id = button.group().checkedId()399 button_id = abs(button_id + 2)400 #self.fitPage.weighting = button_id401 print button_id402 355 403 356 def onPolyModelChange(self, item): … … 448 401 params_to_fit = self.parameters_to_fit 449 402 450 # Potential weights added 403 # Potential weights added directly to data 451 404 self.addWeightingToData(data) 452 405 453 406 # Potential smearing added 407 # Remember that smearing_min/max can be None -> 408 # deal with it until Python gets discriminated unions 454 409 smearing, accuracy, smearing_min, smearing_max = self.smearing_widget.state() 455 410 … … 512 467 res = res_list[0] 513 468 if res.fitness is None or \ 514 not n umpy.isfinite(res.fitness) or \515 n umpy.any(res.pvec == None) or \516 not n umpy.all(numpy.isfinite(res.pvec)):469 not np.isfinite(res.fitness) or \ 470 np.any(res.pvec == None) or \ 471 not np.all(np.isfinite(res.pvec)): 517 472 msg = "Fitting did not converge!!!" 518 473 self.communicate.statusBarUpdateSignal.emit(msg) … … 607 562 Plot the current set of data 608 563 """ 609 if self.data is None:564 if not self.data_is_loaded: 610 565 self.createDefaultDataset() 611 566 self.calculateQGridForModel() 612 567 613 def onNpts(self): 614 """ 615 Callback for number of points line edit update 616 """ 617 # assumes type/value correctness achieved with QValidator 618 try: 619 self.npts = int(self.txtNpts.text()) 620 except ValueError: 621 # TODO 622 # This will return the old value to model/view and return 623 # notifying the user about format available. 624 pass 625 # Force redisplay 626 if self.model_is_loaded: 627 self.onPlot() 628 629 def onMinRange(self): 630 """ 631 Callback for minimum range of points line edit update 632 """ 633 # assumes type/value correctness achieved with QValidator 634 try: 635 self.q_range_min = float(self.txtMinRange.text()) 636 except ValueError: 637 # TODO 638 # This will return the old value to model/view and return 639 # notifying the user about format available. 640 return 641 # set Q range labels on the main tab 642 #self.lblMinRangeDef.setText(str(self.q_range_min)) 643 if self.model_is_loaded: 644 self.onPlot() 645 646 def onMaxRange(self): 647 """ 648 Callback for maximum range of points line edit update 649 """ 650 # assumes type/value correctness achieved with QValidator 651 try: 652 self.q_range_max = float(self.txtMaxRange.text()) 653 except: 654 pass 655 # set Q range labels on the main tab 656 self.lblMaxRangeDef.setText(str(self.q_range_max)) 657 if self.model_is_loaded: 658 self.onPlot() 659 660 def onMaskEdit(self): 661 """ 662 Callback for running the mask editor 663 """ 664 pass 665 666 def onReset(self): 667 """ 668 Callback for resetting qmin/qmax 669 """ 670 pass 568 def onOptionsUpdate(self): 569 """ 570 Update local option values and replot 571 """ 572 self.q_range_min, self.q_range_max, self.npts, self.log_points, self.weighting = \ 573 self.options_widget.state() 574 self.onPlot() 671 575 672 576 def setDefaultStructureCombo(self): … … 686 590 # Create default datasets if no data passed 687 591 if self.is2D: 688 qmax = self.q_range_max/n umpy.sqrt(2)592 qmax = self.q_range_max/np.sqrt(2) 689 593 qstep = self.npts 690 594 self.logic.createDefault2dData(qmax, qstep, self.tab_id) 595 return 596 elif self.log_points: 597 qmin = -10.0 if self.q_range_min < 1.e-10 else np.log10(self.q_range_min) 598 qmax = 10.0 if self.q_range_max > 1.e10 else np.log10(self.q_range_max) 599 interval = np.logspace(start=qmin, stop=qmax, num=self.npts, endpoint=True, base=10.0) 691 600 else: 692 interval = n umpy.linspace(start=self.q_range_min, stop=self.q_range_max,693 694 601 interval = np.linspace(start=self.q_range_min, stop=self.q_range_max, 602 num=self.npts, endpoint=True) 603 self.logic.createDefault1dData(interval, self.tab_id) 695 604 696 605 def readCategoryInfo(self): … … 745 654 """ 746 655 Adds weighting contribution to fitting data 747 """ 748 # Check the state of the Weighting radio buttons 749 button_id = self.weightingGroup.checkedId() 750 # Cast the id to a valid index 751 button_id = abs(button_id + 2) 752 if button_id == 0: 753 # No weight added 754 return 656 #""" 755 657 # Send original data for weighting 756 weight = get_weight(data=data, is2d=self.is2D, flag=button_id) 757 if self.is2D: 758 data.err_data = weight 759 else: 760 data.dy = weight 658 weight = get_weight(data=data, is2d=self.is2D, flag=self.weighting) 659 update_module = data.err_data if self.is2D else data.dy 660 update_module = weight 761 661 762 662 def updateQRange(self): … … 770 670 self.lblMaxRangeDef.setText(str(self.q_range_max)) 771 671 # set Q range labels on the options tab 772 self.txtMaxRange.setText(str(self.q_range_max)) 773 self.txtMinRange.setText(str(self.q_range_min)) 774 self.txtNpts.setText(str(self.npts)) 775 self.txtNptsFit.setText(str(self.npts)) 672 self.options_widget.updateQRange(self.q_range_min, self.q_range_max, self.npts) 776 673 777 674 def SASModelToQModel(self, model_name, structure_factor=None): … … 959 856 Prepare the fitting data object, based on current ModelModel 960 857 """ 858 if self.kernel_module is None: 859 return 961 860 # Awful API to a backend method. 962 861 method = self.methodCalculateForData()(data=self.data,
Note: See TracChangeset
for help on using the changeset viewer.