source: sasview/src/sas/fit/Fitting.py @ d859737

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 d859737 was 386ffe1, checked in by pkienzle, 10 years ago

remove scipy levenburg marquardt and park from ui

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