source: sasview/src/sas/fit/Fitting.py @ 827484cf

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 827484cf was 79492222, checked in by krzywon, 10 years ago

Changed the file and folder names to remove all SANS references.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1"""
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.
5"""
6
7#from scipy import optimize
8from sas.fit.ScipyFitting import ScipyFit
9from sas.fit.ParkFitting import ParkFit
10from sas.fit.BumpsFitting import BumpsFit
11
12ENGINES={
13    'scipy': ScipyFit,
14    'park': ParkFit,
15    'bumps': BumpsFit,
16}
17
18class Fit(object):
19    """
20    Wrap class that allows to select the fitting type.this class
21    can be used as follow : ::
22   
23        from sas.fit.Fitting import Fit
24        fitter= Fit()
25        fitter.fit_engine('scipy') or fitter.fit_engine('park')
26        engine = fitter.returnEngine()
27        engine.set_data(data,id)
28        engine.set_param( model,model.name, pars)
29        engine.set_model(model,id)
30       
31        chisqr1, out1, cov1=engine.fit(pars,qmin,qmax)
32       
33    """ 
34    def __init__(self, engine='scipy', *args, **kw):
35        """
36        """
37        #self._engine will contain an instance of ScipyFit or ParkFit
38        self._engine = None
39        self.fitter_id = None
40        self.set_engine(engine, *args, **kw)
41         
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               
57    def set_engine(self, word, *args, **kw):
58        """
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             
66        """
67        try:
68            self._engine = ENGINES[word](*args, **kw)
69        except KeyError, exc:
70            raise KeyError("fit engine should be one of scipy, park or bumps")
71
72    def fit(self, msg_q=None, q=None, handler=None, 
73                        curr_thread=None, 
74                        ftol=1.49012e-8,
75                        reset_flag=False):
76        """Perform the fit """
77        return self._engine.fit(msg_q=msg_q, 
78                                q=q, handler=handler, curr_thread=curr_thread,
79                                ftol=ftol, reset_flag=reset_flag)
80     
81    def set_model(self, model, id, pars=[], constraints=[], data=None):
82        """
83        store a model model to fit at the position id of the fit engine
84        """
85        self._engine.set_model(model, id, pars, constraints, data=data)
86   
87    def set_data(self, data, id, smearer=None, qmin=None, qmax=None):
88        """
89        Store data to fit at the psotion id of the fit engine
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       
96        """
97        self._engine.set_data(data, id, smearer, qmin, qmax)
98       
99    def get_model(self, id):
100        """ return list of data"""
101        self._engine.get_model(id)
102
103
104    def remove_fit_problem(self, id):
105        """remove fitarrange in id"""
106        self._engine.remove_fit_problem(id)
107       
108    def select_problem_for_fit(self, id, value):
109        """
110        select a couple of model and data at the id position in dictionary
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
115        """
116        self._engine.select_problem_for_fit(id, value)
117       
118    def get_problem_to_fit(self, id):
119        """
120        return the self.selected value of the fit problem of id
121           
122        :param id: the id of the problem
123       
124        """
125        return self._engine.get_problem_to_fit(id)
Note: See TracBrowser for help on using the repository browser.