Changes in / [b69b549:bc7371fd] in sasview


Ignore:
Location:
src/sas/qtgui
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/MainWindow/DataExplorer.py

    r60d55a7 rfd7ef36  
    560560        # Now query the model item for available plots 
    561561        plots = GuiUtils.plotsFromFilename(filename, model) 
     562        ids_keys = list(self.active_plots.keys()) 
     563        ids_vals = [val.data.id for val in self.active_plots.values()] 
    562564 
    563565        new_plots = [] 
    564566        for item, plot in plots.items(): 
    565             if not self.updatePlot(plot): 
     567            plot_id = plot.id 
     568            if plot_id in ids_keys: 
     569                self.active_plots[plot_id].replacePlot(plot_id, plot) 
     570            elif plot_id in ids_vals: 
     571                list(self.active_plots.values())[ids_vals.index(plot_id)].replacePlot(plot_id, plot) 
     572            else: 
    566573                # Don't plot intermediate results, e.g. P(Q), S(Q) 
    567                 match = GuiUtils.theory_plot_ID_pattern.match(plot.id) 
     574                match = GuiUtils.theory_plot_ID_pattern.match(plot_id) 
    568575                # 2nd match group contains the identifier for the intermediate result, if present (e.g. "[P(Q)]") 
    569576                if match and match.groups()[1] != None: 
     
    699706                self.active_plots[plot_set.id] = old_plot 
    700707 
    701     def updatePlot(self, data): 
    702         """ 
    703         Modify existing plot for immediate response and returns True. 
    704         Returns false, if the plot does not exist already. 
    705         """ 
    706         try: # there might be a list or a single value being passed 
    707             data = data[0] 
    708         except TypeError: 
    709             pass 
     708    def updatePlot(self, new_data): 
     709        """ 
     710        Modify existing plot for immediate response 
     711        """ 
     712        data = new_data[0] 
    710713        assert type(data).__name__ in ['Data1D', 'Data2D'] 
    711714 
     
    716719        if data_id in ids_keys: 
    717720            self.active_plots[data_id].replacePlot(data_id, data) 
    718             return True 
    719721        elif data_id in ids_vals: 
    720722            list(self.active_plots.values())[ids_vals.index(data_id)].replacePlot(data_id, data) 
    721             return True 
    722         return False 
    723723 
    724724    def chooseFiles(self): 
  • src/sas/qtgui/Perspectives/Fitting/FittingLogic.py

    rdcabba7 rb4d05bd  
    161161        Create a new 1D data instance based on fitting results 
    162162        """ 
    163  
    164         return self._create1DPlot(tab_id, return_data['x'], return_data['y'], 
    165                                   return_data['model'], return_data['data']) 
     163        # Unpack return data from Calc1D 
     164        x, y, page_id, state, weight,\ 
     165        fid, toggle_mode_on, \ 
     166        elapsed, index, model, \ 
     167        data, update_chisqr, source, \ 
     168        unsmeared_output, unsmeared_data, unsmeared_error, \ 
     169        pq_values, sq_values = return_data 
     170 
     171        return self._create1DPlot(tab_id, x, y, model, data) 
    166172 
    167173    def new2DPlot(self, return_data): 
     
    169175        Create a new 2D data instance based on fitting results 
    170176        """ 
    171         image = return_data['image'] 
    172         data = return_data['data'] 
    173         model = return_data['model'] 
     177        image, data, page_id, model, state, toggle_mode_on,\ 
     178        elapsed, index, fid, qmin, qmax, weight, \ 
     179        update_chisqr, source = return_data 
    174180 
    175181        np.nan_to_num(image) 
     
    177183        new_plot.name = model.name + '2d' 
    178184        new_plot.title = "Analytical model 2D " 
    179         new_plot.id = str(return_data['page_id']) + " " + data.name 
    180         new_plot.group_id = str(return_data['page_id']) + " Model2D" 
     185        new_plot.id = str(page_id) + " " + data.name 
     186        new_plot.group_id = str(page_id) + " Model2D" 
    181187        new_plot.detector = data.detector 
    182188        new_plot.source = data.source 
     
    212218        (pq_plot, sq_plot). If either are unavailable, the corresponding plot is None. 
    213219        """ 
     220        # Unpack return data from Calc1D 
     221        x, y, page_id, state, weight, \ 
     222        fid, toggle_mode_on, \ 
     223        elapsed, index, model, \ 
     224        data, update_chisqr, source, \ 
     225        unsmeared_output, unsmeared_data, unsmeared_error, \ 
     226        pq_values, sq_values = return_data 
    214227 
    215228        pq_plot = None 
    216229        sq_plot = None 
    217230 
    218         if return_data.get('pq_values', None) is not None: 
    219             pq_plot = self._create1DPlot(tab_id, return_data['x'], 
    220                     return_data['pq_values'], return_data['model'], 
    221                     return_data['data'], component="P(Q)") 
    222         if return_data.get('sq_values', None) is not None: 
    223             sq_plot = self._create1DPlot(tab_id, return_data['x'], 
    224                     return_data['sq_values'], return_data['model'], 
    225                     return_data['data'], component="S(Q)") 
     231        if pq_values is not None: 
     232            pq_plot = self._create1DPlot(tab_id, x, pq_values, model, data, component="P(Q)") 
     233        if sq_values is not None: 
     234            sq_plot = self._create1DPlot(tab_id, x, sq_values, model, data, component="S(Q)") 
    226235 
    227236        return pq_plot, sq_plot 
  • src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py

    r70f4458 rbc7371fd  
    167167    return rows 
    168168 
    169 def addSimpleParametersToModel(parameters, is2D, parameters_original=None, model=None, view=None): 
     169def addSimpleParametersToModel(parameters, is2D, model=None, view=None): 
    170170    """ 
    171171    Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 
    172172    Actually appends to model, if model and view params are not None. 
    173173    Always returns list of lists of QStandardItems. 
    174  
    175     parameters_original: list of parameters before any tagging on their IDs, e.g. for product model (so that those are 
    176     the display names; see below) 
    177174    """ 
    178175    if is2D: 
     
    181178        params = parameters.iq_parameters 
    182179 
    183     if parameters_original: 
    184         # 'parameters_original' contains the parameters as they are to be DISPLAYED, while 'parameters' 
    185         # contains the parameters as they were renamed; this is for handling name collisions in product model. 
    186         # The 'real name' of the parameter will be stored in the item's user data. 
    187         if is2D: 
    188             params_orig = [p for p in parameters_original.kernel_parameters if p.type != 'magnetic'] 
    189         else: 
    190             params_orig = parameters_original.iq_parameters 
    191     else: 
    192         # no difference in names anyway 
    193         params_orig = params 
    194  
    195180    rows = [] 
    196     for param, param_orig in zip(params, params_orig): 
     181    for param in params: 
    197182        # Create the top level, checkable item 
    198         item_name = param_orig.name 
     183        item_name = param.name 
    199184        item1 = QtGui.QStandardItem(item_name) 
    200         item1.setData(param.name, QtCore.Qt.UserRole) 
    201185        item1.setCheckable(True) 
    202186        item1.setEditable(False) 
     
    256240    model.appendRow(item_list) 
    257241 
    258 def addHeadingRowToModel(model, name): 
    259     """adds a non-interactive top-level row to the model""" 
    260     header_row = [QtGui.QStandardItem() for i in range(5)] 
    261     header_row[0].setText(name) 
    262  
    263     font = header_row[0].font() 
    264     font.setBold(True) 
    265     header_row[0].setFont(font) 
    266  
    267     for item in header_row: 
    268         item.setEditable(False) 
    269         item.setCheckable(False) 
    270         item.setSelectable(False) 
    271  
    272     model.appendRow(header_row) 
    273  
    274242def addHeadersToModel(model): 
    275243    """ 
     
    317285    model.header_tooltips = copy.copy(poly_header_error_tooltips) 
    318286 
    319 def addShellsToModel(parameters, model, index, row_num=None, view=None): 
    320     """ 
    321     Find out multishell parameters and update the model with the requested number of them. 
    322     Inserts them after the row at row_num, if not None; otherwise, appends to end. 
    323     If view param is not None, supports fixed-choice params. 
    324     Returns a list of lists of QStandardItem objects. 
     287def addShellsToModel(parameters, model, index, view=None): 
     288    """ 
     289    Find out multishell parameters and update the model with the requested number of them 
     290    Always appends to model. If view param is not None, supports fixed-choice params. 
     291    Returns list of lists of QStandardItems. 
    325292    """ 
    326293    multishell_parameters = getIterParams(parameters) 
     
    359326            cbox = createFixedChoiceComboBox(par, row) 
    360327 
    361             # Always add to the model 
    362             if row_num is None: 
    363                 model.appendRow(row) 
    364             else: 
    365                 model.insertRow(row_num, row) 
    366                 row_num += 1 
     328            # Always append to the model 
     329            model.appendRow(row) 
    367330 
    368331            # Apply combobox if required 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r0109f2a ra758043  
    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 = {} 
     
    248247        # copy of current kernel model 
    249248        self.kernel_module_copy = None 
    250  
    251         # dictionaries of current params 
    252         self.poly_params = {} 
    253         self.magnet_params = {} 
    254249 
    255250        # Page id for fitting 
     
    677672        Return list of all parameters for the current model 
    678673        """ 
    679         return [self._model_model.item(row).text() 
    680                 for row in range(self._model_model.rowCount()) 
    681                 if self.isCheckable(row)] 
     674        return [self._model_model.item(row).text() for row in range(self._model_model.rowCount())] 
    682675 
    683676    def modifyViewOnRow(self, row, font=None, brush=None): 
     
    707700        assert isinstance(constraint, Constraint) 
    708701        assert 0 <= row <= self._model_model.rowCount() 
    709         assert self.isCheckable(row) 
    710702 
    711703        item = QtGui.QStandardItem() 
     
    728720        max_col = self.lstParams.itemDelegate().param_max 
    729721        for row in self.selectedParameters(): 
    730             assert(self.isCheckable(row)) 
    731722            param = self._model_model.item(row, 0).text() 
    732723            value = self._model_model.item(row, 1).text() 
     
    771762        max_col = self.lstParams.itemDelegate().param_max 
    772763        for row in range(self._model_model.rowCount()): 
    773             if not self.isCheckable(row): 
    774                 continue 
    775764            if not self.rowHasConstraint(row): 
    776765                continue 
     
    801790        For the given row, return its constraint, if any 
    802791        """ 
    803         if self.isCheckable(row): 
     792        try: 
    804793            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 
     794            return item.child(0).data() 
     795        except AttributeError: 
     796            # return none when no constraints 
     797            return None 
    811798 
    812799    def rowHasConstraint(self, row): 
     
    814801        Finds out if row of the main model has a constraint child 
    815802        """ 
    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 
     803        item = self._model_model.item(row, 1) 
     804        if item.hasChildren(): 
     805            c = item.child(0).data() 
     806            if isinstance(c, Constraint): 
     807                return True 
    822808        return False 
    823809 
     
    826812        Finds out if row of the main model has an active constraint child 
    827813        """ 
    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 
     814        item = self._model_model.item(row, 1) 
     815        if item.hasChildren(): 
     816            c = item.child(0).data() 
     817            if isinstance(c, Constraint) and c.active: 
     818                return True 
    834819        return False 
    835820 
     
    838823        Finds out if row of the main model has an active, nontrivial constraint child 
    839824        """ 
    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 
     825        item = self._model_model.item(row, 1) 
     826        if item.hasChildren(): 
     827            c = item.child(0).data() 
     828            if isinstance(c, Constraint) and c.func and c.active: 
     829                return True 
    846830        return False 
    847831 
     
    12021186            # Update the sasmodel 
    12031187            # PD[ratio] -> width, npts -> npts, nsigs -> nsigmas 
    1204             #self.kernel_module.setParam(parameter_name + '.' + delegate.columnDict()[model_column], value) 
    1205             key = parameter_name + '.' + delegate.columnDict()[model_column] 
    1206             self.poly_params[key] = value 
     1188            self.kernel_module.setParam(parameter_name + '.' + delegate.columnDict()[model_column], value) 
    12071189 
    12081190            # Update plot 
     
    12131195            row = self.getRowFromName(parameter_name) 
    12141196            param_item = self._model_model.item(row) 
    1215             self._model_model.blockSignals(True) 
    12161197            param_item.child(0).child(0, model_column).setText(item.text()) 
    1217             self._model_model.blockSignals(False) 
    12181198 
    12191199    def onMagnetModelChange(self, item): 
     
    12441224            # Unparsable field 
    12451225            return 
    1246         delegate = self.lstMagnetic.itemDelegate() 
    1247  
    1248         if model_column > 1: 
    1249             if model_column == delegate.mag_min: 
    1250                 pos = 1 
    1251             elif model_column == delegate.mag_max: 
    1252                 pos = 2 
    1253             elif model_column == delegate.mag_unit: 
    1254                 pos = 0 
    1255             else: 
    1256                 raise AttributeError("Wrong column in magnetism table.") 
    1257             # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 
    1258             self.kernel_module.details[parameter_name][pos] = value 
    1259         else: 
    1260             self.magnet_params[parameter_name] = value 
    1261             #self.kernel_module.setParam(parameter_name) = value 
    1262             # Force the chart update when actual parameters changed 
     1226 
     1227        property_index = self._magnet_model.headerData(1, model_column)-1 # Value, min, max, etc. 
     1228 
     1229        # Update the parameter value - note: this supports +/-inf as well 
     1230        self.kernel_module.params[parameter_name] = value 
     1231 
     1232        # min/max to be changed in self.kernel_module.details[parameter_name] = ['Ang', 0.0, inf] 
     1233        self.kernel_module.details[parameter_name][property_index] = value 
     1234 
     1235        # Force the chart update when actual parameters changed 
     1236        if model_column == 1: 
    12631237            self.recalculatePlotData() 
    12641238 
     
    15211495        # Data going in 
    15221496        data = self.logic.data 
    1523         model = copy.deepcopy(self.kernel_module) 
     1497        model = self.kernel_module 
    15241498        qmin = self.q_range_min 
    15251499        qmax = self.q_range_max 
    1526         # add polydisperse/magnet parameters if asked 
    1527         self.updateKernelModelWithExtraParams(model) 
    15281500 
    15291501        params_to_fit = self.main_params_to_fit 
     
    15891561            # internal so can use closure for param_dict 
    15901562            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()): 
     1563            if param_name not in list(param_dict.keys()): 
    15921564                return 
    15931565            # modify the param value 
     
    16011573            # Utility function for updateof polydispersity part of the main model 
    16021574            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()): 
     1575            if param_name not in list(param_dict.keys()): 
    16041576                return 
    16051577            # modify the param value 
     
    19781950        # Crete/overwrite model items 
    19791951        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 
     1952 
     1953        # First, add parameters from the main model 
     1954        if model_name is not None: 
     1955            self.fromModelToQModel(model_name) 
     1956 
     1957        # Then, add structure factor derived parameters 
     1958        if structure_factor is not None and structure_factor != "None": 
     1959            if model_name is None: 
     1960                # Instantiate the current sasmodel for SF-only models 
     1961                self.kernel_module = self.models[structure_factor]() 
     1962            self.fromStructureFactorToQModel(structure_factor) 
    19911963        else: 
    1992             self.fromModelToQModel(model_name) 
    1993             self.addExtraShells() 
    1994  
    19951964            # Allow the SF combobox visibility for the given sasmodel 
    19961965            self.enableStructureFactorControl(structure_factor) 
    1997          
    1998             # Add S(Q) 
    19991966            if self.cbStructureFactor.isEnabled(): 
    20001967                structure_factor = self.cbStructureFactor.currentText() 
    20011968                self.fromStructureFactorToQModel(structure_factor) 
    20021969 
    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() 
     1970        # Then, add multishells 
     1971        if model_name is not None: 
     1972            # Multishell models need additional treatment 
     1973            self.addExtraShells() 
     1974 
     1975        # Add polydispersity to the model 
     1976        self.setPolyModel() 
     1977        # Add magnetic parameters to the model 
     1978        self.setMagneticModel() 
    20091979 
    20101980        # Adjust the table cells width 
     
    20792049        self.shell_names = self.shellNamesList() 
    20802050 
    2081         # Add heading row 
    2082         FittingUtilities.addHeadingRowToModel(self._model_model, model_name) 
    2083  
    20842051        # Update the QModel 
    20852052        FittingUtilities.addParametersToModel( 
     
    20902057                self.lstParams) 
    20912058 
     2059        # Update the counter used for multishell display 
     2060        self._last_model_row = self._model_model.rowCount() 
     2061 
    20922062    def fromStructureFactorToQModel(self, structure_factor): 
    20932063        """ 
     
    20962066        if structure_factor is None or structure_factor=="None": 
    20972067            return 
    2098  
    2099         s_kernel = self.models[structure_factor]() 
    2100         p_kernel = self.kernel_module 
    2101  
    2102         # if p_kernel is None: 
    2103         #     # Not a product model, just S(Q) 
    2104         #     self.kernel_module = s_kernel 
    2105         #     params = modelinfo.ParameterTable(self.kernel_module._model_info.parameters.kernel_parameters) 
    2106         #     FittingUtilities.addSimpleParametersToModel(params, self.is2D) 
    2107         # else: 
    2108         p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
    2109         s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) 
    2110  
    2111         self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
    2112         all_params = self.kernel_module._model_info.parameters.kernel_parameters 
    2113         all_param_names = [param.name for param in all_params] 
    2114  
    2115         # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any 
    2116         # conflicting names with P(Q) params will cause a rename 
    2117  
    2118         if "radius_effective_mode" in all_param_names: 
    2119             # Show all parameters 
    2120             s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len]) 
    2121             s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters) 
    2122         else: 
    2123             # Ensure radius_effective is not displayed 
    2124             s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
    2125             if "radius_effective" in all_param_names: 
    2126                 s_params = modelinfo.ParameterTable(all_params[p_pars_len+1:p_pars_len+s_pars_len]) 
    2127             else: 
    2128                 s_params = modelinfo.ParameterTable(all_params[p_pars_len:p_pars_len+s_pars_len-1]) 
    2129  
    2130         # Add heading row 
    2131         FittingUtilities.addHeadingRowToModel(self._model_model, structure_factor) 
    2132  
    2133         # Get new rows for QModel 
    2134         # Any renamed parameters are stored as data in the relevant item, for later handling 
     2068        structure_module = generate.load_kernel_module(structure_factor) 
     2069        structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
     2070 
     2071        structure_kernel = self.models[structure_factor]() 
     2072        form_kernel = self.kernel_module 
     2073 
     2074        self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 
     2075 
     2076        # Update the QModel 
    21352077        FittingUtilities.addSimpleParametersToModel( 
    2136                 s_params, 
     2078                structure_parameters, 
    21372079                self.is2D, 
    2138                 s_params_orig, 
    21392080                self._model_model, 
    21402081                self.lstParams) 
     2082 
     2083        # Any parameters removed from the structure factor when producing the product model, e.g. radius_effective, must 
     2084        # be disabled (greyed out, etc.) 
     2085        for r in range(self._last_model_row, self._model_model.rowCount()): 
     2086            param_name = self._model_model.item(r, 0).text() 
     2087            if param_name not in self.kernel_module.params.keys(): 
     2088                FittingUtilities.markParameterDisabled(self._model_model, r) 
     2089 
     2090        # Update the counter used for multishell display 
     2091        self._last_model_row = self._model_model.rowCount() 
    21412092 
    21422093    def haveParamsToFit(self): 
     
    21642115        model_row = item.row() 
    21652116        name_index = self._model_model.index(model_row, 0) 
    2166         name_item = self._model_model.itemFromIndex(name_index) 
    21672117 
    21682118        # Extract changed value. 
     
    21732123            return 
    21742124 
    2175         # if the item has user data, this is the actual parameter name (e.g. to handle duplicate names) 
    2176         if name_item.data(QtCore.Qt.UserRole): 
    2177             parameter_name = str(name_item.data(QtCore.Qt.UserRole)) 
    2178         else: 
    2179             parameter_name = str(self._model_model.data(name_index)) 
     2125        parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 
    21802126 
    21812127        # Update the parameter value - note: this supports +/-inf as well 
     
    23002246        return self.completed1D if isinstance(self.data, Data1D) else self.completed2D 
    23012247 
    2302     def updateKernelModelWithExtraParams(self, model=None): 
    2303         """ 
    2304         Updates kernel model 'model' with extra parameters from 
    2305         the polydisp and magnetism tab, if the tabs are enabled 
    2306         """ 
    2307         if model is None: return 
    2308         if not hasattr(model, 'setParam'): return 
    2309  
    2310         # add polydisperse parameters if asked 
    2311         if self.chkPolydispersity.isChecked(): 
    2312             for key, value in self.poly_params.items(): 
    2313                 model.setParam(key, value) 
    2314         # add magnetic params if asked 
    2315         if self.chkMagnetism.isChecked(): 
    2316             for key, value in self.magnet_params.items(): 
    2317                 model.setParam(key, value) 
    2318  
    23192248    def calculateQGridForModelExt(self, data=None, model=None, completefn=None, use_threads=True): 
    23202249        """ 
     
    23242253            data = self.data 
    23252254        if model is None: 
    2326             model = copy.deepcopy(self.kernel_module) 
    2327             self.updateKernelModelWithExtraParams(model) 
    2328  
     2255            model = self.kernel_module 
    23292256        if completefn is None: 
    23302257            completefn = self.methodCompleteForData() 
     
    24112338            new_plots.append(sq_data) 
    24122339 
    2413         for plot in new_plots: 
    2414             self.communicate.plotUpdateSignal.emit([plot]) 
    2415  
    2416     def complete2D(self, return_data): 
    2417         """ 
    2418         Plot the current 2D data 
    2419         """ 
    2420         fitted_data = self.logic.new2DPlot(return_data) 
    2421         residuals = self.calculateResiduals(fitted_data) 
    2422         self.model_data = fitted_data 
    2423         new_plots = [fitted_data] 
    2424         if residuals is not None: 
    2425             new_plots.append(residuals) 
    2426  
    24272340        # Update/generate plots 
    24282341        for plot in new_plots: 
    24292342            self.communicate.plotUpdateSignal.emit([plot]) 
     2343 
     2344    def complete2D(self, return_data): 
     2345        """ 
     2346        Plot the current 2D data 
     2347        """ 
     2348        fitted_data = self.logic.new2DPlot(return_data) 
     2349        self.calculateResiduals(fitted_data) 
     2350        self.model_data = fitted_data 
    24302351 
    24312352    def calculateResiduals(self, fitted_data): 
     
    25582479        _, min, max = self.kernel_module.details[param_name] 
    25592480 
    2560         # Update local param dict 
    2561         self.poly_params[param_name + '.width'] = width 
    2562         self.poly_params[param_name + '.npts'] = npts 
    2563         self.poly_params[param_name + '.nsigmas'] = nsigs 
    2564  
    25652481        # Construct a row with polydisp. related variable. 
    25662482        # This will get added to the polydisp. model 
     
    26102526        def updateFunctionCaption(row): 
    26112527            # Utility function for update of polydispersity function name in the main model 
    2612             if not self.isCheckable(row): 
    2613                 return 
    2614             self._model_model.blockSignals(True) 
    26152528            param_name = str(self._model_model.item(row, 0).text()) 
    2616             self._model_model.blockSignals(False) 
    26172529            if param_name !=  param.name: 
    26182530                return 
    26192531            # Modify the param value 
    2620             self._model_model.blockSignals(True) 
    26212532            if self.has_error_column: 
    26222533                # err column changes the indexing 
     
    26242535            else: 
    26252536                self._model_model.item(row, 0).child(0).child(0,4).setText(combo_string) 
    2626             self._model_model.blockSignals(False) 
    26272537 
    26282538        if combo_string == 'array': 
     
    27432653                        param.units] 
    27442654 
    2745         self.magnet_params[param.name] = param.default 
    2746  
    27472655        FittingUtilities.addCheckedListToModel(model, checked_list) 
    27482656 
     
    27842692 
    27852693        self.lstParams.setIndexWidget(shell_index, func) 
    2786         self._n_shells_row = shell_row - 1 
     2694        self._last_model_row = self._model_model.rowCount() 
    27872695 
    27882696        # Set the index to the state-kept value 
     
    27952703        """ 
    27962704        # Find row location of the combobox 
    2797         first_row = self._n_shells_row + 1 
    2798         remove_rows = self._num_shell_params 
     2705        last_row = self._last_model_row 
     2706        remove_rows = self._model_model.rowCount() - last_row 
    27992707 
    28002708        if remove_rows > 1: 
    2801             self._model_model.removeRows(first_row, remove_rows) 
    2802  
    2803         new_rows = FittingUtilities.addShellsToModel( 
     2709            self._model_model.removeRows(last_row, remove_rows) 
     2710 
     2711        FittingUtilities.addShellsToModel( 
    28042712                self.model_parameters, 
    28052713                self._model_model, 
    28062714                index, 
    2807                 first_row, 
    28082715                self.lstParams) 
    28092716 
    2810         self._num_shell_params = len(new_rows) 
    28112717        self.current_shell_displayed = index 
    28122718 
  • src/sas/qtgui/Perspectives/Fitting/ModelThread.py

    rdcabba7 r2df558e  
    101101        elapsed = time.time() - self.starttime 
    102102 
    103         res = dict(image = output, data = self.data, page_id = self.page_id, 
    104             model = self.model, state = self.state, 
    105             toggle_mode_on = self.toggle_mode_on, elapsed = elapsed, 
    106             index = index_model, fid = self.fid, 
    107             qmin = self.qmin, qmax = self.qmax, 
    108             weight = self.weight, update_chisqr = self.update_chisqr, 
    109             source = self.source) 
    110  
    111103        if LocalConfig.USING_TWISTED: 
    112             return res 
    113         else: 
    114             self.completefn(res) 
     104            return (output, 
     105                    self.data, 
     106                    self.page_id, 
     107                    self.model, 
     108                    self.state, 
     109                    self.toggle_mode_on, 
     110                    elapsed, 
     111                    index_model, 
     112                    self.fid, 
     113                    self.qmin, 
     114                    self.qmax, 
     115                    self.weight, 
     116                    self.update_chisqr, 
     117                    self.source) 
     118        else: 
     119            self.completefn((output, 
     120                           self.data, 
     121                           self.page_id, 
     122                           self.model, 
     123                           self.state, 
     124                           self.toggle_mode_on, 
     125                           elapsed, 
     126                           index_model, 
     127                           self.fid, 
     128                           self.qmin, 
     129                           self.qmax, 
     130                           self.weight, 
     131                           #qstep=self.qstep, 
     132                           self.update_chisqr, 
     133                           self.source)) 
     134 
    115135 
    116136class Calc1D(CalcThread): 
     
    216236        elapsed = time.time() - self.starttime 
    217237 
    218         res = dict(x = self.data.x[index], y = output[index], 
    219             page_id = self.page_id, state = self.state, weight = self.weight, 
    220             fid = self.fid, toggle_mode_on = self.toggle_mode_on, 
    221             elapsed = elapsed, index = index, model = self.model, 
    222             data = self.data, update_chisqr = self.update_chisqr, 
    223             source = self.source, unsmeared_output = unsmeared_output, 
    224             unsmeared_data = unsmeared_data, unsmeared_error = unsmeared_error, 
    225             pq_values = pq_values, sq_values = sq_values) 
    226  
    227238        if LocalConfig.USING_TWISTED: 
    228             return res 
    229         else: 
    230             self.completefn(res) 
     239            return (self.data.x[index], output[index], 
     240                    self.page_id, 
     241                    self.state, 
     242                    self.weight, 
     243                    self.fid, 
     244                    self.toggle_mode_on, 
     245                    elapsed, index, self.model, 
     246                    self.data, 
     247                    self.update_chisqr, 
     248                    self.source, 
     249                    unsmeared_output, unsmeared_data, unsmeared_error, 
     250                    pq_values, sq_values) 
     251        else: 
     252            self.completefn((self.data.x[index], output[index], 
     253                        self.page_id, 
     254                        self.state, 
     255                        self.weight, 
     256                        self.fid, 
     257                        self.toggle_mode_on, 
     258                        elapsed, index, self.model, 
     259                        self.data, 
     260                        self.update_chisqr, 
     261                        self.source, 
     262                        unsmeared_output, unsmeared_data, unsmeared_error, 
     263                        pq_values, sq_values)) 
    231264 
    232265    def results(self): 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r3fbd77b r605d944  
    256256        self.widget.cbStructureFactor.setCurrentIndex(structure_index) 
    257257 
    258         # We have 3 more param rows now (radius_effective is removed), and a new heading 
     258        # We have 4 more rows now 
    259259        self.assertEqual(self.widget._model_model.rowCount(), rowcount+4) 
    260260 
     
    276276        last_index = self.widget.cbStructureFactor.count() 
    277277        self.widget.cbStructureFactor.setCurrentIndex(last_index-1) 
    278         # Do we have all the rows (incl. radius_effective & heading row)? 
    279         self.assertEqual(self.widget._model_model.rowCount(), 5) 
     278        # Do we have all the rows? 
     279        self.assertEqual(self.widget._model_model.rowCount(), 4) 
    280280 
    281281        # Are the command buttons properly enabled? 
     
    445445        self.assertEqual(self.widget.kernel_module.details['radius_bell'][1], 1.0) 
    446446 
    447         #self.widget.show() 
    448         #QtWidgets.QApplication.exec_() 
    449  
    450447        # Change the number of points 
    451         self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 
     448        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 35) 
    452449        self.widget._poly_model.item(0,4).setText("22") 
    453         self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 
     450        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 22) 
    454451        # try something stupid 
    455452        self.widget._poly_model.item(0,4).setText("butt") 
    456453        # see that this didn't annoy the control at all 
    457         self.assertEqual(self.widget.poly_params['radius_bell.npts'], 22) 
     454        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 22) 
    458455 
    459456        # Change the number of sigmas 
    460         self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 3) 
     457        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 3) 
    461458        self.widget._poly_model.item(0,5).setText("222") 
    462         self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 
     459        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 222) 
    463460        # try something stupid again 
    464461        self.widget._poly_model.item(0,4).setText("beer") 
    465462        # no efect 
    466         self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 222) 
     463        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 222) 
    467464 
    468465    def testOnPolyComboIndexChange(self): 
     
    485482        self.widget.onPolyComboIndexChange('rectangle', 0) 
    486483        # check values 
    487         self.assertEqual(self.widget.poly_params['radius_bell.npts'], 35) 
    488         self.assertAlmostEqual(self.widget.poly_params['radius_bell.nsigmas'], 1.73205, 5) 
     484        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 35) 
     485        self.assertAlmostEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 1.73205, 5) 
    489486        # Change the index 
    490487        self.widget.onPolyComboIndexChange('lognormal', 0) 
    491488        # check values 
    492         self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 
    493         self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 
     489        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 80) 
     490        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 8) 
    494491        # Change the index 
    495492        self.widget.onPolyComboIndexChange('schulz', 0) 
    496493        # check values 
    497         self.assertEqual(self.widget.poly_params['radius_bell.npts'], 80) 
    498         self.assertEqual(self.widget.poly_params['radius_bell.nsigmas'], 8) 
     494        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.npts'), 80) 
     495        self.assertEqual(self.widget.kernel_module.getParam('radius_bell.nsigmas'), 8) 
    499496 
    500497        # mock up file load 
     
    509506        Test opening of the load file dialog for 'array' polydisp. function 
    510507        """ 
    511  
    512         # open a non-existent file 
    513508        filename = os.path.join("UnitTesting", "testdata_noexist.txt") 
    514         with self.assertRaises(OSError, msg="testdata_noexist.txt should be a non-existent file"): 
    515             os.stat(filename) 
    516509        QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 
    517510        self.widget.show() 
     
    529522 
    530523        # good file 
    531         # TODO: this depends on the working directory being src/sas/qtgui, 
    532         # TODO: which isn't convenient if you want to run this test suite 
    533         # TODO: individually 
    534524        filename = os.path.join("UnitTesting", "testdata.txt") 
    535         try: 
    536             os.stat(filename) 
    537         except OSError: 
    538             self.assertTrue(False, "testdata.txt does not exist") 
    539525        QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 
    540526 
     
    602588 
    603589        # Assure we have the combobox available 
    604         cbox_row = self.widget._n_shells_row 
    605         func_index = self.widget._model_model.index(cbox_row, 1) 
     590        last_row = self.widget._last_model_row 
     591        func_index = self.widget._model_model.index(last_row-1, 1) 
    606592        self.assertIsInstance(self.widget.lstParams.indexWidget(func_index), QtWidgets.QComboBox) 
    607  
    608         # get number of rows before changing shell count 
    609         last_row = self.widget._model_model.rowCount() 
    610593 
    611594        # Change the combo box index 
     
    10411024 
    10421025         # Check the model 
    1043         self.assertEqual(self.widget._model_model.rowCount(), 7) 
     1026        self.assertEqual(self.widget._model_model.rowCount(), 6) 
    10441027        self.assertEqual(self.widget._model_model.columnCount(), 5) 
    10451028 
     
    11571140        # two rows selected 
    11581141        index1 = self.widget.lstParams.model().index(1, 0, QtCore.QModelIndex()) 
    1159         index2 = self.widget.lstParams.model().index(3, 0, QtCore.QModelIndex()) 
     1142        index2 = self.widget.lstParams.model().index(2, 0, QtCore.QModelIndex()) 
    11601143        selection_model = self.widget.lstParams.selectionModel() 
    11611144        selection_model.select(index1, selection_model.Select | selection_model.Rows) 
     
    11931176        # several random parameters 
    11941177        self.assertEqual(self.widget.getRowFromName('scale'), 0) 
    1195         self.assertEqual(self.widget.getRowFromName('length'), 6) 
     1178        self.assertEqual(self.widget.getRowFromName('length'), 5) 
    11961179 
    11971180    def testGetParamNames(self): 
     
    12301213        # Create a constraint object 
    12311214        const = Constraint(parent=None, value=7.0) 
    1232         row = 3 
     1215        row = 2 
    12331216 
    12341217        spy = QtSignalSpy(self.widget, self.widget.constraintAddedSignal) 
     
    12491232        # assign complex constraint now 
    12501233        const = Constraint(parent=None, param='radius', func='5*sld') 
    1251         row = 5 
     1234        row = 4 
    12521235        # call the method tested 
    12531236        self.widget.addConstraintToRow(constraint=const, row=row) 
     
    13081291        self.widget.cbModel.setCurrentIndex(model_index) 
    13091292 
     1293        # select two rows 
    13101294        row1 = 1 
    1311         row2 = 5 
    1312  
    1313         param1 = "background" 
    1314         param2 = "radius" 
    1315  
    1316         #default_value1 = "0.001" 
    1317         default_value2 = "20" 
    1318  
    1319         # select two rows 
     1295        row2 = 4 
    13201296        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    13211297        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    13341310 
    13351311        # delete one of the constraints 
    1336         self.widget.deleteConstraintOnParameter(param=param1) 
     1312        self.widget.deleteConstraintOnParameter(param='background') 
    13371313 
    13381314        # see that the other constraint is still present 
    1339         cons = self.widget.getConstraintForRow(row2) 
    1340         self.assertEqual(cons.param, param2) 
    1341         self.assertEqual(cons.value, default_value2) 
     1315        cons = self.widget.getConstraintForRow(4) # 4 = radius 
     1316        self.assertEqual(cons.param, "radius") 
     1317        self.assertEqual(cons.value, "20") 
    13421318 
    13431319        # kill the other constraint 
     
    13451321 
    13461322        # see that the other constraint is still present 
    1347         self.assertEqual(self.widget.getConstraintsForModel(), [(param2, None)]) 
     1323        self.assertEqual(self.widget.getConstraintsForModel(), [('radius', None)]) 
    13481324 
    13491325    def testGetConstraintForRow(self): 
     
    13651341        self.widget.cbModel.setCurrentIndex(model_index) 
    13661342 
     1343        # select two rows 
    13671344        row1 = 1 
    1368         row2 = 5 
    1369  
    1370         # select two rows 
     1345        row2 = 4 
    13711346        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    13721347        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    13781353        self.widget.addSimpleConstraint() 
    13791354 
    1380         con_list = [False, True, False, False, False, True, False] 
     1355        con_list = [False, True, False, False, True, False] 
    13811356        new_list = [] 
    13821357        for row in range(self.widget._model_model.rowCount()): 
     
    13961371        self.widget.cbModel.setCurrentIndex(model_index) 
    13971372 
     1373        # select two rows 
    13981374        row1 = 1 
    1399         row2 = 5 
    1400  
    1401         # select two rows 
     1375        row2 = 4 
    14021376        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    14031377        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    14131387        constraint_objects[0].active = False 
    14141388 
    1415         con_list = [False, False, False, False, False, True, False] 
     1389        con_list = [False, False, False, False, True, False] 
    14161390        new_list = [] 
    14171391        for row in range(self.widget._model_model.rowCount()): 
     
    14341408        self.assertEqual(self.widget.getConstraintsForModel(),[]) 
    14351409 
     1410        # select two rows 
    14361411        row1 = 1 
    1437         row2 = 5 
    1438  
    1439         param1 = "background" 
    1440         param2 = "radius" 
    1441  
    1442         default_value1 = "0.001" 
    1443         default_value2 = "20" 
    1444  
    1445         # select two rows 
     1412        row2 = 4 
    14461413        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    14471414        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    14551422        # simple constraints 
    14561423        # self.assertEqual(self.widget.getConstraintsForModel(), [('background', '0.001'), ('radius', '20')]) 
    1457         cons = self.widget.getConstraintForRow(row1) 
    1458         self.assertEqual(cons.param, param1) 
    1459         self.assertEqual(cons.value, default_value1) 
    1460         cons = self.widget.getConstraintForRow(row2) 
    1461         self.assertEqual(cons.param, param2) 
    1462         self.assertEqual(cons.value, default_value2) 
     1424        cons = self.widget.getConstraintForRow(1) # 1 - background 
     1425        self.assertEqual(cons.param, "background") 
     1426        self.assertEqual(cons.value, "0.001") 
     1427        cons = self.widget.getConstraintForRow(4) # 4 = radius 
     1428        self.assertEqual(cons.param, "radius") 
     1429        self.assertEqual(cons.value, "20") 
    14631430 
    14641431        objects = self.widget.getConstraintObjectsForModel() 
    14651432        self.assertEqual(len(objects), 2) 
    1466         self.assertEqual(objects[1].value, default_value2) 
    1467         self.assertEqual(objects[0].param, param1) 
    1468  
     1433        self.assertEqual(objects[1].value, '20') 
     1434        self.assertEqual(objects[0].param, 'background') 
     1435 
     1436        # add complex constraint 
     1437        const = Constraint(parent=None, param='scale', func='5*sld') 
    14691438        row = 0 
    1470         param = "scale" 
    1471         func = "5*sld" 
    1472  
    1473         # add complex constraint 
    1474         const = Constraint(parent=None, param=param, func=func) 
    14751439        self.widget.addConstraintToRow(constraint=const, row=row) 
    14761440        #self.assertEqual(self.widget.getConstraintsForModel(),[('scale', '5*sld'), ('background', '0.001'), ('radius', None)]) 
    1477         cons = self.widget.getConstraintForRow(row2) 
    1478         self.assertEqual(cons.param, param2) 
    1479         self.assertEqual(cons.value, default_value2) 
     1441        cons = self.widget.getConstraintForRow(4) # 4 = radius 
     1442        self.assertEqual(cons.param, "radius") 
     1443        self.assertEqual(cons.value, "20") 
    14801444 
    14811445        objects = self.widget.getConstraintObjectsForModel() 
    14821446        self.assertEqual(len(objects), 3) 
    1483         self.assertEqual(objects[0].func, func) 
     1447        self.assertEqual(objects[0].func, '5*sld') 
    14841448 
    14851449    def testReplaceConstraintName(self): 
Note: See TracChangeset for help on using the changeset viewer.