Changes in src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py [f3cc979:70f4458] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
rf3cc979 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 poly_pars = parameters.form_volume_parameters 131 if is2D: 132 poly_pars += parameters.orientation_parameters 133 for p in poly_pars: 96 for p in parameters.form_volume_parameters: 134 97 if p.name != param.name: 135 98 continue 136 99 width = kernel_module.getParam(p.name+'.width') 137 100 ptype = kernel_module.getParam(p.name+'.type') 101 138 102 item1_2 = QtGui.QStandardItem(str(width)) 139 103 item1_2.setEditable(False) … … 146 110 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 147 111 break 148 149 112 # Add the polydisp item as a child 150 113 item1.appendRow([poly_item]) 151 152 114 # Param values 153 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() 154 119 item3 = QtGui.QStandardItem(str(param.limits[0])) 155 120 item4 = QtGui.QStandardItem(str(param.limits[1])) 156 item5 = QtGui.QStandardItem( str(param.units))121 item5 = QtGui.QStandardItem(param.units) 157 122 item5.setEditable(False) 158 159 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 160 row = [item1, item2, item3, item4, item5] 161 cbox = createFixedChoiceComboBox(param, row) 162 163 # Append to the model and use the combobox, if required 164 if None not in (model, view): 165 model.appendRow(row) 166 if cbox: 167 view.setIndexWidget(item2.index(), cbox) 168 rows.append(row) 169 170 return rows 171 172 def addSimpleParametersToModel(parameters, is2D, parameters_original=None, model=None, view=None, row_num=None): 173 """ 174 Update local ModelModel with sasmodel parameters (non-dispersed, non-magnetic) 175 Actually appends to model, if model and view params are not None. 176 Always returns list of lists of QStandardItems. 177 178 parameters_original: list of parameters before any tagging on their IDs, e.g. for product model (so that those are 179 the display names; see below) 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) 180 131 """ 181 132 if is2D: … … 196 147 params_orig = params 197 148 198 rows= []149 item = [] 199 150 for param, param_orig in zip(params, params_orig): 200 151 # Create the top level, checkable item … … 204 155 item1.setCheckable(True) 205 156 item1.setEditable(False) 206 207 157 # Param values 208 158 # TODO: add delegate for validation of cells 209 159 item2 = QtGui.QStandardItem(str(param.default)) 210 item3 = QtGui.QStandardItem(str(param.limits[0])) 211 item4 = QtGui.QStandardItem(str(param.limits[1])) 212 item5 = QtGui.QStandardItem(str(param.units)) 213 item5.setEditable(False) 214 215 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 216 row = [item1, item2, item3, item4, item5] 217 cbox = createFixedChoiceComboBox(param, row) 218 219 # Append to the model and use the combobox, if required 220 if None not in (model, view): 221 if row_num is None: 222 model.appendRow(row) 223 else: 224 model.insertRow(row_num, row) 225 row_num += 1 226 227 if cbox: 228 view.setIndexWidget(item2.index(), cbox) 229 230 rows.append(row) 231 232 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 233 166 234 167 def markParameterDisabled(model, row): … … 326 259 model.header_tooltips = copy.copy(poly_header_error_tooltips) 327 260 328 def addShellsToModel(parameters, model, index, row_num=None , view=None):261 def addShellsToModel(parameters, model, index, row_num=None): 329 262 """ 330 263 Find out multishell parameters and update the model with the requested number of them. 331 264 Inserts them after the row at row_num, if not None; otherwise, appends to end. 332 If view param is not None, supports fixed-choice params.333 265 Returns a list of lists of QStandardItem objects. 334 266 """ … … 353 285 item1_3 = QtGui.QStandardItem(str(p.limits[0])) 354 286 item1_4 = QtGui.QStandardItem(str(p.limits[1])) 355 item1_5 = QtGui.QStandardItem( str(p.units))287 item1_5 = QtGui.QStandardItem(p.units) 356 288 poly_item.appendRow([item1_1, item1_2, item1_3, item1_4, item1_5]) 357 289 break … … 361 293 item3 = QtGui.QStandardItem(str(par.limits[0])) 362 294 item4 = QtGui.QStandardItem(str(par.limits[1])) 363 item5 = QtGui.QStandardItem(str(par.units)) 364 item5.setEditable(False) 365 366 # Check if fixed-choice (returns combobox, if so, also makes some items uneditable) 295 item5 = QtGui.QStandardItem(par.units) 367 296 row = [item1, item2, item3, item4, item5] 368 cbox = createFixedChoiceComboBox(par, row) 369 370 # Always add to the model 297 rows.append(row) 298 371 299 if row_num is None: 372 300 model.appendRow(row) … … 374 302 model.insertRow(row_num, row) 375 303 row_num += 1 376 377 # Apply combobox if required378 if None not in (view, cbox):379 view.setIndexWidget(item2.index(), cbox)380 381 rows.append(row)382 304 383 305 return rows … … 552 474 553 475 theory_name = str(current_data.name.split()[0]) 554 res _name = reference_data.filename if reference_data.filename else reference_data.name555 residuals.name = "Residuals for " + str(theory_name) + "[" + res_name+ "]"476 residuals.name = "Residuals for " + str(theory_name) + "[" + \ 477 str(reference_data.filename) + "]" 556 478 residuals.title = residuals.name 557 479 residuals.ytransform = 'y' … … 579 501 """ 580 502 weight = None 581 if data is None:582 return []583 503 if is2d: 584 if not hasattr(data, 'err_data'):585 return []586 504 dy_data = data.err_data 587 505 data = data.data 588 506 else: 589 if not hasattr(data, 'dy'):590 return []591 507 dy_data = data.dy 592 508 data = data.y
Note: See TracChangeset
for help on using the changeset viewer.