source: sasview/park_integration/test/test_fitting_panel.py @ c8c5b9a

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 c8c5b9a was 985c88b, checked in by Gervaise Alina <gervyh@…>, 16 years ago

testing modified

  • Property mode set to 100644
File size: 6.0 KB
Line 
1"""
2    Unit tests for fitting module
3"""
4import unittest
5from sans.guitools.plottables import Theory1D
6from sans.guitools.plottables import Data1D
7from sans.fit.ScipyFitting import Parameter
8import math
9import logging
10logging.basicConfig(level=logging.DEBUG,
11                    format='%(asctime)s %(levelname)s %(message)s',
12                    filename='test_log.txt',
13                    filemode='w')
14class testFitModule(unittest.TestCase):
15    def test0(self):
16        """ test fitting for two set of data  and 2 models no constraint"""
17        from sans.fit.Loader import Load
18        load= Load()
19        #Load the first set of data
20        load.set_filename("testdata1.txt")
21        load.set_values()
22        data1 = Data1D(x=[], y=[],dx=None, dy=None)
23        load.load_data(data1)
24       
25        #Load the second set of data
26        load.set_filename("testdata2.txt")
27        load.set_values()
28        data2 = Data1D(x=[], y=[],dx=None, dy=None)
29        load.load_data(data2)
30       
31        #Importing the Fit module
32        from sans.fit.Fitting import Fit
33        fitter= Fit('park')
34        # Receives the type of model for the fitting
35        from sans.guitools.LineModel import LineModel
36        model1  = LineModel()
37        model2  = LineModel()
38       
39        #Do the fit
40        model1.setParam( 'A', 1)
41        model1.setParam( 'B', 2)
42        fitter.set_model(model1,"M1",1, ['A','B'])
43        fitter.set_data(data1,1)
44       
45        model2.setParam( 'A', 1)
46        model2.setParam( 'B', 1)
47        fitter.set_model(model2,"M2",2, ['A','B'])
48        fitter.set_data(data2,2)
49   
50       
51        chisqr1, out1, cov1,result= fitter.fit()
52        print "chisqr1",chisqr1
53        print "out1", out1
54        print " cov1", cov1
55        self.assert_(chisqr1)
56       
57    def test01(self):
58        """ test fitting for two set of data  and 2 models and 2 constraints set on on model"""
59        from sans.fit.Loader import Load
60        load= Load()
61        #Load the first set of data
62        load.set_filename("testdata1.txt")
63        load.set_values()
64        data1 = Data1D(x=[], y=[],dx=None, dy=None)
65        load.load_data(data1)
66       
67        #Load the second set of data
68        load.set_filename("testdata2.txt")
69        load.set_values()
70        data2 = Data1D(x=[], y=[],dx=None, dy=None)
71        load.load_data(data2)
72       
73        #Importing the Fit module
74        from sans.fit.Fitting import Fit
75        fitter= Fit('park')
76        # Receives the type of model for the fitting
77        from sans.guitools.LineModel import LineModel
78        model1  = LineModel()
79        model2  = LineModel()
80       
81        #Do the fit
82        model1.setParam( 'A', 1)
83        model1.setParam( 'B', 1)
84        fitter.set_model(model1,"M1",1, ['A','B'])
85        fitter.set_data(data1,1)
86       
87        model2.setParam( 'A','M1.A')
88        model2.setParam( 'B', 'M1.B')
89        fitter.set_model(model2,"M2",2, ['A','B'])
90        fitter.set_data(data2,2)
91   
92       
93        chisqr1, out1, cov1= fitter.fit()
94        print "chisqr1",chisqr1
95        print "out1", out1
96        print " cov1", cov1
97        self.assert_(chisqr1)
98     
99   
100   
101    def test1(self):
102        """ test fitting for two set of data 2 model on constraint set on 1 model"""
103        from sans.fit.Loader import Load
104        load= Load()
105        #Load the first set of data
106        load.set_filename("testdata_line.txt")
107        load.set_values()
108        data1 = Data1D(x=[], y=[],dx=None, dy=None)
109        load.load_data(data1)
110       
111        #Load the second set of data
112        load.set_filename("testdata_line1.txt")
113        load.set_values()
114        data2 = Data1D(x=[], y=[],dx=None, dy=None)
115        load.load_data(data2)
116       
117        #Importing the Fit module
118        from sans.fit.Fitting import Fit
119        fitter= Fit('park')
120        # Receives the type of model for the fitting
121        from sans.guitools.LineModel import LineModel
122        model1  = LineModel()
123        model2  = LineModel()
124       
125        #Do the fit
126        model1.setParam( 'A',1)
127        model1.setParam( 'B',1)
128        fitter.set_model(model1,"M1",1, ['A','B'])
129        fitter.set_data(data1,1)
130       
131        model2.setParam( 'A','M1.A')
132        model2.setParam( 'B', 1)
133        fitter.set_model(model2,"M2",2, ['A','B'])
134        fitter.set_data(data2,2)
135   
136       
137        chisqr1, out1, cov1= fitter.fit()
138        print "chisqr1",chisqr1
139        print "out1", out1
140        print " cov1", cov1
141        self.assert_(chisqr1)
142     
143   
144    def test2(self):
145        """ test fitting for two data 2 model not equal nombre of parameters fit"""
146        from sans.fit.Loader import Load
147        load= Load()
148        #Load the first set of data
149        load.set_filename("testdata_line.txt")
150        load.set_values()
151        data1 = Data1D(x=[], y=[],dx=None, dy=None)
152        load.load_data(data1)
153       
154        #Load the second set of data
155        load.set_filename("testdata_line1.txt")
156        load.set_values()
157        data2 = Data1D(x=[], y=[],dx=None, dy=None)
158        load.load_data(data2)
159       
160        #Importing the Fit module
161        from sans.fit.Fitting import Fit
162        fitter= Fit('park')
163        # Receives the type of model for the fitting
164        from sans.guitools.LineModel import LineModel
165        model1  = LineModel()
166        model2  = LineModel()
167       
168        #Do the fit
169        model1.setParam( 'A',1)
170        model1.setParam( 'B',1)
171        fitter.set_model(model1,"M1",1, ['A','B'])
172        fitter.set_data(data1,1)
173       
174        model2.setParam( 'A',1)
175       
176        fitter.set_model(model2,"M2",2, ['A'])
177        fitter.set_data(data2,2)
178   
179       
180        chisqr1, out1, cov1= fitter.fit()
181        print "chisqr1",chisqr1
182        print "out1", out1
183        print " cov1", cov1
184        self.assert_(chisqr1)
185       
186       
187       
188       
189   
190     
Note: See TracBrowser for help on using the repository browser.