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

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 bc3e38c 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
Line 
1"""
2Class Fit contains fitting engine methods declaration
3"""
4
5from sas.fit.BumpsFitting import BumpsFit
6
7ENGINES={
8    'bumps': BumpsFit,
9}
10
11class Fit(object):
12    """
13    Wrap class that allows to select the fitting type.this class
14    can be used as follow : ::
15   
16        from sas.fit.Fitting import Fit
17        fitter= Fit()
18        fitter.fit_engine('bumps')
19        engine = fitter.returnEngine()
20        engine.set_data(data,id)
21        engine.set_param( model,model.name, pars)
22        engine.set_model(model,id)
23       
24        chisqr1, out1, cov1=engine.fit(pars,qmin,qmax)
25       
26    """ 
27    def __init__(self, engine='bumps', *args, **kw):
28        """
29        """
30        self._engine = None
31        self.fitter_id = None
32        self.set_engine(engine, *args, **kw)
33         
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               
49    def set_engine(self, word, *args, **kw):
50        """
51        Select the type of Fit
52       
53        :param word: the keyword to select the fit type
54       
55        :raise: KeyError if the user does not enter an available engine
56
57        """
58        try:
59            self._engine = ENGINES[word](*args, **kw)
60        except KeyError, exc:
61            raise KeyError("fit engine should be bumps")
62            #raise KeyError("fit engine should be one of "+", ".join(sorted(ENGINES.keys())))
63
64    def fit(self, msg_q=None, q=None, handler=None, 
65                        curr_thread=None, 
66                        ftol=1.49012e-8,
67                        reset_flag=False):
68        """Perform the fit """
69        return self._engine.fit(msg_q=msg_q,
70                                q=q, handler=handler, curr_thread=curr_thread,
71                                ftol=ftol, reset_flag=reset_flag)
72     
73    def set_model(self, model, id, pars=[], constraints=[], data=None):
74        """
75        store a model model to fit at the position id of the fit engine
76        """
77        self._engine.set_model(model, id, pars, constraints, data=data)
78   
79    def set_data(self, data, id, smearer=None, qmin=None, qmax=None):
80        """
81        Store data to fit at the psotion id of the fit engine
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       
88        """
89        self._engine.set_data(data, id, smearer, qmin, qmax)
90       
91    def get_model(self, id):
92        """ return list of data"""
93        self._engine.get_model(id)
94
95
96    def remove_fit_problem(self, id):
97        """remove fitarrange in id"""
98        self._engine.remove_fit_problem(id)
99       
100    def select_problem_for_fit(self, id, value):
101        """
102        select a couple of model and data at the id position in dictionary
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
107        """
108        self._engine.select_problem_for_fit(id, value)
109       
110    def get_problem_to_fit(self, id):
111        """
112        return the self.selected value of the fit problem of id
113           
114        :param id: the id of the problem
115       
116        """
117        return self._engine.get_problem_to_fit(id)
Note: See TracBrowser for help on using the repository browser.