Changes in / [9ba91b7:d6c4987] 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 r40975f8  
    161161        Create a new 1D data instance based on fitting results 
    162162        """ 
    163         return self._create1DPlot(tab_id, return_data['x'], return_data['y'], 
    164                                   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        intermediate_results = return_data 
     170 
     171        return self._create1DPlot(tab_id, x, y, model, data) 
    165172 
    166173    def new2DPlot(self, return_data): 
     
    168175        Create a new 2D data instance based on fitting results 
    169176        """ 
    170         image = return_data['image'] 
    171         data = return_data['data'] 
    172         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 
    173180 
    174181        np.nan_to_num(image) 
     
    176183        new_plot.name = model.name + '2d' 
    177184        new_plot.title = "Analytical model 2D " 
    178         new_plot.id = str(return_data['page_id']) + " " + data.name 
    179         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" 
    180187        new_plot.detector = data.detector 
    181188        new_plot.source = data.source 
     
    211218        (pq_plot, sq_plot). If either are unavailable, the corresponding plot is None. 
    212219        """ 
     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        intermediate_results = return_data 
     227 
    213228        plots = [] 
    214         for name, result in return_data['intermediate_results'].items(): 
    215             plots.append(self._create1DPlot(tab_id, return_data['x'], result, 
    216                          return_data['model'], return_data['data'], 
    217                          component=name)) 
     229        for name, result in intermediate_results.items(): 
     230            plots.append(self._create1DPlot(tab_id, x, result, model, data, component=name)) 
    218231        return plots 
    219232 
  • src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py

    r70f4458 rb764ae5  
    124124    return item 
    125125 
    126 def addSimpleParametersToModel(parameters, is2D, parameters_original=None): 
     126def addSimpleParametersToModel(parameters, is2D): 
    127127    """ 
    128128    Update local ModelModel with sasmodel parameters 
    129     parameters_original: list of parameters before any tagging on their IDs, e.g. for product model 
    130     (so that those are the display names; see below) 
    131129    """ 
    132130    if is2D: 
     
    134132    else: 
    135133        params = parameters.iq_parameters 
    136  
    137     if parameters_original: 
    138         # 'parameters_original' contains the parameters as they are to be DISPLAYED, while 'parameters' 
    139         # contains the parameters as they were renamed; this is for handling name collisions in product model. 
    140         # The 'real name' of the parameter will be stored in the item's user data. 
    141         if is2D: 
    142             params_orig = [p for p in parameters_original.kernel_parameters if p.type != 'magnetic'] 
    143         else: 
    144             params_orig = parameters_original.iq_parameters 
    145     else: 
    146         # no difference in names anyway 
    147         params_orig = params 
    148  
    149134    item = [] 
    150     for param, param_orig in zip(params, params_orig): 
     135    for param in params: 
    151136        # Create the top level, checkable item 
    152         item_name = param_orig.name 
     137        item_name = param.name 
    153138        item1 = QtGui.QStandardItem(item_name) 
    154         item1.setData(param.name, QtCore.Qt.UserRole) 
    155139        item1.setCheckable(True) 
    156140        item1.setEditable(False) 
     
    160144        item4 = QtGui.QStandardItem(str(param.limits[0])) 
    161145        item5 = QtGui.QStandardItem(str(param.limits[1])) 
    162         item6 = QtGui.QStandardItem(str(param.units)) 
     146        item6 = QtGui.QStandardItem(param.units) 
    163147        item6.setEditable(False) 
    164148        item.append([item1, item2, item4, item5, item6]) 
     
    198182    model.appendRow(item_list) 
    199183 
    200 def addHeadingRowToModel(model, name): 
    201     """adds a non-interactive top-level row to the model""" 
    202     header_row = [QtGui.QStandardItem() for i in range(5)] 
    203     header_row[0].setText(name) 
    204  
    205     font = header_row[0].font() 
    206     font.setBold(True) 
    207     header_row[0].setFont(font) 
    208  
    209     for item in header_row: 
    210         item.setEditable(False) 
    211         item.setCheckable(False) 
    212         item.setSelectable(False) 
    213  
    214     model.appendRow(header_row) 
    215  
    216184def addHeadersToModel(model): 
    217185    """ 
     
    259227    model.header_tooltips = copy.copy(poly_header_error_tooltips) 
    260228 
    261 def addShellsToModel(parameters, model, index, row_num=None): 
    262     """ 
    263     Find out multishell parameters and update the model with the requested number of them. 
    264     Inserts them after the row at row_num, if not None; otherwise, appends to end. 
    265     Returns a list of lists of QStandardItem objects. 
     229def addShellsToModel(parameters, model, index): 
     230    """ 
     231    Find out multishell parameters and update the model with the requested number of them 
    266232    """ 
    267233    multishell_parameters = getIterParams(parameters) 
    268234 
    269     rows = [] 
    270235    for i in range(index): 
    271236        for par in multishell_parameters: 
     
    294259            item4 = QtGui.QStandardItem(str(par.limits[1])) 
    295260            item5 = QtGui.QStandardItem(par.units) 
    296             row = [item1, item2, item3, item4, item5] 
    297             rows.append(row) 
    298  
    299             if row_num is None: 
    300                 model.appendRow(row) 
    301             else: 
    302                 model.insertRow(row_num, row) 
    303                 row_num += 1 
    304  
    305     return rows 
     261            model.appendRow([item1, item2, item3, item4, item5]) 
    306262 
    307263def calculateChi2(reference_data, current_data): 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r0109f2a r40975f8  
    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         # Get new rows for QModel 
     2061        # Update the QModel 
    20822062        new_rows = FittingUtilities.addParametersToModel(self.model_parameters, self.kernel_module, self.is2D) 
    20832063 
    2084         # Add heading row 
    2085         FittingUtilities.addHeadingRowToModel(self._model_model, model_name) 
    2086  
    2087         # Update QModel 
    20882064        for row in new_rows: 
    20892065            self._model_model.appendRow(row) 
     2066        # Update the counter used for multishell display 
     2067        self._last_model_row = self._model_model.rowCount() 
    20902068 
    20912069    def fromStructureFactorToQModel(self, structure_factor): 
     
    20952073        if structure_factor is None or structure_factor=="None": 
    20962074            return 
    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 
     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) 
    21532084        for row in new_rows: 
    21542085            self._model_model.appendRow(row) 
    21552086            # disable fitting of parameters not listed in self.kernel_module (probably radius_effective) 
    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) 
     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() 
    21592093 
    21602094    def haveParamsToFit(self): 
     
    21822116        model_row = item.row() 
    21832117        name_index = self._model_model.index(model_row, 0) 
    2184         name_item = self._model_model.itemFromIndex(name_index) 
    21852118 
    21862119        # Extract changed value. 
     
    21912124            return 
    21922125 
    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)) 
     2126        parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 
    21982127 
    21992128        # Update the parameter value - note: this supports +/-inf as well 
     
    24232352            new_plots.append(plot) 
    24242353 
     2354        # Update/generate plots 
    24252355        for plot in new_plots: 
    24262356            self.communicate.plotUpdateSignal.emit([plot]) 
     
    26222552        def updateFunctionCaption(row): 
    26232553            # 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) 
    26272554            param_name = str(self._model_model.item(row, 0).text()) 
    2628             self._model_model.blockSignals(False) 
    26292555            if param_name !=  param.name: 
    26302556                return 
    26312557            # Modify the param value 
    2632             self._model_model.blockSignals(True) 
    26332558            if self.has_error_column: 
    26342559                # err column changes the indexing 
     
    26362561            else: 
    26372562                self._model_model.item(row, 0).child(0).child(0,4).setText(combo_string) 
    2638             self._model_model.blockSignals(False) 
    26392563 
    26402564        if combo_string == 'array': 
     
    27962720 
    27972721        self.lstParams.setIndexWidget(shell_index, func) 
    2798         self._n_shells_row = shell_row - 1 
     2722        self._last_model_row = self._model_model.rowCount() 
    27992723 
    28002724        # Set the index to the state-kept value 
     
    28072731        """ 
    28082732        # Find row location of the combobox 
    2809         first_row = self._n_shells_row + 1 
    2810         remove_rows = self._num_shell_params 
     2733        last_row = self._last_model_row 
     2734        remove_rows = self._model_model.rowCount() - last_row 
    28112735 
    28122736        if remove_rows > 1: 
    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  
     2737            self._model_model.removeRows(last_row, remove_rows) 
     2738 
     2739        FittingUtilities.addShellsToModel(self.model_parameters, self._model_model, index) 
    28182740        self.current_shell_displayed = index 
    28192741 
  • src/sas/qtgui/Perspectives/Fitting/ModelThread.py

    rdcabba7 r40975f8  
    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): 
     
    229249        elapsed = time.time() - self.starttime 
    230250 
    231         res = dict(x = self.data.x[index], y = output[index], 
    232             page_id = self.page_id, state = self.state, weight = self.weight, 
    233             fid = self.fid, toggle_mode_on = self.toggle_mode_on, 
    234             elapsed = elapsed, index = index, model = self.model, 
    235             data = self.data, update_chisqr = self.update_chisqr, 
    236             source = self.source, unsmeared_output = unsmeared_output, 
    237             unsmeared_data = unsmeared_data, unsmeared_error = unsmeared_error, 
    238             intermediate_results = results_eval) 
    239  
    240251        if LocalConfig.USING_TWISTED: 
    241             return res 
    242         else: 
    243             self.completefn(res) 
     252            return (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                    results_eval) 
     264        else: 
     265            self.completefn((self.data.x[index], output[index], 
     266                        self.page_id, 
     267                        self.state, 
     268                        self.weight, 
     269                        self.fid, 
     270                        self.toggle_mode_on, 
     271                        elapsed, index, self.model, 
     272                        self.data, 
     273                        self.update_chisqr, 
     274                        self.source, 
     275                        unsmeared_output, unsmeared_data, unsmeared_error, 
     276                        results_eval)) 
    244277 
    245278    def results(self): 
  • src/sas/qtgui/Perspectives/Fitting/UnitTesting/FittingWidgetTest.py

    r3fbd77b r66d4370  
    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? 
     
    509509        Test opening of the load file dialog for 'array' polydisp. function 
    510510        """ 
    511  
    512         # open a non-existent file 
    513511        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) 
    516512        QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 
    517513        self.widget.show() 
     
    529525 
    530526        # 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 
    534527        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") 
    539528        QtWidgets.QFileDialog.getOpenFileName = MagicMock(return_value=(filename,'')) 
    540529 
     
    602591 
    603592        # 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) 
     593        last_row = self.widget._last_model_row 
     594        func_index = self.widget._model_model.index(last_row-1, 1) 
    606595        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() 
    610596 
    611597        # Change the combo box index 
     
    10411027 
    10421028         # Check the model 
    1043         self.assertEqual(self.widget._model_model.rowCount(), 7) 
     1029        self.assertEqual(self.widget._model_model.rowCount(), 6) 
    10441030        self.assertEqual(self.widget._model_model.columnCount(), 5) 
    10451031 
     
    11571143        # two rows selected 
    11581144        index1 = self.widget.lstParams.model().index(1, 0, QtCore.QModelIndex()) 
    1159         index2 = self.widget.lstParams.model().index(3, 0, QtCore.QModelIndex()) 
     1145        index2 = self.widget.lstParams.model().index(2, 0, QtCore.QModelIndex()) 
    11601146        selection_model = self.widget.lstParams.selectionModel() 
    11611147        selection_model.select(index1, selection_model.Select | selection_model.Rows) 
     
    11931179        # several random parameters 
    11941180        self.assertEqual(self.widget.getRowFromName('scale'), 0) 
    1195         self.assertEqual(self.widget.getRowFromName('length'), 6) 
     1181        self.assertEqual(self.widget.getRowFromName('length'), 5) 
    11961182 
    11971183    def testGetParamNames(self): 
     
    12301216        # Create a constraint object 
    12311217        const = Constraint(parent=None, value=7.0) 
    1232         row = 3 
     1218        row = 2 
    12331219 
    12341220        spy = QtSignalSpy(self.widget, self.widget.constraintAddedSignal) 
     
    12491235        # assign complex constraint now 
    12501236        const = Constraint(parent=None, param='radius', func='5*sld') 
    1251         row = 5 
     1237        row = 4 
    12521238        # call the method tested 
    12531239        self.widget.addConstraintToRow(constraint=const, row=row) 
     
    13081294        self.widget.cbModel.setCurrentIndex(model_index) 
    13091295 
     1296        # select two rows 
    13101297        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 
     1298        row2 = 4 
    13201299        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    13211300        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    13341313 
    13351314        # delete one of the constraints 
    1336         self.widget.deleteConstraintOnParameter(param=param1) 
     1315        self.widget.deleteConstraintOnParameter(param='background') 
    13371316 
    13381317        # 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) 
     1318        cons = self.widget.getConstraintForRow(4) # 4 = radius 
     1319        self.assertEqual(cons.param, "radius") 
     1320        self.assertEqual(cons.value, "20") 
    13421321 
    13431322        # kill the other constraint 
     
    13451324 
    13461325        # see that the other constraint is still present 
    1347         self.assertEqual(self.widget.getConstraintsForModel(), [(param2, None)]) 
     1326        self.assertEqual(self.widget.getConstraintsForModel(), [('radius', None)]) 
    13481327 
    13491328    def testGetConstraintForRow(self): 
     
    13651344        self.widget.cbModel.setCurrentIndex(model_index) 
    13661345 
     1346        # select two rows 
    13671347        row1 = 1 
    1368         row2 = 5 
    1369  
    1370         # select two rows 
     1348        row2 = 4 
    13711349        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    13721350        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    13781356        self.widget.addSimpleConstraint() 
    13791357 
    1380         con_list = [False, True, False, False, False, True, False] 
     1358        con_list = [False, True, False, False, True, False] 
    13811359        new_list = [] 
    13821360        for row in range(self.widget._model_model.rowCount()): 
     
    13961374        self.widget.cbModel.setCurrentIndex(model_index) 
    13971375 
     1376        # select two rows 
    13981377        row1 = 1 
    1399         row2 = 5 
    1400  
    1401         # select two rows 
     1378        row2 = 4 
    14021379        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    14031380        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    14131390        constraint_objects[0].active = False 
    14141391 
    1415         con_list = [False, False, False, False, False, True, False] 
     1392        con_list = [False, False, False, False, True, False] 
    14161393        new_list = [] 
    14171394        for row in range(self.widget._model_model.rowCount()): 
     
    14341411        self.assertEqual(self.widget.getConstraintsForModel(),[]) 
    14351412 
     1413        # select two rows 
    14361414        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 
     1415        row2 = 4 
    14461416        index1 = self.widget.lstParams.model().index(row1, 0, QtCore.QModelIndex()) 
    14471417        index2 = self.widget.lstParams.model().index(row2, 0, QtCore.QModelIndex()) 
     
    14551425        # simple constraints 
    14561426        # 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) 
     1427        cons = self.widget.getConstraintForRow(1) # 1 - background 
     1428        self.assertEqual(cons.param, "background") 
     1429        self.assertEqual(cons.value, "0.001") 
     1430        cons = self.widget.getConstraintForRow(4) # 4 = radius 
     1431        self.assertEqual(cons.param, "radius") 
     1432        self.assertEqual(cons.value, "20") 
    14631433 
    14641434        objects = self.widget.getConstraintObjectsForModel() 
    14651435        self.assertEqual(len(objects), 2) 
    1466         self.assertEqual(objects[1].value, default_value2) 
    1467         self.assertEqual(objects[0].param, param1) 
    1468  
     1436        self.assertEqual(objects[1].value, '20') 
     1437        self.assertEqual(objects[0].param, 'background') 
     1438 
     1439        # add complex constraint 
     1440        const = Constraint(parent=None, param='scale', func='5*sld') 
    14691441        row = 0 
    1470         param = "scale" 
    1471         func = "5*sld" 
    1472  
    1473         # add complex constraint 
    1474         const = Constraint(parent=None, param=param, func=func) 
    14751442        self.widget.addConstraintToRow(constraint=const, row=row) 
    14761443        #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) 
     1444        cons = self.widget.getConstraintForRow(4) # 4 = radius 
     1445        self.assertEqual(cons.param, "radius") 
     1446        self.assertEqual(cons.value, "20") 
    14801447 
    14811448        objects = self.widget.getConstraintObjectsForModel() 
    14821449        self.assertEqual(len(objects), 3) 
    1483         self.assertEqual(objects[0].func, func) 
     1450        self.assertEqual(objects[0].func, '5*sld') 
    14841451 
    14851452    def testReplaceConstraintName(self): 
Note: See TracChangeset for help on using the changeset viewer.