Ignore:
File:
1 edited

Legend:

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

    r5fb714b r66d4370  
    9191    fittingFinishedSignal = QtCore.pyqtSignal(tuple) 
    9292    batchFittingFinishedSignal = QtCore.pyqtSignal(tuple) 
    93     Calc1DFinishedSignal = QtCore.pyqtSignal(dict) 
    94     Calc2DFinishedSignal = QtCore.pyqtSignal(dict) 
     93    Calc1DFinishedSignal = QtCore.pyqtSignal(tuple) 
     94    Calc2DFinishedSignal = QtCore.pyqtSignal(tuple) 
    9595 
    9696    def __init__(self, parent=None, data=None, tab_id=1): 
     
    219219        # Utility variable to enable unselectable option in category combobox 
    220220        self._previous_category_index = 0 
    221         # Utility variables for multishell display 
    222         self._n_shells_row = 0 
    223         self._num_shell_params = 0 
     221        # Utility variable for multishell display 
     222        self._last_model_row = 0 
    224223        # Dictionary of {model name: model class} for the current category 
    225224        self.models = {} 
     
    677676        Return list of all parameters for the current model 
    678677        """ 
    679         return [self._model_model.item(row).text() 
    680                 for row in range(self._model_model.rowCount()) 
    681                 if self.isCheckable(row)] 
     678        return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 
    682679 
    683680    def modifyViewOnRow(self, row, font=None, brush=None): 
     
    707704        assert isinstance(constraint, Constraint) 
    708705        assert 0 <= row <= self._model_model.rowCount() 
    709         assert self.isCheckable(row) 
    710706 
    711707        item = QtGui.QStandardItem() 
     
    728724        max_col = self.lstParams.itemDelegate().param_max 
    729725        for row in self.selectedParameters(): 
    730             assert(self.isCheckable(row)) 
    731726            param = self._model_model.item(row, 0).text() 
    732727            value = self._model_model.item(row, 1).text() 
     
    771766        max_col = self.lstParams.itemDelegate().param_max 
    772767        for row in range(self._model_model.rowCount()): 
    773             if not self.isCheckable(row): 
    774                 continue 
    775768            if not self.rowHasConstraint(row): 
    776769                continue 
     
    801794        For the given row, return its constraint, if any 
    802795        """ 
    803         if self.isCheckable(row): 
     796        try: 
    804797            item = self._model_model.item(row, 1) 
    805             try: 
    806                 return item.child(0).data() 
    807             except AttributeError: 
    808                 # return none when no constraints 
    809                 pass 
    810         return None 
     798            return item.child(0).data() 
     799        except AttributeError: 
     800            # return none when no constraints 
     801            return None 
    811802 
    812803    def rowHasConstraint(self, row): 
     
    814805        Finds out if row of the main model has a constraint child 
    815806        """ 
    816         if self.isCheckable(row): 
    817             item = self._model_model.item(row, 1) 
    818             if item.hasChildren(): 
    819                 c = item.child(0).data() 
    820                 if isinstance(c, Constraint): 
    821                     return True 
     807        item = self._model_model.item(row, 1) 
     808        if item.hasChildren(): 
     809            c = item.child(0).data() 
     810            if isinstance(c, Constraint): 
     811                return True 
    822812        return False 
    823813 
     
    826816        Finds out if row of the main model has an active constraint child 
    827817        """ 
    828         if self.isCheckable(row): 
    829             item = self._model_model.item(row, 1) 
    830             if item.hasChildren(): 
    831                 c = item.child(0).data() 
    832                 if isinstance(c, Constraint) and c.active: 
    833                     return True 
     818        item = self._model_model.item(row, 1) 
     819        if item.hasChildren(): 
     820            c = item.child(0).data() 
     821            if isinstance(c, Constraint) and c.active: 
     822                return True 
    834823        return False 
    835824 
     
    838827        Finds out if row of the main model has an active, nontrivial constraint child 
    839828        """ 
    840         if self.isCheckable(row): 
    841             item = self._model_model.item(row, 1) 
    842             if item.hasChildren(): 
    843                 c = item.child(0).data() 
    844                 if isinstance(c, Constraint) and c.func and c.active: 
    845                     return True 
     829        item = self._model_model.item(row, 1) 
     830        if item.hasChildren(): 
     831            c = item.child(0).data() 
     832            if isinstance(c, Constraint) and c.func and c.active: 
     833                return True 
    846834        return False 
    847835 
     
    12091197            self.updateData() 
    12101198 
    1211         # update in param model 
    1212         if model_column in [delegate.poly_pd, delegate.poly_error, delegate.poly_min, delegate.poly_max]: 
    1213             row = self.getRowFromName(parameter_name) 
    1214             param_item = self._model_model.item(row) 
    1215             self._model_model.blockSignals(True) 
    1216             param_item.child(0).child(0, model_column).setText(item.text()) 
    1217             self._model_model.blockSignals(False) 
    1218  
    12191199    def onMagnetModelChange(self, item): 
    12201200        """ 
     
    15891569            # internal so can use closure for param_dict 
    15901570            param_name = str(self._model_model.item(row, 0).text()) 
    1591             if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 
     1571            if param_name not in list(param_dict.keys()): 
    15921572                return 
    15931573            # modify the param value 
     
    16011581            # Utility function for updateof polydispersity part of the main model 
    16021582            param_name = str(self._model_model.item(row, 0).text())+'.width' 
    1603             if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 
     1583            if param_name not in list(param_dict.keys()): 
    16041584                return 
    16051585            # modify the param value 
     
    19781958        # Crete/overwrite model items 
    19791959        self._model_model.clear() 
    1980         self._poly_model.clear() 
    1981         self._magnet_model.clear() 
    1982  
    1983         if model_name is None: 
    1984             if structure_factor not in (None, "None"): 
    1985                 # S(Q) on its own, treat the same as a form factor 
    1986                 self.kernel_module = None 
    1987                 self.fromStructureFactorToQModel(structure_factor) 
    1988             else: 
    1989                 # No models selected 
    1990                 return 
     1960 
     1961        # First, add parameters from the main model 
     1962        if model_name is not None: 
     1963            self.fromModelToQModel(model_name) 
     1964 
     1965        # Then, add structure factor derived parameters 
     1966        if structure_factor is not None and structure_factor != "None": 
     1967            if model_name is None: 
     1968                # Instantiate the current sasmodel for SF-only models 
     1969                self.kernel_module = self.models[structure_factor]() 
     1970            self.fromStructureFactorToQModel(structure_factor) 
    19911971        else: 
    1992             self.fromModelToQModel(model_name) 
    1993             self.addExtraShells() 
    1994  
    19951972            # Allow the SF combobox visibility for the given sasmodel 
    19961973            self.enableStructureFactorControl(structure_factor) 
    1997          
    1998             # Add S(Q) 
    19991974            if self.cbStructureFactor.isEnabled(): 
    20001975                structure_factor = self.cbStructureFactor.currentText() 
    20011976                self.fromStructureFactorToQModel(structure_factor) 
    20021977 
    2003             # Add polydispersity to the model 
    2004             self.poly_params = {} 
    2005             self.setPolyModel() 
    2006             # Add magnetic parameters to the model 
    2007             self.magnet_params = {} 
    2008             self.setMagneticModel() 
     1978        # Then, add multishells 
     1979        if model_name is not None: 
     1980            # Multishell models need additional treatment 
     1981            self.addExtraShells() 
     1982 
     1983        # Add polydispersity to the model 
     1984        self.poly_params = {} 
     1985        self.setPolyModel() 
     1986        # Add magnetic parameters to the model 
     1987        self.magnet_params = {} 
     1988        self.setMagneticModel() 
    20091989 
    20101990        # Adjust the table cells width 
     
    20792059        self.shell_names = self.shellNamesList() 
    20802060 
    2081         # Add heading row 
    2082         FittingUtilities.addHeadingRowToModel(self._model_model, model_name) 
    2083  
    20842061        # Update the QModel 
    2085         FittingUtilities.addParametersToModel( 
    2086                 self.model_parameters, 
    2087                 self.kernel_module, 
    2088                 self.is2D, 
    2089                 self._model_model, 
    2090                 self.lstParams) 
     2062        new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 
     2063 
     2064        for row in new_rows: 
     2065            self._model_model.appendRow(row) 
     2066        # Update the counter used for multishell display 
     2067        self._last_model_row = self._model_model.rowCount() 
    20912068 
    20922069    def fromStructureFactorToQModel(self, structure_factor): 
     
    20962073        if structure_factor is None or structure_factor=="None": 
    20972074            return 
    2098  
    2099         if self.kernel_module is None: 
    2100             # Structure factor is the only selected model; build it and show all its params 
    2101             self.kernel_module = self.models[structure_factor]() 
    2102             s_params = self.kernel_module._model_info.parameters 
    2103             s_params_orig = s_params 
    2104  
    2105         else: 
    2106             s_kernel = self.models[structure_factor]() 
    2107             p_kernel = self.kernel_module 
    2108  
    2109             p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
    2110             s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) 
    2111  
    2112             self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
    2113             all_params = self.kernel_module._model_info.parameters.kernel_parameters 
    2114             all_param_names = [param.name for param in all_params] 
    2115  
    2116             # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any 
    2117             # conflicting names with P(Q) params will cause a rename 
    2118  
    2119             if "radius_effective_mode" in all_param_names: 
    2120                 # Show all parameters 
    2121                 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 
    2122                 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 
    2123             else: 
    2124                 # Ensure radius_effective is not displayed 
    2125                 s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
    2126                 if "radius_effective" in all_param_names: 
    2127                     s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 
    2128                 else: 
    2129                     s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 
    2130  
    2131         # Add heading row 
    2132         FittingUtilities.addHeadingRowToModel(self._model_model, structure_factor) 
    2133  
    2134         # Get new rows for QModel 
    2135         # Any renamed parameters are stored as data in the relevant item, for later handling 
    2136         FittingUtilities.addSimpleParametersToModel( 
    2137                 s_params, 
    2138                 self.is2D, 
    2139                 s_params_orig, 
    2140                 self._model_model, 
    2141                 self.lstParams) 
     2075        structure_module = generate.load_kernel_module(structure_factor) 
     2076        structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
     2077 
     2078        structure_kernel = self.models[structure_factor]() 
     2079        form_kernel = self.kernel_module 
     2080 
     2081        self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 
     2082 
     2083        new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 
     2084        for row in new_rows: 
     2085            self._model_model.appendRow(row) 
     2086            # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 
     2087            if row[0].text() not in self.kernel_module.params.keys(): 
     2088                row_num = self._model_model.rowCount() - 1 
     2089                FittingUtilities.markParameterDisabled(self._model_model, row_num) 
     2090 
     2091        # Update the counter used for multishell display 
     2092        self._last_model_row = self._model_model.rowCount() 
    21422093 
    21432094    def haveParamsToFit(self): 
     
    21652116        model_row = item.row() 
    21662117        name_index = self._model_model.index(model_row, 0) 
    2167         name_item = self._model_model.itemFromIndex(name_index) 
    21682118 
    21692119        # Extract changed value. 
     
    21742124            return 
    21752125 
    2176         # if the item has user data, this is the actual parameter name (e.g. to handle duplicate names) 
    2177         if name_item.data(QtCore.Qt.UserRole): 
    2178             parameter_name = str(name_item.data(QtCore.Qt.UserRole)) 
    2179         else: 
    2180             parameter_name = str(self._model_model.data(name_index)) 
     2126        parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 
    21812127 
    21822128        # Update the parameter value - note: this supports +/-inf as well 
     
    24122358            new_plots.append(sq_data) 
    24132359 
     2360        # Update/generate plots 
    24142361        for plot in new_plots: 
    24152362            self.communicate.plotUpdateSignal.emit([plot]) 
     
    26112558        def updateFunctionCaption(row): 
    26122559            # Utility function for update of polydispersity function name in the main model 
    2613             if not self.isCheckable(row): 
    2614                 return 
    2615             self._model_model.blockSignals(True) 
    26162560            param_name = str(self._model_model.item(row, 0).text()) 
    2617             self._model_model.blockSignals(False) 
    26182561            if param_name !=  param.name: 
    26192562                return 
    26202563            # Modify the param value 
    2621             self._model_model.blockSignals(True) 
    26222564            if self.has_error_column: 
    26232565                # err column changes the indexing 
     
    26252567            else: 
    26262568                self._model_model.item(row, 0).child(0).child(0,4).setText(combo_string) 
    2627             self._model_model.blockSignals(False) 
    26282569 
    26292570        if combo_string == 'array': 
     
    27852726 
    27862727        self.lstParams.setIndexWidget(shell_index, func) 
    2787         self._n_shells_row = shell_row - 1 
     2728        self._last_model_row = self._model_model.rowCount() 
    27882729 
    27892730        # Set the index to the state-kept value 
     
    27962737        """ 
    27972738        # Find row location of the combobox 
    2798         first_row = self._n_shells_row + 1 
    2799         remove_rows = self._num_shell_params 
     2739        last_row = self._last_model_row 
     2740        remove_rows = self._model_model.rowCount() - last_row 
    28002741 
    28012742        if remove_rows > 1: 
    2802             self._model_model.removeRows(first_row, remove_rows) 
    2803  
    2804         new_rows = FittingUtilities.addShellsToModel( 
    2805                 self.model_parameters, 
    2806                 self._model_model, 
    2807                 index, 
    2808                 first_row, 
    2809                 self.lstParams) 
    2810  
    2811         self._num_shell_params = len(new_rows) 
     2743            self._model_model.removeRows(last_row, remove_rows) 
     2744 
     2745        FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index) 
    28122746        self.current_shell_displayed = index 
    28132747 
Note: See TracChangeset for help on using the changeset viewer.