Changeset c1e380e in sasview


Ignore:
Timestamp:
May 30, 2017 4:14:29 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
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:
358b39d
Parents:
c416a17
Message:

Towards polydispersity support SASVIEW-593

Location:
src/sas/qtgui/Perspectives/Fitting
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r6964d44 rc1e380e  
    4040CATEGORY_STRUCTURE = "Structure Factor" 
    4141STRUCTURE_DEFAULT = "None" 
     42 
     43# Mapping between column index and relevant parameter name extension 
     44POLY_COLUMN_DICT = { 
     45    1: 'width', 
     46    2: 'min', 
     47    3: 'max', 
     48    4: 'npts', 
     49    5: 'nsigmas'} 
    4250 
    4351class FittingWidget(QtGui.QWidget, Ui_FittingWidgetUI): 
     
    239247        self.setTableProperties(self.lstPoly) 
    240248        # Delegates for custom editing and display 
    241         self.lstPoly.setItemDelegate(PolyViewDelegate(self)) 
     249        # self.lstPoly.setItemDelegate(PolyViewDelegate(self)) 
    242250 
    243251        # Magnetism model displayed in magnetism list 
     
    469477        model_row = item.row() 
    470478        name_index = self._poly_model.index(model_row, 0) 
     479        parameter_name = str(name_index.data().toString()).lower() # "distribution of sld" etc. 
     480        if "distribution of" in parameter_name: 
     481            parameter_name = parameter_name[16:] 
     482 
    471483        # Extract changed value. Assumes proper validation by QValidator/Delegate 
    472484        # TODO: abstract away hardcoded column numbers 
     
    475487            value = item.checkState() 
    476488            # TODO: add the param to self.params_for_fitting 
     489            parameter_name = parameter_name+'.width' 
     490            if value == QtCore.Qt.Checked: 
     491                self.parameters_to_fit.append(parameter_name) 
     492            else: 
     493                if parameter_name in self.parameters_to_fit: 
     494                    self.parameters_to_fit.remove(parameter_name) 
     495            return 
    477496        elif model_column == 6: 
    478497            value = item.text() 
     
    485504                return 
    486505 
    487         parameter_name = str(self._poly_model.data(name_index).toPyObject()) # "distribution of sld" etc. 
    488         if "Distribution of" in parameter_name: 
    489             parameter_name = parameter_name[16:] 
    490         property_name = str(self._poly_model.headerData(model_column, 1).toPyObject()) # Value, min, max, etc. 
     506        property_name = str(self._poly_model.headerData(model_column, 1).toPyObject()).lower() # Value, min, max, etc. 
    491507        # print "%s(%s) => %d" % (parameter_name, property_name, value) 
    492508 
    493509        # Update the sasmodel 
    494         #self.kernel_module.params[parameter_name] = value 
     510        # PD[ratio] -> width, npts -> npts, nsigs -> nsigmas 
     511        self.kernel_module.setParam(parameter_name + '.' + POLY_COLUMN_DICT[model_column], value) 
    495512 
    496513        # Reload the main model - may not be required if no variable is shown in main view 
     
    521538        qmax = self.q_range_max 
    522539        params_to_fit = self.parameters_to_fit 
     540 
     541        print "OPTIMIZING: ", params_to_fit 
    523542 
    524543        # Potential weights added directly to data 
     
    963982        status = item.checkState() 
    964983 
    965         def isChecked(row): 
    966             return self._model_model.item(row, 0).checkState() == QtCore.Qt.Checked 
    967  
    968984        def isCheckable(row): 
    969985            return self._model_model.item(row, 0).isCheckable() 
     
    979995 
    980996        # update the list of parameters to fit 
    981         self.parameters_to_fit = [str(self._model_model.item(row_index, 0).text()) 
    982                                   for row_index in xrange(self._model_model.rowCount()) 
    983                                   if isChecked(row_index)] 
     997        main_params = self.checkedListFromModel(self._model_model) 
     998        poly_params = self.checkedListFromModel(self._poly_model) 
     999        # Retrieve poly params names 
     1000        poly_params = [param[16:]+'.width' for param in poly_params] 
     1001        # TODO : add magnetic params 
     1002 
     1003        self.parameters_to_fit = main_params + poly_params 
     1004 
     1005    def checkedListFromModel(self, model): 
     1006        """ 
     1007        Returns list of checked parameters for given model 
     1008        """ 
     1009        def isChecked(row): 
     1010            return model.item(row, 0).checkState() == QtCore.Qt.Checked 
     1011 
     1012        return [str(model.item(row_index, 0).text()) 
     1013                for row_index in xrange(model.rowCount()) 
     1014                if isChecked(row_index)] 
    9841015 
    9851016    def nameForFittedData(self, name): 
     
    10771108        calc_thread = threads.deferToThread(method.compute) 
    10781109        calc_thread.addCallback(self.methodCompleteForData()) 
    1079         calc_thread.addErrback(self.calculateDataFailed()) 
     1110        calc_thread.addErrback(self.calculateDataFailed) 
    10801111 
    10811112    def calculateDataFailed(self): 
    10821113        """ 
     1114        Thread returned error 
    10831115        """ 
    10841116        print "Calculate Data failed." 
     
    11281160    def calcException(self, etype, value, tb): 
    11291161        """ 
    1130         Something horrible happened in the deferred. 
    1131         """ 
     1162        Thread threw an exception. 
     1163        """ 
     1164        # TODO: remimplement thread cancellation 
    11321165        logging.error("".join(traceback.format_exception(etype, value, tb))) 
    11331166 
     
    11641197                continue 
    11651198 
     1199            # Values from the sasmodel 
     1200            width = self.kernel_module.getParam(param.name+'.width') 
     1201            npts = self.kernel_module.getParam(param.name+'.npts') 
     1202            nsigs = self.kernel_module.getParam(param.name+'.nsigmas') 
    11661203            # Potential multishell params 
    1167             checked_list = ["Distribution of "+param.name, str(param.default), 
     1204            checked_list = ["Distribution of "+param.name, str(width), 
    11681205                            str(param.limits[0]), str(param.limits[1]), 
    1169                             "35", "3", "gaussian"] 
     1206                            str(npts), str(nsigs), ""] 
    11701207            FittingUtilities.addCheckedListToModel(self._poly_model, checked_list) 
    11711208 
    11721209            #TODO: Need to find cleaner way to input functions 
    1173             #func = QtGui.QComboBox() 
    1174             #func.addItems(['rectangle', 'array', 'lognormal', 'gaussian', 'schulz',]) 
    1175             #func_index = self.lstPoly.model().index(row, 6) 
    1176             #self.lstPoly.setIndexWidget(func_index, func) 
     1210            func = QtGui.QComboBox() 
     1211            func.addItems(['rectangle', 'array', 'lognormal', 'gaussian', 'schulz',]) 
     1212            func_index = self.lstPoly.model().index(row, 6) 
     1213            self.lstPoly.setIndexWidget(func_index, func) 
    11771214 
    11781215        FittingUtilities.addPolyHeadersToModel(self._poly_model) 
  • src/sas/qtgui/Perspectives/Fitting/OptionsWidget.py

    rdc5ef15 rc1e380e  
    8484        self.txtMinRange.setText(str(QMIN_DEFAULT)) 
    8585        self.txtNpts.setText(str(NPTS_DEFAULT)) 
     86        self.txtNptsFit.setText(str(NPTS_DEFAULT)) 
    8687        self.model.blockSignals(False) 
    8788 
     
    125126        Callback for resetting qmin/qmax 
    126127        """ 
    127         pass 
     128        self.updateQRange(QMIN_DEFAULT, QMAX_DEFAULT, NPTS_DEFAULT) 
    128129 
    129130    def onWeightingChoice(self, button): 
  • src/sas/qtgui/Perspectives/Fitting/UI/OptionsWidgetUI.ui

    r180bd54 rc1e380e  
    3131        </item> 
    3232        <item row="0" column="1"> 
    33          <widget class="QLineEdit" name="txtMinRange"/> 
     33         <widget class="QLineEdit" name="txtMinRange"> 
     34          <property name="toolTip"> 
     35           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Minimum value of Q.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> 
     36          </property> 
     37         </widget> 
    3438        </item> 
    3539        <item row="0" column="2"> 
     
    4953        </item> 
    5054        <item row="1" column="1"> 
    51          <widget class="QLineEdit" name="txtMaxRange"/> 
     55         <widget class="QLineEdit" name="txtMaxRange"> 
     56          <property name="toolTip"> 
     57           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Maximum value of Q.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> 
     58          </property> 
     59         </widget> 
    5260        </item> 
    5361        <item row="1" column="2"> 
     
    7684      <item row="0" column="2"> 
    7785       <widget class="QPushButton" name="cmdReset"> 
     86        <property name="toolTip"> 
     87         <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Reset the Q range to the default.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> 
     88        </property> 
    7889        <property name="text"> 
    7990         <string>Reset</string> 
     
    107118        </item> 
    108119        <item row="0" column="1"> 
    109          <widget class="QLineEdit" name="txtNpts"/> 
     120         <widget class="QLineEdit" name="txtNpts"> 
     121          <property name="toolTip"> 
     122           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Total number of data points.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> 
     123          </property> 
     124         </widget> 
    110125        </item> 
    111126        <item row="0" column="2"> 
    112127         <widget class="QCheckBox" name="chkLogData"> 
     128          <property name="toolTip"> 
     129           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Check to use log spaced points.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> 
     130          </property> 
    113131          <property name="text"> 
    114132           <string>Log spaced points</string> 
     
    125143        <item row="1" column="1"> 
    126144         <widget class="QLineEdit" name="txtNptsFit"> 
     145          <property name="toolTip"> 
     146           <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Number of points selected for fitting.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string> 
     147          </property> 
    127148          <property name="readOnly"> 
    128149           <bool>true</bool> 
Note: See TracChangeset for help on using the changeset viewer.