Changes in src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py [bc7371fd:70f4458] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
rbc7371fd r70f4458 8 8 from sas.qtgui.Plotting.PlotterData import Data1D 9 9 from sas.qtgui.Plotting.PlotterData import Data2D 10 11 from sas.qtgui.Perspectives.Fitting.AssociatedComboBox import AssociatedComboBox12 10 13 11 model_header_captions = ['Parameter', 'Value', 'Min', 'Max', 'Units'] … … 63 61 return (param_name, param_length) 64 62 65 def createFixedChoiceComboBox(param, item_row): 66 """ 67 Determines whether param is a fixed-choice parameter, modifies items in item_row appropriately and returns a combo 68 box containing the fixed choices. Returns None if param is not fixed-choice. 69 70 item_row is a list of QStandardItem objects for insertion into the parameter table. 71 """ 72 73 # Determine whether this is a fixed-choice parameter. There are lots of conditionals, simply because the 74 # implementation is not yet concrete; there are several possible indicators that the parameter is fixed-choice. 75 # TODO: (when the sasmodels implementation is concrete, clean this up) 76 choices = None 77 if isinstance(param.choices, (list, tuple)) and len(param.choices) > 0: 78 # The choices property is concrete in sasmodels, probably will use this 79 choices = param.choices 80 elif isinstance(param.units, (list, tuple)): 81 choices = [str(x) for x in param.units] 82 83 cbox = None 84 if choices is not None: 85 # Use combo box for input, if it is fixed-choice 86 cbox = AssociatedComboBox(item_row[1], idx_as_value=True) 87 cbox.addItems(choices) 88 item_row[2].setEditable(False) 89 item_row[3].setEditable(False) 90 91 return cbox 92 93 def addParametersToModel(parameters, kernel_module, is2D, model=None, view=None): 94 """ 95 Update local ModelModel with sasmodel parameters. 96 Actually appends to model, if model and view params are not None. 97 Always returns list of lists of QStandardItems. 63 def addParametersToModel(parameters, kernel_module, is2D): 64 """ 65 Update local ModelModel with sasmodel parameters 98 66 """ 99 67 multishell_parameters = getIterParams(parameters) … … 104 72 else: 105 73 params = parameters.iq_parameters 106 107 rows = [] 74 item = [] 108 75 for param in params: 109 76 # don't include shell parameters 110 77 if param.name == multishell_param_name: 111 78 continue 112 113 79 # Modify parameter name from <param>[n] to <param>1 114 80 item_name = param.name 115 81 if param in multishell_parameters: 116 82 continue 83 # item_name = replaceShellName(param.name, 1) 117 84 118 85 item1 = QtGui.QStandardItem(item_name) 119 86 item1.setCheckable(True) 120 87 item1.setEditable(False) 121 88 # item_err = QtGui.QStandardItem() 122 89 # check for polydisp params 123 90 if param.polydisperse: … … 126 93 item1_1 = QtGui.QStandardItem("Distribution") 127 94 item1_1.setEditable(False) 128 129 95 # Find param in volume_params 130 96 for p in parameters.form_volume_parameters: … … 133 99 width = kernel_module.getParam(p.name+'.width') 134 100 ptype = kernel_module.getParam(p.name+'.type') 101 135 102 item1_2 = QtGui.QStandardItem(str(width)) 136 103 item1_2.setEditable(False) … … 143 110 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 144 111 break 145 146 112 # Add the polydisp item as a child 147 113 item1.appendRow([poly_item]) 148 149 114 # Param values 150 115 item2 = QtGui.QStandardItem(str(param.default)) 116 # TODO: the error column. 117 # Either add a proxy model or a custom view delegate 118 #item_err = QtGui.QStandardItem() 151 119 item3 = QtGui.QStandardItem(str(param.limits[0])) 152 120 item4 = QtGui.QStandardItem(str(param.limits[1])) 153 item5 = QtGui.QStandardItem( str(param.units))121 item5 = QtGui.QStandardItem(param.units) 154 122 item5.setEditable(False) 155 156 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 157 row = [item1, item2, item3, item4, item5] 158 cbox = createFixedChoiceComboBox(param, row) 159 160 # Append to the model and use the combobox, if required 161 if None not in (model, view): 162 model.appendRow(row) 163 if cbox: 164 view.setIndexWidget(item2.index(), cbox) 165 rows.append(row) 166 167 return rows 168 169 def addSimpleParametersToModel(parameters, is2D, model=None, view=None): 170 """ 171 Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 172 Actually appends to model, if model and view params are not None. 173 Always returns list of lists of QStandardItems. 123 item.append([item1, item2, item3, item4, item5]) 124 return item 125 126 def addSimpleParametersToModel(parameters, is2D, parameters_original=None): 127 """ 128 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) 174 131 """ 175 132 if is2D: … … 178 135 params = parameters.iq_parameters 179 136 180 rows = [] 181 for param in params: 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 149 item = [] 150 for param, param_orig in zip(params, params_orig): 182 151 # Create the top level, checkable item 183 item_name = param .name152 item_name = param_orig.name 184 153 item1 = QtGui.QStandardItem(item_name) 154 item1.setData(param.name, QtCore.Qt.UserRole) 185 155 item1.setCheckable(True) 186 156 item1.setEditable(False) 187 188 157 # Param values 189 158 # TODO: add delegate for validation of cells 190 159 item2 = QtGui.QStandardItem(str(param.default)) 191 item3 = QtGui.QStandardItem(str(param.limits[0])) 192 item4 = QtGui.QStandardItem(str(param.limits[1])) 193 item5 = QtGui.QStandardItem(str(param.units)) 194 item5.setEditable(False) 195 196 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 197 row = [item1, item2, item3, item4, item5] 198 cbox = createFixedChoiceComboBox(param, row) 199 200 # Append to the model and use the combobox, if required 201 if None not in (model, view): 202 model.appendRow(row) 203 if cbox: 204 view.setIndexWidget(item2.index(), cbox) 205 rows.append(row) 206 207 return rows 160 item4 = QtGui.QStandardItem(str(param.limits[0])) 161 item5 = QtGui.QStandardItem(str(param.limits[1])) 162 item6 = QtGui.QStandardItem(str(param.units)) 163 item6.setEditable(False) 164 item.append([item1, item2, item4, item5, item6]) 165 return item 208 166 209 167 def markParameterDisabled(model, row): … … 240 198 model.appendRow(item_list) 241 199 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 242 216 def addHeadersToModel(model): 243 217 """ … … 285 259 model.header_tooltips = copy.copy(poly_header_error_tooltips) 286 260 287 def 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.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. 292 266 """ 293 267 multishell_parameters = getIterParams(parameters) … … 311 285 item1_3 = QtGui.QStandardItem(str(p.limits[0])) 312 286 item1_4 = QtGui.QStandardItem(str(p.limits[1])) 313 item1_5 = QtGui.QStandardItem( str(p.units))287 item1_5 = QtGui.QStandardItem(p.units) 314 288 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 315 289 break … … 319 293 item3 = QtGui.QStandardItem(str(par.limits[0])) 320 294 item4 = QtGui.QStandardItem(str(par.limits[1])) 321 item5 = QtGui.QStandardItem(str(par.units)) 322 item5.setEditable(False) 323 324 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 295 item5 = QtGui.QStandardItem(par.units) 325 296 row = [item1, item2, item3, item4, item5] 326 cbox = createFixedChoiceComboBox(par, row)327 328 # Always append to the model329 model.appendRow(row)330 331 # Apply combobox if required332 if None not in (view, cbox):333 view.setIndexWidget(item2.index(), cbox)334 335 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 336 304 337 305 return rows … … 506 474 507 475 theory_name = str(current_data.name.split()[0]) 508 res _name = reference_data.filename if reference_data.filename else reference_data.name509 residuals.name = "Residuals for " + str(theory_name) + "[" + res_name+ "]"476 residuals.name = "Residuals for " + str(theory_name) + "[" + \ 477 str(reference_data.filename) + "]" 510 478 residuals.title = residuals.name 511 479 residuals.ytransform = 'y' … … 533 501 """ 534 502 weight = None 535 if data is None:536 return []537 503 if is2d: 538 if not hasattr(data, 'err_data'):539 return []540 504 dy_data = data.err_data 541 505 data = data.data 542 506 else: 543 if not hasattr(data, 'dy'):544 return []545 507 dy_data = data.dy 546 508 data = data.y
Note: See TracChangeset
for help on using the changeset viewer.