source: sasview/park_integration/Fitting.py @ 8dc0b746

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 8dc0b746 was a6a7e8a, checked in by Jae Cho <jhjcho@…>, 15 years ago

Let fit_thread handle the fit error

  • Property mode set to 100644
File size: 3.3 KB
Line 
1"""
2    @organization: Class Fit contains ScipyFit and ParkFit methods declaration
3    allows to create instance of type ScipyFit or ParkFit to perform either
4    a park fit or a scipy fit.
5"""
6#from sans.guitools.plottables import Data1D
7#from danse.common.plottools.plottables import Data1D
8#from Loader import Load
9from scipy import optimize
10from ScipyFitting import ScipyFit
11from ParkFitting import ParkFit
12
13
14class Fit:
15    """
16        Wrap class that allows to select the fitting type.this class
17        can be used as follow :
18       
19        from sans.fit.Fitting import Fit
20        fitter= Fit()
21        fitter.fit_engine('scipy') or fitter.fit_engine('park')
22        engine = fitter.returnEngine()
23        engine.set_data(data,Uid)
24        engine.set_param( model,model.name, pars)
25        engine.set_model(model,Uid)
26       
27        chisqr1, out1, cov1=engine.fit(pars,qmin,qmax)
28    """ 
29    def __init__(self, engine='scipy'):
30        """
31            self._engine will contain an instance of ScipyFit or ParkFit
32        """
33        self._engine = None
34        self.set_engine(engine)
35         
36         
37    def set_engine(self,word):
38        """
39            Select the type of Fit
40            @param word: the keyword to select the fit type
41            @raise: if the user does not enter 'scipy' or 'park',
42             a valueError is rase
43        """
44        if word=="scipy":
45            self._engine=ScipyFit()
46        elif word=="park":
47            self._engine=ParkFit()
48        else:
49            raise ValueError, "enter the keyword scipy or park"
50       
51   
52   
53    def fit(self,handler=None, curr_thread=None):
54        """Perform the fit """
55        try:
56            return self._engine.fit(handler, curr_thread= curr_thread)
57        except:
58            #Let fit_thread handle the fit error
59            raise
60   
61    def set_model(self,model,Uid,pars=[]):
62        """
63        store a model model to fit at the position Uid of the fit engine
64        """
65        self._engine.set_model(model,Uid,pars)
66   
67   
68    def set_data(self,data,Uid,smearer=None,qmin=None, qmax=None):
69        """
70            Store data to fit at the psotion Uid of the fit engine
71            @param data: data to fit
72            @param smearer: smearerobject to smear data
73            @param qmin: the minimum q range to fit
74            @param qmax: the minimum q range to fit
75        """
76        self._engine.set_data(data,Uid,smearer,qmin, qmax)
77       
78       
79    def get_model(self,Uid):
80        """ return list of data"""
81        self._engine.get_model(Uid)
82
83
84    def remove_Fit_Problem(self,Uid):
85        """remove   fitarrange in Uid"""
86        self._engine.remove_Fit_Problem(Uid)
87       
88       
89    def select_problem_for_fit(self,Uid,value):
90        """
91            select a couple of model and data at the Uid position in dictionary
92            and set in self.selected value to value
93            @param value: the value to allow fitting. can only have the value one or zero
94        """
95        self._engine.select_problem_for_fit(Uid,value)
96       
97       
98    def get_problem_to_fit(self,Uid):
99        """
100            return the self.selected value of the fit problem of Uid
101           @param Uid: the Uid of the problem
102        """
103        return self._engine.get_problem_to_fit(Uid)
Note: See TracBrowser for help on using the repository browser.