Ignore:
Timestamp:
Sep 7, 2018 8:11:37 AM (6 years ago)
Author:
ibressler
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:
254199c
Parents:
d6c4987 (diff), fb560d2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Ingo Breßler <dev@…> (09/07/18 08:09:21)
git-committer:
Ingo Breßler <dev@…> (09/07/18 08:11:37)
Message:

Merge branch 'ESS_GUI' into ESS_GUI_iss1033

  • fixed the conflicts introduced by dcabba7b in ESS_GUI
File:
1 edited

Legend:

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

    r40975f8 r9ba91b7  
    9191    fittingFinishedSignal = QtCore.pyqtSignal(tuple) 
    9292    batchFittingFinishedSignal = QtCore.pyqtSignal(tuple) 
    93     Calc1DFinishedSignal = QtCore.pyqtSignal(tuple) 
    94     Calc2DFinishedSignal = QtCore.pyqtSignal(tuple) 
     93    Calc1DFinishedSignal = QtCore.pyqtSignal(dict) 
     94    Calc2DFinishedSignal = QtCore.pyqtSignal(dict) 
    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 variable for multishell display 
    222         self._last_model_row = 0 
     221        # Utility variables for multishell display 
     222        self._n_shells_row = 0 
     223        self._num_shell_params = 0 
    223224        # Dictionary of {model name: model class} for the current category 
    224225        self.models = {} 
     
    676677        Return list of all parameters for the current model 
    677678        """ 
    678         return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 
     679        return [self._model_model.item(row).text() 
     680                for row in range(self._model_model.rowCount()) 
     681                if self.isCheckable(row)] 
    679682 
    680683    def modifyViewOnRow(self, row, font=None, brush=None): 
     
    704707        assert isinstance(constraint, Constraint) 
    705708        assert 0 <= row <= self._model_model.rowCount() 
     709        assert self.isCheckable(row) 
    706710 
    707711        item = QtGui.QStandardItem() 
     
    724728        max_col = self.lstParams.itemDelegate().param_max 
    725729        for row in self.selectedParameters(): 
     730            assert(self.isCheckable(row)) 
    726731            param = self._model_model.item(row, 0).text() 
    727732            value = self._model_model.item(row, 1).text() 
     
    766771        max_col = self.lstParams.itemDelegate().param_max 
    767772        for row in range(self._model_model.rowCount()): 
     773            if not self.isCheckable(row): 
     774                continue 
    768775            if not self.rowHasConstraint(row): 
    769776                continue 
     
    794801        For the given row, return its constraint, if any 
    795802        """ 
    796         try: 
     803        if self.isCheckable(row): 
    797804            item = self._model_model.item(row, 1) 
    798             return item.child(0).data() 
    799         except AttributeError: 
    800             # return none when no constraints 
    801             return None 
     805            try: 
     806                return item.child(0).data() 
     807            except AttributeError: 
     808                # return none when no constraints 
     809                pass 
     810        return None 
    802811 
    803812    def rowHasConstraint(self, row): 
     
    805814        Finds out if row of the main model has a constraint child 
    806815        """ 
    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 
     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 
    812822        return False 
    813823 
     
    816826        Finds out if row of the main model has an active constraint child 
    817827        """ 
    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 
     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 
    823834        return False 
    824835 
     
    827838        Finds out if row of the main model has an active, nontrivial constraint child 
    828839        """ 
    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 
     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 
    834846        return False 
    835847 
     
    11971209            self.updateData() 
    11981210 
     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 
    11991219    def onMagnetModelChange(self, item): 
    12001220        """ 
     
    15691589            # internal so can use closure for param_dict 
    15701590            param_name = str(self._model_model.item(row, 0).text()) 
    1571             if param_name not in list(param_dict.keys()): 
     1591            if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 
    15721592                return 
    15731593            # modify the param value 
     
    15811601            # Utility function for updateof polydispersity part of the main model 
    15821602            param_name = str(self._model_model.item(row, 0).text())+'.width' 
    1583             if param_name not in list(param_dict.keys()): 
     1603            if not self.isCheckable(row) or param_name not in list(param_dict.keys()): 
    15841604                return 
    15851605            # modify the param value 
     
    19581978        # Crete/overwrite model items 
    19591979        self._model_model.clear() 
    1960  
    1961         # First, add parameters from the main model 
    1962         if model_name is not None: 
     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 
     1991        else: 
    19631992            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) 
    1971         else: 
     1993            self.addExtraShells() 
     1994 
    19721995            # Allow the SF combobox visibility for the given sasmodel 
    19731996            self.enableStructureFactorControl(structure_factor) 
     1997         
     1998            # Add S(Q) 
    19741999            if self.cbStructureFactor.isEnabled(): 
    19752000                structure_factor = self.cbStructureFactor.currentText() 
    19762001                self.fromStructureFactorToQModel(structure_factor) 
    19772002 
    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() 
     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() 
    19892009 
    19902010        # Adjust the table cells width 
     
    20592079        self.shell_names = self.shellNamesList() 
    20602080 
    2061         # Update the QModel 
     2081        # Get new rows for QModel 
    20622082        new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 
    20632083 
     2084        # Add heading row 
     2085        FittingUtilities.addHeadingRowToModel(self._model_model, model_name) 
     2086 
     2087        # Update QModel 
    20642088        for row in new_rows: 
    20652089            self._model_model.appendRow(row) 
    2066         # Update the counter used for multishell display 
    2067         self._last_model_row = self._model_model.rowCount() 
    20682090 
    20692091    def fromStructureFactorToQModel(self, structure_factor): 
     
    20732095        if structure_factor is None or structure_factor=="None": 
    20742096            return 
    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) 
     2097 
     2098        s_kernel = self.models[structure_factor]() 
     2099        p_kernel = self.kernel_module 
     2100 
     2101        if p_kernel is None: 
     2102            # Not a product model, just S(Q) 
     2103            self.kernel_module = s_kernel 
     2104            params = modelinfo.ParameterTable(self.kernel_module._model_info.parameters.kernel_parameters) 
     2105            new_rows = FittingUtilities.addSimpleParametersToModel(params, self.is2D) 
     2106        else: 
     2107            p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
     2108            s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) 
     2109 
     2110            self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
     2111            all_params = self.kernel_module._model_info.parameters.kernel_parameters 
     2112            all_param_names = [param.name for param in all_params] 
     2113 
     2114            # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any 
     2115            # conflicting names with P(Q) params will cause a rename; we also lose radius_effective (for now...) 
     2116 
     2117            # TODO: merge rest of beta approx implementation in 
     2118            # This is to ensure compatibility when we merge beta approx support in...! 
     2119 
     2120            # radius_effective is always s_params[0] 
     2121 
     2122            # if radius_effective_mode is in all_params, then all_params contains radius_effective and we want to 
     2123            # keep it in the model 
     2124 
     2125            # if radius_effective_mode is NOT in all_params, then radius_effective should NOT be kept, because the user 
     2126            # cannot specify it themselves; but, make sure we only remove it if it's actually there in the first place 
     2127            # (sasmodels master removes it already) 
     2128            if "radius_effective_mode" in all_param_names: 
     2129                # Show all parameters 
     2130                s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 
     2131                s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 
     2132            else: 
     2133                # Ensure radius_effective is not displayed 
     2134                s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
     2135                if "radius_effective" in all_param_names: 
     2136                    s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 
     2137                else: 
     2138                    s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 
     2139 
     2140            # Get new rows for QModel 
     2141            # Any renamed parameters are stored as data in the relevant item, for later handling 
     2142            new_rows = FittingUtilities.addSimpleParametersToModel(s_params, self.is2D, s_params_orig) 
     2143 
     2144            # TODO: merge rest of beta approx implementation in 
     2145            # These parameters are not part of P(Q) nor S(Q), but are added only to the product model (e.g. specifying 
     2146            # structure factor calculation mode) 
     2147            # product_params = all_params[p_pars_len+s_pars_len:] 
     2148 
     2149        # Add heading row 
     2150        FittingUtilities.addHeadingRowToModel(self._model_model, structure_factor) 
     2151 
     2152        # Update QModel 
    20842153        for row in new_rows: 
    20852154            self._model_model.appendRow(row) 
    20862155            # 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() 
     2156            # if row[0].text() not in self.kernel_module.params.keys(): 
     2157            #     row_num = self._model_model.rowCount() - 1 
     2158            #     FittingUtilities.markParameterDisabled(self._model_model, row_num) 
    20932159 
    20942160    def haveParamsToFit(self): 
     
    21162182        model_row = item.row() 
    21172183        name_index = self._model_model.index(model_row, 0) 
     2184        name_item = self._model_model.itemFromIndex(name_index) 
    21182185 
    21192186        # Extract changed value. 
     
    21242191            return 
    21252192 
    2126         parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 
     2193        # if the item has user data, this is the actual parameter name (e.g. to handle duplicate names) 
     2194        if name_item.data(QtCore.Qt.UserRole): 
     2195            parameter_name = str(name_item.data(QtCore.Qt.UserRole)) 
     2196        else: 
     2197            parameter_name = str(self._model_model.data(name_index)) 
    21272198 
    21282199        # Update the parameter value - note: this supports +/-inf as well 
     
    23522423            new_plots.append(plot) 
    23532424 
    2354         # Update/generate plots 
    23552425        for plot in new_plots: 
    23562426            self.communicate.plotUpdateSignal.emit([plot]) 
     
    25522622        def updateFunctionCaption(row): 
    25532623            # Utility function for update of polydispersity function name in the main model 
     2624            if not self.isCheckable(row): 
     2625                return 
     2626            self._model_model.blockSignals(True) 
    25542627            param_name = str(self._model_model.item(row, 0).text()) 
     2628            self._model_model.blockSignals(False) 
    25552629            if param_name !=  param.name: 
    25562630                return 
    25572631            # Modify the param value 
     2632            self._model_model.blockSignals(True) 
    25582633            if self.has_error_column: 
    25592634                # err column changes the indexing 
     
    25612636            else: 
    25622637                self._model_model.item(row, 0).child(0).child(0,4).setText(combo_string) 
     2638            self._model_model.blockSignals(False) 
    25632639 
    25642640        if combo_string == 'array': 
     
    27202796 
    27212797        self.lstParams.setIndexWidget(shell_index, func) 
    2722         self._last_model_row = self._model_model.rowCount() 
     2798        self._n_shells_row = shell_row - 1 
    27232799 
    27242800        # Set the index to the state-kept value 
     
    27312807        """ 
    27322808        # Find row location of the combobox 
    2733         last_row = self._last_model_row 
    2734         remove_rows = self._model_model.rowCount() - last_row 
     2809        first_row = self._n_shells_row + 1 
     2810        remove_rows = self._num_shell_params 
    27352811 
    27362812        if remove_rows > 1: 
    2737             self._model_model.removeRows(last_row, remove_rows) 
    2738  
    2739         FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index) 
     2813            self._model_model.removeRows(first_row, remove_rows) 
     2814 
     2815        new_rows = FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index, first_row) 
     2816        self._num_shell_params = len(new_rows) 
     2817 
    27402818        self.current_shell_displayed = index 
    27412819 
Note: See TracChangeset for help on using the changeset viewer.