Changeset 700b03b in sasview


Ignore:
Timestamp:
Sep 4, 2018 5:51:03 AM (6 years ago)
Author:
Torin Cooper-Bennun <torin.cooper-bennun@…>
Branches:
ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
c7809a9
Parents:
00b7ddf0
git-author:
Torin Cooper-Bennun <torin.cooper-bennun@…> (08/17/18 11:51:05)
git-committer:
Torin Cooper-Bennun <torin.cooper-bennun@…> (09/04/18 05:51:03)
Message:

[CHERRY-PICK FROM 1547a91bc] handle duplicate names in P(Q)S(Q), using param item's internal data

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

Legend:

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

    r00b7ddf0 r700b03b  
    124124    return item 
    125125 
    126 def addSimpleParametersToModel(parameters, is2D): 
     126def addSimpleParametersToModel(parameters, is2D, parameters_original=None): 
    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) 
    129131    """ 
    130132    if is2D: 
     
    132134    else: 
    133135        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 
    134149    item = [] 
    135     for param in params: 
     150    for param, param_orig in zip(params, params_orig): 
    136151        # Create the top level, checkable item 
    137         item_name = param.name 
     152        item_name = param_orig.name 
    138153        item1 = QtGui.QStandardItem(item_name) 
     154        item1.setData(param.name, QtCore.Qt.UserRole) 
    139155        item1.setCheckable(True) 
    140156        item1.setEditable(False) 
  • src/sas/qtgui/Perspectives/Fitting/FittingWidget.py

    r00b7ddf0 r700b03b  
    20602060        """ 
    20612061        structure_module = generate.load_kernel_module(structure_factor) 
    2062         structure_parameters = modelinfo.make_parameter_table(getattr(structure_module, 'parameters', [])) 
    2063  
    2064         structure_kernel = self.models[structure_factor]() 
    2065         form_kernel = self.kernel_module 
    2066  
    2067         self.kernel_module = MultiplicationModel(form_kernel, structure_kernel) 
     2062 
     2063        s_kernel = self.models[structure_factor]() 
     2064        p_kernel = self.kernel_module 
     2065 
     2066        p_pars_len = len(p_kernel._model_info.parameters.kernel_parameters) 
     2067        s_pars_len = len(s_kernel._model_info.parameters.kernel_parameters) - 1 # no radius_effective 
     2068 
     2069        self.kernel_module = MultiplicationModel(p_kernel, s_kernel) 
     2070 
     2071        # S(Q) params from the product model are not necessarily the same as those from the S(Q) model; any conflicting 
     2072        # names with P(Q) params will cause a rename; we also lose radius_effective (for now...) 
     2073        s_params = modelinfo.ParameterTable( 
     2074            self.kernel_module._model_info.parameters.kernel_parameters[p_pars_len:p_pars_len+s_pars_len]) 
     2075 
     2076        # These are the parameters before rename; ignore the first one, as it is radius_effective, which is removed 
     2077        # from the product model to be handled internally (for now...) 
     2078        s_params_orig = modelinfo.ParameterTable(s_kernel._model_info.parameters.kernel_parameters[1:]) 
    20682079 
    20692080        # Get new rows for QModel 
    2070         new_rows = FittingUtilities.addSimpleParametersToModel(structure_parameters, self.is2D) 
     2081        # Any renamed parameters are stored as data in the relevant item, for later handling 
     2082        new_rows = FittingUtilities.addSimpleParametersToModel(s_params, self.is2D, s_params_orig) 
     2083 
     2084        # TODO: deal with new parameter(s) added to product model, in kernel_parameters[p_pars_len+s_pars_len:] 
    20712085 
    20722086        # Add heading row 
     
    21082122        model_row = item.row() 
    21092123        name_index = self._model_model.index(model_row, 0) 
     2124        name_item = self._model_model.itemFromIndex(name_index) 
    21102125 
    21112126        # Extract changed value. 
     
    21162131            return 
    21172132 
    2118         parameter_name = str(self._model_model.data(name_index)) # sld, background etc. 
     2133        # if the item has user data, this is the actual parameter name (e.g. to handle duplicate names) 
     2134        if name_item.data(QtCore.Qt.UserRole): 
     2135            parameter_name = str(name_item.data(QtCore.Qt.UserRole)) 
     2136        else: 
     2137            parameter_name = str(self._model_model.data(name_index)) 
    21192138 
    21202139        # Update the parameter value - note: this supports +/-inf as well 
Note: See TracChangeset for help on using the changeset viewer.