Changeset 740a738 in sasview


Ignore:
Timestamp:
Mar 28, 2019 9:32:47 AM (6 years ago)
Author:
ibressler
Branches:
ESS_GUI_bumps_abstraction
Children:
ea1753f
Parents:
04a269f
Message:

move bumps specific reading/writing from/to backend to subclasses, same for other optimizers

File:
1 edited

Legend:

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

    r04a269f r740a738  
    1919 
    2020# 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 used 
    25     once the 'fit' button is hit in the GUI. 
    26     """ 
    27 #    assert isinstance(fittingMethod, FittingMethod) # FIXME once FittingMethod is known here 
    28     # self.config.values[self.current_fitter_id][option] = new_value 
    29     fitConfig = bumps.options.FIT_CONFIG 
    30     fitConfig.selected_id = fittingMethod.shortName 
    31     for param in fittingMethod.params.values(): 
    32         fitConfig.values[fittingMethod.shortName][param.shortName] = param.value 
    3321 
    3422def parse_int(value): 
     
    116104        return self._params 
    117105 
     106    def storeConfig(self): 
     107        """ 
     108        To be overridden by subclasses specific to optimizers. 
     109        """ 
     110        pass 
     111 
    118112    def __str__(self): 
    119113        return "\n".join(["{} ({})".format(self.longName, self.shortName)] 
     
    137131        self._methods[fittingMethod.longName] = fittingMethod 
    138132 
    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 
     161class 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 
     172class FittingMethodsBumps(FittingMethods): 
     173    def __init__(self): 
    140174        """ 
    141175        Import fitting methods indicated by the provided list of ids from the bumps package. 
    142176        """ 
     177        super(FittingMethodsBumps, self).__init__() 
     178        ids = fitters.FIT_ACTIVE_IDS 
    143179        for f in fitters.FITTERS: 
    144180            if f.id not in ids: 
     
    149185                param = FittingMethodParameter(shortName, longName, dtype, defValue) 
    150186                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)) 
    174188 
    175189class FittingOptions(QtWidgets.QDialog, Ui_FittingOptions): 
     
    209223 
    210224        # Fill up the algorithm combo, based on what BUMPS says is available 
    211         self._fittingMethods = FittingMethods() 
     225        self._fittingMethods = FittingMethodsBumps() 
    212226        # option 1: hardcode the list of bumps fitting methods according to forms 
    213227        # 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 
    216229        self.fittingMethods.setDefault('Levenberg-Marquardt') 
    217230        # build up the comboBox finally 
     
    368381                self.reject 
    369382 
     383        fm.storeConfig() # write the current settings to bumps module 
    370384        # Notify the perspective, so the window title is updated 
    371385        self.fit_option_changed.emit(self.cbAlgorithm.currentText()) 
    372         configToBumps(fm) # write the current settings to bumps module 
    373386        self.close() 
    374387 
Note: See TracChangeset for help on using the changeset viewer.