1 | """ |
---|
2 | Unit tests for fitting module |
---|
3 | """ |
---|
4 | import unittest |
---|
5 | from sans.guitools.plottables import Theory1D |
---|
6 | from sans.guitools.plottables import Data1D |
---|
7 | from sans.fit.ScipyFitting import Parameter |
---|
8 | import math |
---|
9 | import logging |
---|
10 | logging.basicConfig(level=logging.DEBUG, |
---|
11 | format='%(asctime)s %(levelname)s %(message)s', |
---|
12 | filename='test_log.txt', |
---|
13 | filemode='w') |
---|
14 | class testFitModule(unittest.TestCase): |
---|
15 | def test0(self): |
---|
16 | """ test fitting for two set of data and one model B 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 | |
---|
41 | fitter.set_model(model1,"M1",1, {'A':1,'B':1}) |
---|
42 | fitter.set_data(data1,1) |
---|
43 | |
---|
44 | fitter.set_model(model2,"M2",2, {'A':1,'B':1}) |
---|
45 | fitter.set_data(data2,2) |
---|
46 | |
---|
47 | |
---|
48 | chisqr1, out1, cov1,result= fitter.fit() |
---|
49 | self.assert_(chisqr1) |
---|
50 | print "chisqr1",chisqr1 |
---|
51 | print "out1", out1 |
---|
52 | print " cov1", cov1 |
---|
53 | |
---|
54 | def test01(self): |
---|
55 | """ test fitting for two set of data and one model B constraint""" |
---|
56 | from sans.fit.Loader import Load |
---|
57 | load= Load() |
---|
58 | #Load the first set of data |
---|
59 | load.set_filename("testdata1.txt") |
---|
60 | load.set_values() |
---|
61 | data1 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
62 | load.load_data(data1) |
---|
63 | |
---|
64 | #Load the second set of data |
---|
65 | load.set_filename("testdata2.txt") |
---|
66 | load.set_values() |
---|
67 | data2 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
68 | load.load_data(data2) |
---|
69 | |
---|
70 | #Importing the Fit module |
---|
71 | from sans.fit.Fitting import Fit |
---|
72 | fitter= Fit('park') |
---|
73 | # Receives the type of model for the fitting |
---|
74 | from sans.guitools.LineModel import LineModel |
---|
75 | model1 = LineModel() |
---|
76 | model2 = LineModel() |
---|
77 | |
---|
78 | #Do the fit |
---|
79 | |
---|
80 | fitter.set_model(model1,"M1",1, {'A':1,'B':1}) |
---|
81 | fitter.set_data(data1,1) |
---|
82 | |
---|
83 | fitter.set_model(model2,"M2",2, {'A':'M1.A','B':'M1.B'}) |
---|
84 | fitter.set_data(data2,2) |
---|
85 | |
---|
86 | |
---|
87 | chisqr1, out1, cov1= fitter.fit() |
---|
88 | print "chisqr1",chisqr1 |
---|
89 | print "out1", out1 |
---|
90 | print " cov1", cov1 |
---|
91 | self.assert_(chisqr1) |
---|
92 | |
---|
93 | |
---|
94 | |
---|
95 | def test1(self): |
---|
96 | """ test fitting for two set of data and one model 1 constraint""" |
---|
97 | from sans.fit.Loader import Load |
---|
98 | load= Load() |
---|
99 | #Load the first set of data |
---|
100 | load.set_filename("testdata_line.txt") |
---|
101 | load.set_values() |
---|
102 | data1 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
103 | load.load_data(data1) |
---|
104 | |
---|
105 | #Load the second set of data |
---|
106 | load.set_filename("testdata_line1.txt") |
---|
107 | load.set_values() |
---|
108 | data2 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
109 | load.load_data(data2) |
---|
110 | |
---|
111 | #Importing the Fit module |
---|
112 | from sans.fit.Fitting import Fit |
---|
113 | fitter= Fit('park') |
---|
114 | # Receives the type of model for the fitting |
---|
115 | from sans.guitools.LineModel import LineModel |
---|
116 | model1 = LineModel() |
---|
117 | model2 = LineModel() |
---|
118 | |
---|
119 | #Do the fit |
---|
120 | |
---|
121 | fitter.set_model(model1,"M1",1, {'A':1,'B':1}) |
---|
122 | fitter.set_data(data1,1) |
---|
123 | |
---|
124 | fitter.set_model(model2,"M2",2, {'A':'M1.A','B':1}) |
---|
125 | fitter.set_data(data2,2) |
---|
126 | |
---|
127 | |
---|
128 | chisqr1, out1, cov1= fitter.fit() |
---|
129 | print "chisqr1",chisqr1 |
---|
130 | print "out1", out1 |
---|
131 | print " cov1", cov1 |
---|
132 | self.assert_(chisqr1) |
---|
133 | |
---|
134 | |
---|
135 | def test2(self): |
---|
136 | """ test fitting for two set of data and one model no constraint""" |
---|
137 | from sans.fit.Loader import Load |
---|
138 | load= Load() |
---|
139 | #Load the first set of data |
---|
140 | load.set_filename("testdata_line.txt") |
---|
141 | load.set_values() |
---|
142 | data1 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
143 | load.load_data(data1) |
---|
144 | |
---|
145 | #Load the second set of data |
---|
146 | load.set_filename("testdata_line1.txt") |
---|
147 | load.set_values() |
---|
148 | data2 = Data1D(x=[], y=[],dx=None, dy=None) |
---|
149 | load.load_data(data2) |
---|
150 | |
---|
151 | #Importing the Fit module |
---|
152 | from sans.fit.Fitting import Fit |
---|
153 | fitter= Fit('park') |
---|
154 | # Receives the type of model for the fitting |
---|
155 | from sans.guitools.LineModel import LineModel |
---|
156 | model1 = LineModel() |
---|
157 | model2 = LineModel() |
---|
158 | |
---|
159 | #Do the fit |
---|
160 | |
---|
161 | fitter.set_model(model1,"M1",1, {'A':1,'B':1}) |
---|
162 | fitter.set_data(data1,1) |
---|
163 | |
---|
164 | fitter.set_model(model2,"M2",2, {'A':1}) |
---|
165 | fitter.set_data(data2,2) |
---|
166 | |
---|
167 | |
---|
168 | chisqr1, out1, cov1= fitter.fit() |
---|
169 | print "chisqr1",chisqr1 |
---|
170 | print "out1", out1 |
---|
171 | print " cov1", cov1 |
---|
172 | self.assert_(chisqr1) |
---|
173 | |
---|
174 | fitter= Fit('park') |
---|
175 | # Receives the type of model for the fitting |
---|
176 | from sans.guitools.LineModel import LineModel |
---|
177 | model1 = LineModel() |
---|
178 | model2 = LineModel() |
---|
179 | |
---|
180 | #Do the fit |
---|
181 | |
---|
182 | fitter.set_model(model1,"M1",1, {'A':1,'B':1}) |
---|
183 | fitter.set_data(data1,1) |
---|
184 | |
---|
185 | fitter.set_model(model2,"M2",2, {'A':1,'B':None}) |
---|
186 | fitter.set_data(data2,2) |
---|
187 | |
---|
188 | |
---|
189 | chisqr2, out2, cov2,result= fitter.fit() |
---|
190 | print "chisqr2",chisqr2 |
---|
191 | print "out2", out2 |
---|
192 | print " cov2", cov2 |
---|
193 | self.assert_(chisqr2) |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|