Changeset f3a19ad in sasview for src/sas/qtgui/Perspectives/Fitting


Ignore:
Timestamp:
Sep 4, 2018 10:19:33 AM (6 years ago)
Author:
Torin Cooper-Bennun <torin.cooper-bennun@…>
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:
70f4458
Parents:
c7809a9
Message:

refactor & fix param handling; test fixes

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

Legend:

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

    rc7809a9 rf3a19ad  
    19551955        # Crete/overwrite model items 
    19561956        self._model_model.clear() 
    1957  
    1958         # First, add parameters from the main model 
    1959         if model_name is not None: 
     1957        self._poly_model.clear() 
     1958        self._magnet_model.clear() 
     1959 
     1960        if model_name is None: 
     1961            if structure_factor not in (None, "None"): 
     1962                # S(Q) on its own, treat the same as a form factor 
     1963                self.kernel_module = None 
     1964                self.fromStructureFactorToQModel(structure_factor) 
     1965            else: 
     1966                # No models selected 
     1967                return 
     1968        else: 
    19601969            self.fromModelToQModel(model_name) 
    1961  
    1962         # Then, add structure factor derived parameters 
    1963         if structure_factor is not None and structure_factor != "None": 
    1964             if model_name is None: 
    1965                 # Instantiate the current sasmodel for SF-only models 
    1966                 self.kernel_module = self.models[structure_factor]() 
    1967             self.fromStructureFactorToQModel(structure_factor) 
    1968         else: 
    1969             # Allow the SF combobox visibility for the given sasmodel 
    1970             self.enableStructureFactorControl(structure_factor) 
     1970            if structure_factor not in (None, "None"): 
     1971                # add S(Q) 
     1972                self.fromStructureFactorToQModel(structure_factor) 
     1973            else: 
     1974                # enable selection of S(Q) 
     1975                self.enableStructureFactorControl(structure_factor) 
     1976            # Add polydispersity to the model 
     1977            self.setPolyModel() 
     1978            # Add magnetic parameters to the model 
     1979            self.setMagneticModel() 
    19711980 
    19721981        # Then, add multishells 
     
    19741983            # Multishell models need additional treatment 
    19751984            self.addExtraShells() 
    1976  
    1977         # Add polydispersity to the model 
    1978         self.setPolyModel() 
    1979         # Add magnetic parameters to the model 
    1980         self.setMagneticModel() 
    19811985 
    19821986        # Adjust the table cells width 
     
    20592063        Setting model parameters into QStandardItemModel based on selected _structure factor_ 
    20602064        """ 
    2061         structure_module = generate.load_kernel_module(structure_factor) 
    2062  
    20632065        s_kernel = self.models[structure_factor]() 
    20642066        p_kernel = self.kernel_module 
    20652067 
    2066         p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
    2067         s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) - 1 # no radius_effective 
    2068  
    2069         self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
    2070         all_params = self.kernel_module._model_info.parameters.kernel_parameters 
    2071         all_param_names = [param.name for param in all_params] 
    2072  
    2073         # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any conflicting 
    2074         # names with P(Q) params will cause a rename; we also lose radius_effective (for now...) 
    2075  
    2076         if "radius_effective_mode" in all_param_names: 
    2077             # for this version of sasmodels we do NOT kill radius_effective 
    2078             s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 
    2079             s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 
     2068        if p_kernel is None: 
     2069            # Not a product model, just S(Q) 
     2070            self.kernel_module = s_kernel 
     2071            params = modelinfo.ParameterTable(self.kernel_module._model_info.parameters.kernel_parameters) 
     2072            new_rows = FittingUtilities.addSimpleParametersToModel(params, self.is2D) 
    20802073        else: 
    2081             # kill radius_effective 
    2082             s_pars_len -= 1 
    2083             s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 
    2084             s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
    2085  
    2086         # Get new rows for QModel 
    2087         # Any renamed parameters are stored as data in the relevant item, for later handling 
    2088         new_rows = FittingUtilities.addSimpleParametersToModel(s_params, self.is2D, s_params_orig) 
    2089  
    2090         # TODO: merge the rest of this implementation in 
    2091         # These parameters are not part of P(Q) nor S(Q), but are added only to the product model (e.g. specifying 
    2092         # structure factor calculation mode) 
    2093         # product_params = all_params[p_pars_len+s_pars_len:] 
     2074            p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
     2075            s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) 
     2076 
     2077            self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
     2078            all_params = self.kernel_module._model_info.parameters.kernel_parameters 
     2079            all_param_names = [param.name for param in all_params] 
     2080 
     2081            # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any 
     2082            # conflicting names with P(Q) params will cause a rename; we also lose radius_effective (for now...) 
     2083 
     2084            # TODO: merge rest of beta approx implementation in 
     2085            # This is to ensure compatibility when we merge beta approx support in...! 
     2086 
     2087            # radius_effective is always s_params[0] 
     2088 
     2089            # if radius_effective_mode is in all_params, then all_params contains radius_effective and we want to 
     2090            # keep it in the model 
     2091 
     2092            # if radius_effective_mode is NOT in all_params, then radius_effective should NOT be kept, because the user 
     2093            # cannot specify it themselves; but, make sure we only remove it if it's actually there in the first place 
     2094            # (sasmodels master removes it already) 
     2095            if "radius_effective_mode" in all_param_names: 
     2096                # Show all parameters 
     2097                s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 
     2098                s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 
     2099            else: 
     2100                # Ensure radius_effective is not displayed 
     2101                s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
     2102                if "radius_effective" in all_param_names: 
     2103                    s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 
     2104                else: 
     2105                    s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 
     2106 
     2107            # Get new rows for QModel 
     2108            # Any renamed parameters are stored as data in the relevant item, for later handling 
     2109            new_rows = FittingUtilities.addSimpleParametersToModel(s_params, self.is2D, s_params_orig) 
     2110 
     2111            # TODO: merge rest of beta approx implementation in 
     2112            # These parameters are not part of P(Q) nor S(Q), but are added only to the product model (e.g. specifying 
     2113            # structure factor calculation mode) 
     2114            # product_params = all_params[p_pars_len+s_pars_len:] 
    20942115 
    20952116        # Add heading row 
     
    21002121            self._model_model.appendRow(row) 
    21012122            # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 
    2102             if row[0].text() not in self.kernel_module.params.keys(): 
    2103                 row_num = self._model_model.rowCount() - 1 
    2104                 FittingUtilities.markParameterDisabled(self._model_model, row_num) 
     2123            # if row[0].text() not in self.kernel_module.params.keys(): 
     2124            #     row_num = self._model_model.rowCount() - 1 
     2125            #     FittingUtilities.markParameterDisabled(self._model_model, row_num) 
    21052126 
    21062127        # Update the counter used for multishell display 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r00b7ddf0 rf3a19ad  
    254254        self.widget.cbStructureFactor.setCurrentIndex(structure_index) 
    255255 
    256         # We have 4 more rows now 
    257         self.assertEqual(self.widget._model_model.rowCount(), rowcount+5) 
     256        # We have 3 more param rows now (radius_effective is removed), and a new heading 
     257        self.assertEqual(self.widget._model_model.rowCount(), rowcount+4) 
    258258 
    259259        # Switch models 
     
    274274        last_index = self.widget.cbStructureFactor.count() 
    275275        self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 
    276         # Do we have all the rows? 
     276        # Do we have all the rows (incl. radius_effective & heading row)? 
    277277        self.assertEqual(self.widget._model_model.rowCount(), 5) 
    278278 
Note: See TracChangeset for help on using the changeset viewer.