source: sasview/park_integration/test/Fitting.py @ 1d02586

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 1d02586 was 1d02586, checked in by Gervaise Alina <gervyh@…>, 16 years ago
  • Property mode set to 100644
File size: 4.1 KB
Line 
1#class Fitting
2from sans.guitools.plottables import Data1D
3from Loader import Load
4from scipy import optimize
5from ScipyFitting import ScipyFit
6from ParkFitting import ParkFit
7
8
9class Fit:
10    """
11        Wrap class that allows to select the fitting type
12    """ 
13    def __init__(self):
14       
15        # To initialize a type of Fit
16        self._engine=None
17         
18    def fit_engine(self,word):
19        """
20            Select the type of Fit
21            @param word: the keyword to select the fit type
22        """
23        if word=="scipy":
24            self._engine=ScipyFit()
25        elif word=="park":
26            self._engine=ParkFit()
27        else:
28            raise ValueError, "enter the keyword scipy or park"
29    def returnEngine(self):
30        return self._engine
31   
32    def fit(self,pars, qmin=None, qmax=None):
33        """ Do the fit """
34     
35    def set_model(self,model,Uid):
36        """ Set model """
37       
38    def set_data(self,data,Uid):
39        """ Receive plottable and create a list of data to fit"""
40           
41    def get_model(self,Uid):
42        """ return list of data"""
43   
44    def set_param(self,model, pars):
45        """ Recieve a dictionary of parameter and save it """
46   
47    def add_constraint(self, constraint):
48        """ User specify contraint to fit """
49       
50    def get_constraint(self):
51        """ return the contraint value """
52 
53    def set_constraint(self,constraint):
54        """
55            receive a string as a constraint
56            @param constraint: a string used to constraint some parameters to get a
57                specific value
58        """
59if __name__ == "__main__": 
60    load= Load()
61    # test scipy
62    """test fit one data set one model with scipy """
63    #load data
64    load.set_filename("testdata_line.txt")
65    load.set_values()
66    data1 = Data1D(x=[], y=[], dx=None,dy=None)
67    data1.name = "data1"
68    load.load_data(data1)
69    #choose a model
70    from sans.guitools.LineModel import LineModel
71    model  = LineModel()
72    #Create a Fit engine
73    fitter =Fit()
74    fitter.fit_engine('scipy')
75    engine = fitter.returnEngine()
76   
77    #set the model
78    engine.set_model(model,1)
79    engine.set_data(data1,1)
80   
81    print"fit only one data SCIPY:",engine.fit({'A':2,'B':1},None,None)
82   
83   
84    """ test fit one data set one model with park """
85    fitter.fit_engine('scipy')
86    engine = fitter.returnEngine()
87    #set the model
88    engine.set_model(model,1)
89    engine.set_data(data1,1)
90   
91    print"fit only one data PARK:",engine.fit({'A':2,'B':1},None,None)
92   
93   
94    """test fit with 2 data and one model SCIPY:"""
95    # reinitialize the fitter
96    fitter =Fit()
97    #create an engine
98    fitter.fit_engine("scipy")
99    engine=fitter.returnEngine()
100    #set the model for fit
101    engine.set_model(model,2 )
102    #load 1 st data
103    load.set_filename("testdata1.txt")
104    load.set_values()
105    data2 = Data1D(x=[], y=[], dx=None,dy=None)
106    data2.name = "data2"
107    load.load_data(data2)
108    #load  2nd data
109    load.set_filename("testdata2.txt")
110    load.set_values()
111    data3 = Data1D(x=[], y=[], dx=None,dy=None)
112    data3.name = "data2"
113    load.load_data(data3)
114   
115    #set data in the engine
116    engine.set_data(data2,2)
117    engine.set_data(data3,2)
118    print"fit two data SCIPY:",engine.fit({'A':2,'B':1},None,None)
119   
120    """ test fit with 2 data and one model PARK:"""
121    fitter.fit_engine("park")
122    engine=fitter.returnEngine()
123    #set the model for fit
124    engine.set_model(model,2 )
125    #load 1 st data
126    load.set_filename("testdata1.txt")
127    load.set_values()
128    data2 = Data1D(x=[], y=[], dx=None,dy=None)
129    data2.name = "data2"
130    load.load_data(data2)
131    #load  2nd data
132    load.set_filename("testdata2.txt")
133    load.set_values()
134    data3 = Data1D(x=[], y=[], dx=None,dy=None)
135    data3.name = "data2"
136    load.load_data(data3)
137   
138    #set data in the engine
139    engine.set_data(data2,2)
140    engine.set_data(data3,2)
141    print"fit two data PARK:",engine.fit({'A':2,'B':1},None,None)
142   
143 
Note: See TracBrowser for help on using the repository browser.