source: sasview/park_integration/src/sans/fit/Fitting.py @ 6e01f06

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 6e01f06 was 06e7c26, checked in by Jae Cho <jhjcho@…>, 13 years ago

fixed combined/batch

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