source: sasview/src/sans/fit/Fitting.py @ 76f132a

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 76f132a was 6fe5100, checked in by pkienzle, 11 years ago

Bumps first pass. Fitting works but no pretty pictures

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[792db7d5]1"""
[aa36f96]2Class Fit contains ScipyFit and ParkFit methods declaration
3allows to create instance of type ScipyFit or ParkFit to perform either
4a park fit or a scipy fit.
[792db7d5]5"""
[d8a2e31]6
[89f3b66]7#from scipy import optimize
[c4d6900]8from sans.fit.ScipyFitting import ScipyFit
9from sans.fit.ParkFitting import ParkFit
[6fe5100]10from sans.fit.BumpsFitting import BumpsFit
[7705306]11
[6fe5100]12ENGINES={
13    'scipy': ScipyFit,
14    'park': ParkFit,
15    'bumps': BumpsFit,
16}
[7705306]17
[06e7c26]18class Fit(object):
[7705306]19    """
[aa36f96]20    Wrap class that allows to select the fitting type.this class
21    can be used as follow : ::
22   
[792db7d5]23        from sans.fit.Fitting import Fit
24        fitter= Fit()
25        fitter.fit_engine('scipy') or fitter.fit_engine('park')
26        engine = fitter.returnEngine()
[c4d6900]27        engine.set_data(data,id)
[792db7d5]28        engine.set_param( model,model.name, pars)
[c4d6900]29        engine.set_model(model,id)
[393f0f3]30       
[792db7d5]31        chisqr1, out1, cov1=engine.fit(pars,qmin,qmax)
[aa36f96]32       
[7705306]33    """ 
[93f0a586]34    def __init__(self, engine='scipy'):
[792db7d5]35        """
36        """
[aa36f96]37        #self._engine will contain an instance of ScipyFit or ParkFit
[20d30e9]38        self._engine = None
[06e7c26]39        self.fitter_id = None
[93f0a586]40        self.set_engine(engine)
[7705306]41         
[06e7c26]42    def __setattr__(self, name, value):
43        """
44        set fitter_id and its engine at the same time
45        """
46        if name == "fitter_id":
47            self.__dict__[name] = value
48            if hasattr(self, "_engine") and self._engine is not None:
49                self._engine.fitter_id = value   
50        elif name == "_engine":
51            self.__dict__[name] = value
52            if hasattr(self, "fitter_id") and self.fitter_id is not None:
53                self._engine.fitter_id = self.fitter_id
54        else:
55            self.__dict__[name] = value
56               
[89f3b66]57    def set_engine(self, word):
[7705306]58        """
[aa36f96]59        Select the type of Fit
60       
61        :param word: the keyword to select the fit type
62       
63        :raise: if the user does not enter 'scipy' or 'park',
64             a valueError is raised
65             
[7705306]66        """
[6fe5100]67        try:
68            self._engine = ENGINES[word]()
69        except KeyError, exc:
70            raise KeyError("fit engine should be one of scipy, park or bumps")
[aa36f96]71
[ba7dceb]72    def fit(self, msg_q=None, q=None, handler=None, 
[7db52f1]73                        curr_thread=None, 
74                        ftol=1.49012e-8,
75                        reset_flag=False):
[792db7d5]76        """Perform the fit """
[ba7dceb]77        return self._engine.fit(msg_q=msg_q, 
78                                q=q, handler=handler, curr_thread=curr_thread,
[7db52f1]79                                ftol=ftol, reset_flag=reset_flag)
[511c6810]80     
[634ca14]81    def set_model(self, model, id, pars=[], constraints=[], data=None):
[20d30e9]82        """
[c4d6900]83        store a model model to fit at the position id of the fit engine
[20d30e9]84        """
[634ca14]85        self._engine.set_model(model, id, pars, constraints, data=data)
[20d30e9]86   
[c4d6900]87    def set_data(self, data, id, smearer=None, qmin=None, qmax=None):
[20d30e9]88        """
[c4d6900]89        Store data to fit at the psotion id of the fit engine
[aa36f96]90       
91        :param data: data to fit
92        :param smearer: smearerobject to smear data
93        :param qmin: the minimum q range to fit
94        :param qmax: the minimum q range to fit
95       
[20d30e9]96        """
[c4d6900]97        self._engine.set_data(data, id, smearer, qmin, qmax)
[ca6d914]98       
[c4d6900]99    def get_model(self, id):
[7705306]100        """ return list of data"""
[c4d6900]101        self._engine.get_model(id)
[9855699]102
[20d30e9]103
[c4d6900]104    def remove_fit_problem(self, id):
105        """remove fitarrange in id"""
106        self._engine.remove_fit_problem(id)
[ca6d914]107       
[c4d6900]108    def select_problem_for_fit(self, id, value):
[a9e04aa]109        """
[c4d6900]110        select a couple of model and data at the id position in dictionary
[aa36f96]111        and set in self.selected value to value
112       
113        :param value: the value to allow fitting.
114             can only have the value one or zero
[a9e04aa]115        """
[c4d6900]116        self._engine.select_problem_for_fit(id, value)
[20d30e9]117       
[c4d6900]118    def get_problem_to_fit(self, id):
[a9e04aa]119        """
[c4d6900]120        return the self.selected value of the fit problem of id
[aa36f96]121           
[c4d6900]122        :param id: the id of the problem
[aa36f96]123       
[a9e04aa]124        """
[c4d6900]125        return self._engine.get_problem_to_fit(id)
Note: See TracBrowser for help on using the repository browser.