Changeset 740a738 in sasview
- Timestamp:
- Mar 28, 2019 9:32:47 AM (6 years ago)
- Branches:
- ESS_GUI_bumps_abstraction
- Children:
- ea1753f
- Parents:
- 04a269f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Perspectives/Fitting/FittingOptions.py
r04a269f r740a738 19 19 20 20 # Set the default optimizer 21 22 def configToBumps(fittingMethod):23 """24 Writes the user settings of given fitting method back to be bumps module where it is used25 once the 'fit' button is hit in the GUI.26 """27 # assert isinstance(fittingMethod, FittingMethod) # FIXME once FittingMethod is known here28 # self.config.values[self.current_fitter_id][option] = new_value29 fitConfig = bumps.options.FIT_CONFIG30 fitConfig.selected_id = fittingMethod.shortName31 for param in fittingMethod.params.values():32 fitConfig.values[fittingMethod.shortName][param.shortName] = param.value33 21 34 22 def parse_int(value): … … 116 104 return self._params 117 105 106 def storeConfig(self): 107 """ 108 To be overridden by subclasses specific to optimizers. 109 """ 110 pass 111 118 112 def __str__(self): 119 113 return "\n".join(["{} ({})".format(self.longName, self.shortName)] … … 137 131 self._methods[fittingMethod.longName] = fittingMethod 138 132 139 def importFromBumps(self, ids): 133 @property 134 def longNames(self): 135 return list(self._methods.keys()) 136 137 @property 138 def ids(self): 139 return [fm.shortName for fm in self._methods.values()] 140 141 def __getitem__(self, longName): 142 return self._methods[longName] 143 144 def __len__(self): 145 return len(self._methods) 146 147 def __iter__(self): 148 return self._methods.__iter__ 149 150 @property 151 def default(self): 152 return self._default 153 154 def setDefault(self, methodName): 155 assert methodName in self._methods # silently fail instead? 156 self._default = self._methods[methodName] 157 158 def __str__(self): 159 return "\n".join(["{}: {}".format(key, fm) for key, fm in self._methods.items()]) 160 161 class FittingMethodBumps(FittingMethod): 162 def storeConfig(self): 163 """ 164 Writes the user settings of given fitting method back to the optimizer backend 165 where it is used once the 'fit' button is hit in the GUI. 166 """ 167 fitConfig = bumps.options.FIT_CONFIG 168 fitConfig.selected_id = self.shortName 169 for param in self.params.values(): 170 fitConfig.values[self.shortName][param.shortName] = param.value 171 172 class FittingMethodsBumps(FittingMethods): 173 def __init__(self): 140 174 """ 141 175 Import fitting methods indicated by the provided list of ids from the bumps package. 142 176 """ 177 super(FittingMethodsBumps, self).__init__() 178 ids = fitters.FIT_ACTIVE_IDS 143 179 for f in fitters.FITTERS: 144 180 if f.id not in ids: … … 149 185 param = FittingMethodParameter(shortName, longName, dtype, defValue) 150 186 params.append(param) 151 self.add(FittingMethod(f.id, f.name, params)) 152 153 @property 154 def longNames(self): 155 return list(self._methods.keys()) 156 157 @property 158 def ids(self): 159 return [fm.shortName for fm in self._methods.values()] 160 161 def __getitem__(self, longName): 162 return self._methods[longName] 163 164 @property 165 def default(self): 166 return self._default 167 168 def setDefault(self, methodName): 169 assert methodName in self._methods # silently fail instead? 170 self._default = self._methods[methodName] 171 172 def __str__(self): 173 return "\n".join(["{}: {}".format(key, fm) for key, fm in self._methods.items()]) 187 self.add(FittingMethodBumps(f.id, f.name, params)) 174 188 175 189 class FittingOptions(QtWidgets.QDialog, Ui_FittingOptions): … … 209 223 210 224 # Fill up the algorithm combo, based on what BUMPS says is available 211 self._fittingMethods = FittingMethods ()225 self._fittingMethods = FittingMethodsBumps() 212 226 # option 1: hardcode the list of bumps fitting methods according to forms 213 227 # option 2: create forms dynamically based on selected fitting methods 214 self.fittingMethods.importFromBumps(fitters.FIT_ACTIVE_IDS) 215 self.fittingMethods.add(FittingMethod('mcsas', 'McSAS', [])) 228 self.fittingMethods.add(FittingMethod('mcsas', 'McSAS', [])) # FIXME just testing for now 216 229 self.fittingMethods.setDefault('Levenberg-Marquardt') 217 230 # build up the comboBox finally … … 368 381 self.reject 369 382 383 fm.storeConfig() # write the current settings to bumps module 370 384 # Notify the perspective, so the window title is updated 371 385 self.fit_option_changed.emit(self.cbAlgorithm.currentText()) 372 configToBumps(fm) # write the current settings to bumps module373 386 self.close() 374 387
Note: See TracChangeset
for help on using the changeset viewer.