1 | """ |
---|
2 | Unit tests for specific models. |
---|
3 | @since: 08/25/2009 |
---|
4 | @note: The models are running also with numpy array as input. |
---|
5 | Some models return limit of the function at critical point . |
---|
6 | So the user should expect finite value for some critical points. |
---|
7 | Only critical q=0 will be tested. |
---|
8 | |
---|
9 | Critical points tests that fail. the user is responsible of changing |
---|
10 | the model tested or document the failure. |
---|
11 | |
---|
12 | Initial values for models are given as the one of Igo software. |
---|
13 | @author: Gervaise Alina / UTK |
---|
14 | @summary: Run by G. Alina 10/21/2009 |
---|
15 | Most of the lamellar tests are not passing. Check lamellar im |
---|
16 | plementation. |
---|
17 | critial points tested not passing for: |
---|
18 | - Flexible Cylinder |
---|
19 | - PeakLorenzt |
---|
20 | - Squarewell Structure |
---|
21 | - StickyHstructure |
---|
22 | - hardSphereStructure |
---|
23 | |
---|
24 | @ Note: We don't use matrix for 2D anymore so testEval2D can be ignored (JC) |
---|
25 | |
---|
26 | """ |
---|
27 | |
---|
28 | import unittest |
---|
29 | import numpy |
---|
30 | import math |
---|
31 | |
---|
32 | class TestCoreShell(unittest.TestCase): |
---|
33 | """ Unit tests for coreshell model """ |
---|
34 | |
---|
35 | def setUp(self): |
---|
36 | from sans.models.CoreShellModel import CoreShellModel |
---|
37 | self.comp = CoreShellModel() |
---|
38 | #Give initial value to model |
---|
39 | self.comp.setParam("scale", 1.0) |
---|
40 | self.comp.setParam("radius", 60.0) |
---|
41 | self.comp.setParam("thickness", 10.0) |
---|
42 | self.comp.setParam("core_sld", 1.0e-6) |
---|
43 | self.comp.setParam("shell_sld",2.0e-6) |
---|
44 | self.comp.setParam("solvent_sld",3.0e-6) |
---|
45 | self.comp.setParam("Background", 0.001) |
---|
46 | |
---|
47 | self.x = numpy.array([0.4, 1.3]) |
---|
48 | self.y = numpy.array([0.5, 1.57]) |
---|
49 | self.x_array = self.comp.evalDistribution(self.x) |
---|
50 | self.y_array = self.comp.evalDistribution(self.y) |
---|
51 | |
---|
52 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
53 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
54 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
55 | |
---|
56 | def test1D(self): |
---|
57 | """ Test 1D model for a coreshell """ |
---|
58 | self.assertAlmostEquals(self.comp.run(0.4),0.00169, 4) |
---|
59 | |
---|
60 | def test1D_2(self): |
---|
61 | """ Test 2D model for a coreshell """ |
---|
62 | self.assertAlmostEquals(self.comp.run([0.4, 1.3]),0.00169, 4) |
---|
63 | |
---|
64 | def testEval_1D(self): |
---|
65 | """ Test 1D model for a coreshell with evalDistribution""" |
---|
66 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
67 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
68 | |
---|
69 | def testEval_2D(self): |
---|
70 | """ Test 2D model for a coreshell with evalDistribution""" |
---|
71 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
72 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
73 | |
---|
74 | # No more singular point |
---|
75 | #def testCriticalPoint(self): |
---|
76 | # """ Test coreshell at the critical point""" |
---|
77 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
78 | |
---|
79 | class TestMultiShellModel(unittest.TestCase): |
---|
80 | """ Unit tests for MultiShell Model """ |
---|
81 | |
---|
82 | def setUp(self): |
---|
83 | from sans.models.MultiShellModel import MultiShellModel |
---|
84 | self.comp = MultiShellModel() |
---|
85 | #Give initial value to model |
---|
86 | self.comp.setParam("scale", 1.0) |
---|
87 | self.comp.setParam("core_radius", 60.0) |
---|
88 | self.comp.setParam("s_thickness", 10.0) |
---|
89 | self.comp.setParam("w_thickness",10.0 ) |
---|
90 | self.comp.setParam("core_sld",6.4e-6) |
---|
91 | self.comp.setParam("shell_sld",4e-7) |
---|
92 | self.comp.setParam("n_pairs", 2) |
---|
93 | self.comp.setParam("Background", 0.001) |
---|
94 | |
---|
95 | self.x = numpy.array([0.4, 1.3]) |
---|
96 | self.y = numpy.array([0.5, 1.57]) |
---|
97 | self.x_array = self.comp.evalDistribution(self.x) |
---|
98 | self.y_array = self.comp.evalDistribution(self.y) |
---|
99 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
100 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
101 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
102 | |
---|
103 | def test1D(self): |
---|
104 | """ Test 1D model for a MultiShell Model """ |
---|
105 | self.assertAlmostEquals(self.comp.run(0.001), 2442.81, 2) |
---|
106 | |
---|
107 | def test1D_2(self): |
---|
108 | """ Test 2D model for a MultiShell Model""" |
---|
109 | self.assertAlmostEquals(self.comp.run([0.001, 0.30903]), 2442.81, 2) |
---|
110 | |
---|
111 | def testEval_1D(self): |
---|
112 | """ Test 1D model for a MultiShell with evalDistribution""" |
---|
113 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
114 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
115 | |
---|
116 | def testEval_2D(self): |
---|
117 | """ Test 2D model for a MultiShell with evalDistribution""" |
---|
118 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
119 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
120 | |
---|
121 | # No more singular point |
---|
122 | #def testCriticalPoint(self): |
---|
123 | # """ Test multishell at the critical point""" |
---|
124 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
125 | |
---|
126 | class TestVesicleModel(unittest.TestCase): |
---|
127 | """ Unit tests for Vesicle Model """ |
---|
128 | |
---|
129 | def setUp(self): |
---|
130 | from sans.models.VesicleModel import VesicleModel |
---|
131 | self.comp = VesicleModel() |
---|
132 | #Give initial value to model |
---|
133 | self.comp.setParam("scale", 1.0) |
---|
134 | self.comp.setParam("radius", 100.0) |
---|
135 | self.comp.setParam("solv_sld", 6.36e-6) |
---|
136 | self.comp.setParam("shell_sld",5e-7) |
---|
137 | self.comp.setParam("thickness",30.0 ) |
---|
138 | self.comp.setParam("Background", 0.001) |
---|
139 | |
---|
140 | self.x = numpy.array([0.4, 1.3]) |
---|
141 | self.y = numpy.array([0.5, 1.57]) |
---|
142 | self.x_array = self.comp.evalDistribution(self.x) |
---|
143 | self.y_array = self.comp.evalDistribution(self.y) |
---|
144 | #qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
145 | #qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
146 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
147 | |
---|
148 | def test1D(self): |
---|
149 | """ Test 1D model for a Vesicle Model """ |
---|
150 | self.assertAlmostEquals(self.comp.run(0.001), 1.71399e4,1) |
---|
151 | |
---|
152 | def test1D_2(self): |
---|
153 | """ Test 2D model for a Vesicle Model""" |
---|
154 | self.assertAlmostEquals(self.comp.run([0.001, 1.3]), 1.71399e4,1) |
---|
155 | |
---|
156 | def testEval_1D(self): |
---|
157 | """ Test 1D model for a Vesicle with evalDistribution""" |
---|
158 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
159 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
160 | |
---|
161 | def testEval_2D(self): |
---|
162 | """ Test 2D model for a Vesicle with evalDistribution""" |
---|
163 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
164 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
165 | |
---|
166 | |
---|
167 | def testCriticalPoint(self): |
---|
168 | """ Test vesicle at the critical point""" |
---|
169 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
170 | |
---|
171 | |
---|
172 | class TestBinaryHSModel(unittest.TestCase): |
---|
173 | """ Unit tests for BinaryHS Model""" |
---|
174 | |
---|
175 | def setUp(self): |
---|
176 | from sans.models.BinaryHSModel import BinaryHSModel |
---|
177 | self.comp = BinaryHSModel() |
---|
178 | #Give initial value to model |
---|
179 | self.comp.setParam("l_radius", 100.0) |
---|
180 | self.comp.setParam("ls_sld", 3.5e-6) |
---|
181 | self.comp.setParam("s_radius",25) |
---|
182 | self.comp.setParam("solvent_sld",6.36e-6 ) |
---|
183 | self.comp.setParam("ss_sld", 5e-7) |
---|
184 | self.comp.setParam("vol_frac_ss", 0.1) |
---|
185 | self.comp.setParam("vol_frac_ls", 0.2) |
---|
186 | self.comp.setParam("Background", 0.001) |
---|
187 | |
---|
188 | self.x = numpy.array([0.4, 1.3]) |
---|
189 | self.y = numpy.array([0.5, 1.57]) |
---|
190 | self.x_array = self.comp.evalDistribution(self.x) |
---|
191 | self.y_array = self.comp.evalDistribution(self.y) |
---|
192 | #qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
193 | #qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
194 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
195 | |
---|
196 | def test1D(self): |
---|
197 | """ Test 1D model for a BinaryHS Model""" |
---|
198 | self.assertAlmostEquals(self.comp.run(0.001),60.6785, 4) |
---|
199 | |
---|
200 | def test1D_2(self): |
---|
201 | """ Test 2D model for a BinaryHS Model""" |
---|
202 | self.assertAlmostEquals(self.comp.run([0.001, 1.3]),60.6785, 4) |
---|
203 | |
---|
204 | def testEval_1D(self): |
---|
205 | """ Test 1D model for a BinaryHS with evalDistribution""" |
---|
206 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
207 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
208 | |
---|
209 | def testEval_2D(self): |
---|
210 | """ Test 2D model for a BinaryHS with evalDistribution""" |
---|
211 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
212 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
213 | |
---|
214 | # No more singular point |
---|
215 | #def testCriticalPoint(self): |
---|
216 | # """ Test BinaryHS at the critical point""" |
---|
217 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
218 | |
---|
219 | |
---|
220 | class TestCoreShellCylinderModel(unittest.TestCase): |
---|
221 | """ Unit tests for CoreShellCylinder Model""" |
---|
222 | |
---|
223 | def setUp(self): |
---|
224 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
225 | self.comp = CoreShellCylinderModel() |
---|
226 | #Give initial value to model |
---|
227 | self.comp.setParam("scale", 1.0) |
---|
228 | self.comp.setParam("core_sld", 1e-6) |
---|
229 | self.comp.setParam("length", 400) |
---|
230 | self.comp.setParam("radius",20) |
---|
231 | self.comp.setParam("solvent_sld",1e-6 ) |
---|
232 | self.comp.setParam("shell_sld", 4e-6) |
---|
233 | self.comp.setParam("thickness", 10.0) |
---|
234 | self.comp.setParam("Background", 0.01) |
---|
235 | |
---|
236 | self.x = numpy.array([0.4, 1.3]) |
---|
237 | self.y = numpy.array([0.5, 1.57]) |
---|
238 | self.x_array = self.comp.evalDistribution(self.x) |
---|
239 | self.y_array = self.comp.evalDistribution(self.y) |
---|
240 | |
---|
241 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
242 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
243 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
244 | |
---|
245 | self.q = 0.001 |
---|
246 | self.phi= math.pi/2 |
---|
247 | self.qx= self.q*math.cos(self.phi) |
---|
248 | self.qy= self.q*math.sin(self.phi) |
---|
249 | |
---|
250 | def test1D(self): |
---|
251 | """ Test 1D model for a CoreShellCylinder Model""" |
---|
252 | self.assertAlmostEqual(self.comp.run(0.001), 353.56,1) |
---|
253 | |
---|
254 | def test1D_2(self): |
---|
255 | """ Test 2D model for a CoreShellCylinder Model""" |
---|
256 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
257 | self.comp.runXY([self.qx, self.qy]),1) |
---|
258 | |
---|
259 | def testEval_1D(self): |
---|
260 | """ Test 1D model for a CoreShellCylinder with evalDistribution""" |
---|
261 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
262 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
263 | |
---|
264 | def testEval_2D(self): |
---|
265 | """ Test 2D model for a CoreShellCylinder with evalDistribution""" |
---|
266 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
267 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
268 | |
---|
269 | # No more singular point |
---|
270 | #def testCriticalPoint(self): |
---|
271 | # """ Test CoreShellCylinder at the critical point""" |
---|
272 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
273 | |
---|
274 | |
---|
275 | class TestCoreShellBicelleModel(unittest.TestCase): |
---|
276 | """ Unit tests for CoreShellBicelle Model""" |
---|
277 | |
---|
278 | def setUp(self): |
---|
279 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
280 | from sans.models.CoreShellBicelleModel import CoreShellBicelleModel |
---|
281 | self.comp1 = CoreShellCylinderModel() |
---|
282 | self.comp2 = CoreShellBicelleModel() |
---|
283 | # Using the default values of CSBiselle is same as CSCylinder |
---|
284 | |
---|
285 | def testcompare1D(self): |
---|
286 | """ Test 1D model for a CoreShellBicelle Model""" |
---|
287 | self.assertAlmostEqual(self.comp1.run(0.01), self.comp2.run(0.01), 8) |
---|
288 | |
---|
289 | def testcompareEval_2D(self): |
---|
290 | """ Test 2D model for a CoreShellBicelle with evalDistribution""" |
---|
291 | self.assertAlmostEquals(self.comp1.runXY([0.4, 0.5]),self.comp2.runXY([0.4, 0.5]),8) |
---|
292 | self.assertAlmostEquals(self.comp1.runXY([1.3,1.57]),self.comp2.runXY([1.3,1.57]),8) |
---|
293 | |
---|
294 | |
---|
295 | class TestHollowCylinderModel(unittest.TestCase): |
---|
296 | """ Unit tests for HollowCylinder Model""" |
---|
297 | |
---|
298 | def setUp(self): |
---|
299 | from sans.models.HollowCylinderModel import HollowCylinderModel |
---|
300 | self.comp = HollowCylinderModel() |
---|
301 | #Give initial value to model |
---|
302 | self.comp.setParam("scale", 1.0) |
---|
303 | self.comp.setParam("core_radius",20.0) |
---|
304 | self.comp.setParam("radius",30) |
---|
305 | self.comp.setParam("length", 400) |
---|
306 | self.comp.setParam("sldCyl",6.3e-6 ) |
---|
307 | self.comp.setParam("sldSolv",1e-6 ) |
---|
308 | self.comp.setParam("Background", 0.01) |
---|
309 | |
---|
310 | self.x = numpy.array([0.4, 1.3]) |
---|
311 | self.y = numpy.array([0.5, 1.57]) |
---|
312 | self.x_array = self.comp.evalDistribution(self.x) |
---|
313 | self.y_array = self.comp.evalDistribution(self.y) |
---|
314 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
315 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
316 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
317 | |
---|
318 | self.q = 0.001 |
---|
319 | self.phi= math.pi/2 |
---|
320 | self.qx= self.q*math.cos(self.phi) |
---|
321 | self.qy= self.q*math.sin(self.phi) |
---|
322 | |
---|
323 | def test1D(self): |
---|
324 | """ Test 1D model for a HollowCylinder Model""" |
---|
325 | self.assertAlmostEqual(self.comp.run(0.001), 1756.76, 1) |
---|
326 | |
---|
327 | def test1D_2(self): |
---|
328 | """ Test 2D model for a HollowCylinder Model""" |
---|
329 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
330 | self.comp.runXY([self.qx, self.qy]),1) |
---|
331 | |
---|
332 | def testEval_1D(self): |
---|
333 | """ Test 1D model for a HollowCylinder with evalDistribution""" |
---|
334 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
335 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
336 | |
---|
337 | def testEval_2D(self): |
---|
338 | """ Test 2D model for a HollowCylinder with evalDistribution""" |
---|
339 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
340 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1],8) |
---|
341 | |
---|
342 | # No more singular point |
---|
343 | #def testCriticalPoint(self): |
---|
344 | # """ Test HollowCylinder at the critical point""" |
---|
345 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
346 | |
---|
347 | |
---|
348 | class TestFlexibleCylinderModel(unittest.TestCase): |
---|
349 | """ Unit tests for FlexibleCylinder Model""" |
---|
350 | |
---|
351 | def setUp(self): |
---|
352 | from sans.models.FlexibleCylinderModel import FlexibleCylinderModel |
---|
353 | self.comp = FlexibleCylinderModel() |
---|
354 | #Give initial value to model |
---|
355 | self.comp.setParam("scale", 1.0) |
---|
356 | self.comp.setParam("sldSolv",6.3e-6 ) |
---|
357 | self.comp.setParam("sldCyl",1e-6 ) |
---|
358 | self.comp.setParam("kuhn_length",100) |
---|
359 | self.comp.setParam("length", 1000) |
---|
360 | self.comp.setParam("radius",20) |
---|
361 | self.comp.setParam("Background", 0.0001) |
---|
362 | |
---|
363 | self.x = numpy.array([0.4, 1.3]) |
---|
364 | self.y = numpy.array([0.5, 1.57]) |
---|
365 | self.x_array = self.comp.evalDistribution(self.x) |
---|
366 | self.y_array = self.comp.evalDistribution(self.y) |
---|
367 | |
---|
368 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
369 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
370 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
371 | |
---|
372 | self.q = 0.001 |
---|
373 | self.phi= math.pi/2 |
---|
374 | self.qx= self.q*math.cos(self.phi) |
---|
375 | self.qy= self.q*math.sin(self.phi) |
---|
376 | |
---|
377 | def test1D(self): |
---|
378 | """ Test 1D model for a FlexibleCylinder Model""" |
---|
379 | self.assertAlmostEqual(self.comp.run(0.001), 3509.22, 1) |
---|
380 | |
---|
381 | def test1D_2(self): |
---|
382 | """ Test 2D model for a FlexibleCylinder Model""" |
---|
383 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
384 | self.comp.runXY([self.qx, self.qy]),1) |
---|
385 | def testEval_1D(self): |
---|
386 | """ Test 1D model for a FlexibleCylinder Model with evalDistribution""" |
---|
387 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
388 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
389 | |
---|
390 | def testEval_2D(self): |
---|
391 | """ Test 2D model for a FlexibleCylinder Model with evalDistribution""" |
---|
392 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
393 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
394 | |
---|
395 | # No more singular point |
---|
396 | #def testCriticalPoint(self): |
---|
397 | # """ Test FlexibleCylinder at the critical point""" |
---|
398 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
399 | |
---|
400 | class TestFlexCylEllipXModel(unittest.TestCase): |
---|
401 | """ Unit tests for FlexCylEllipXModel""" |
---|
402 | |
---|
403 | def setUp(self): |
---|
404 | from sans.models.FlexCylEllipXModel import FlexCylEllipXModel |
---|
405 | self.comp = FlexCylEllipXModel() |
---|
406 | #Give initial value to model |
---|
407 | self.comp.setParam("scale", 1.0) |
---|
408 | self.comp.setParam("sldSolv",6.3e-6 ) |
---|
409 | self.comp.setParam("sldCyl",1e-6 ) |
---|
410 | self.comp.setParam("kuhn_length",100) |
---|
411 | self.comp.setParam("length", 1000) |
---|
412 | self.comp.setParam("radius",20) |
---|
413 | self.comp.setParam("background", 0.0001) |
---|
414 | self.comp.setParam("axis_ratio", 1.0) |
---|
415 | |
---|
416 | self.x = numpy.array([0.4, 1.3]) |
---|
417 | self.y = numpy.array([0.5, 1.57]) |
---|
418 | self.x_array = self.comp.evalDistribution(self.x) |
---|
419 | self.y_array = self.comp.evalDistribution(self.y) |
---|
420 | |
---|
421 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
422 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
423 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
424 | |
---|
425 | self.q = 0.001 |
---|
426 | self.phi= math.pi/2 |
---|
427 | self.qx= self.q*math.cos(self.phi) |
---|
428 | self.qy= self.q*math.sin(self.phi) |
---|
429 | |
---|
430 | def test1D(self): |
---|
431 | """ Test 1D model for FlexCylEllipXModel""" |
---|
432 | self.assertAlmostEqual(self.comp.run(0.001), 3509.22, 1) |
---|
433 | |
---|
434 | def test1D_2(self): |
---|
435 | """ Test 2D model for FlexCylEllipXModel""" |
---|
436 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
437 | self.comp.runXY([self.qx, self.qy]),1) |
---|
438 | def testEval_1D(self): |
---|
439 | """ Test 1D model for FlexCylEllipXModel with evalDistribution""" |
---|
440 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
441 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
442 | |
---|
443 | def testEval_2D(self): |
---|
444 | """ Test 2D model for FlexCylEllipXModel with evalDistribution""" |
---|
445 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
446 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
447 | |
---|
448 | |
---|
449 | class TestStackedDisksModel(unittest.TestCase): |
---|
450 | """ Unit tests for StackedDisks Model""" |
---|
451 | |
---|
452 | def setUp(self): |
---|
453 | from sans.models.StackedDisksModel import StackedDisksModel |
---|
454 | self.comp = StackedDisksModel() |
---|
455 | #Give initial value to model |
---|
456 | self.comp.setParam("scale", 0.01 ) |
---|
457 | self.comp.setParam("radius",3000.0 ) |
---|
458 | self.comp.setParam("core_thick", 10.0) |
---|
459 | self.comp.setParam("layer_thick",15.0 ) |
---|
460 | self.comp.setParam("core_sld",4e-006 ) |
---|
461 | self.comp.setParam("layer_sld",-4e-007 ) |
---|
462 | self.comp.setParam("solvent_sld", 5e-006 ) |
---|
463 | self.comp.setParam("n_stacking",1.0 ) |
---|
464 | self.comp.setParam("sigma_d", 0.0) |
---|
465 | self.comp.setParam("background",0.001) |
---|
466 | self.comp.setParam("axis_theta", 0.0 ) |
---|
467 | self.comp.setParam("axis_phi",0.0) |
---|
468 | |
---|
469 | self.x = numpy.array([0.4, 1.3]) |
---|
470 | self.y = numpy.array([0.5, 1.57]) |
---|
471 | self.x_array = self.comp.evalDistribution(self.x) |
---|
472 | self.y_array = self.comp.evalDistribution(self.y) |
---|
473 | |
---|
474 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
475 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
476 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
477 | |
---|
478 | self.q = 0.001 |
---|
479 | self.phi= math.pi/2 |
---|
480 | self.qx= self.q*math.cos(self.phi) |
---|
481 | self.qy= self.q*math.sin(self.phi) |
---|
482 | |
---|
483 | def test1D(self): |
---|
484 | """ Test 1D model for a StackedDisks Model""" |
---|
485 | self.assertAlmostEqual(self.comp.run(0.001), 5075.12, 1) |
---|
486 | |
---|
487 | def test1D_2(self): |
---|
488 | """ Test 2D model for a StackedDisks Model""" |
---|
489 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
490 | self.comp.runXY([self.qx, self.qy]),1) |
---|
491 | |
---|
492 | def testEval_1D(self): |
---|
493 | """ Test 1D model for a StackedDisks Model with evalDistribution""" |
---|
494 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
495 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
496 | |
---|
497 | def testEval_2D(self): |
---|
498 | """ Test 2D model for a StackedDisks Model with evalDistribution""" |
---|
499 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
500 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
501 | |
---|
502 | # No more singular point |
---|
503 | #def testCriticalPoint(self): |
---|
504 | # """ Test StackedDisks at the critical point""" |
---|
505 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
506 | |
---|
507 | |
---|
508 | class TestParallelepipedModel(unittest.TestCase): |
---|
509 | """ Unit tests for Parallelepiped Model""" |
---|
510 | |
---|
511 | def setUp(self): |
---|
512 | from sans.models.ParallelepipedModel import ParallelepipedModel |
---|
513 | self.comp = ParallelepipedModel() |
---|
514 | #Give initial value to model |
---|
515 | self.comp.setParam("background", 0.0 ) |
---|
516 | self.comp.setParam("short_a",35) |
---|
517 | self.comp.setParam("short_b", 75) |
---|
518 | self.comp.setParam("long_c",400 ) |
---|
519 | self.comp.setParam("sldPipe", 6.3e-006 ) |
---|
520 | self.comp.setParam("sldSolv", 1e-006 ) |
---|
521 | self.comp.setParam("scale",1.0 ) |
---|
522 | |
---|
523 | self.x = numpy.array([0.4, 1.3]) |
---|
524 | self.y = numpy.array([0.5, 1.57]) |
---|
525 | self.x_array = self.comp.evalDistribution(self.x) |
---|
526 | self.y_array = self.comp.evalDistribution(self.y) |
---|
527 | |
---|
528 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
529 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
530 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
531 | |
---|
532 | self.q = 0.001 |
---|
533 | self.phi= math.pi/2 |
---|
534 | self.qx= self.q*math.cos(self.phi) |
---|
535 | self.qy= self.q*math.sin(self.phi) |
---|
536 | |
---|
537 | |
---|
538 | def test1D(self): |
---|
539 | """ Test 1D model for a Parallelepiped Model""" |
---|
540 | self.assertAlmostEqual(self.comp.run(0.001), 2935.82, 2) |
---|
541 | |
---|
542 | def test1D_2(self): |
---|
543 | """ Test 2D model for a Parallelepiped Model""" |
---|
544 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
545 | self.comp.runXY([self.qx, self.qy]),1) |
---|
546 | |
---|
547 | def testEval_1D(self): |
---|
548 | """ Test 1D model for a Parallelepiped Model with evalDistribution""" |
---|
549 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
550 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
551 | |
---|
552 | def testEval_2D(self): |
---|
553 | """ Test 2D model for a Parallelepiped Model with evalDistribution""" |
---|
554 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
555 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
556 | |
---|
557 | |
---|
558 | def testCriticalPoint(self): |
---|
559 | """ Test Parallelepiped at the critical point""" |
---|
560 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
561 | |
---|
562 | class TestEllipticalCylinderModel(unittest.TestCase): |
---|
563 | """ Unit tests for EllipticalCylinder Model""" |
---|
564 | |
---|
565 | def setUp(self): |
---|
566 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
567 | self.comp = EllipticalCylinderModel() |
---|
568 | self.comp.setParam("scale",1.0) |
---|
569 | self.comp.setParam("r_minor",20.0) |
---|
570 | self.comp.setParam("r_ratio",1.5) |
---|
571 | self.comp.setParam("length",400.0) |
---|
572 | self.comp.setParam("sldCyl",4e-006) |
---|
573 | self.comp.setParam("sldSolv",1e-006) |
---|
574 | self.comp.setParam("background",0.0) |
---|
575 | self.comp.setParam("cyl_theta",0.0) |
---|
576 | self.comp.setParam("cyl_phi",0.0) |
---|
577 | self.comp.setParam("cyl_psi",0.0) |
---|
578 | |
---|
579 | self.x = numpy.array([0.4, 1.3]) |
---|
580 | self.y = numpy.array([0.5, 1.57]) |
---|
581 | self.x_array = self.comp.evalDistribution(self.x) |
---|
582 | self.y_array = self.comp.evalDistribution(self.y) |
---|
583 | |
---|
584 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
585 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
586 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
587 | |
---|
588 | self.q = 0.001 |
---|
589 | self.phi= math.pi/2 |
---|
590 | self.qx= self.q*math.cos(self.phi) |
---|
591 | self.qy= self.q*math.sin(self.phi) |
---|
592 | |
---|
593 | def test1D(self): |
---|
594 | """ Test 1D model for a EllipticalCylinder Model""" |
---|
595 | self.assertAlmostEqual(self.comp.run(0.001), 675.504402, 4) |
---|
596 | |
---|
597 | def test1D_2(self): |
---|
598 | """ Test 2D model for a EllipticalCylinder Model""" |
---|
599 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
600 | self.comp.runXY([self.qx, self.qy]),1) |
---|
601 | |
---|
602 | def testEval_1D(self): |
---|
603 | """ Test 1D model for a EllipticalCylinder with evalDistribution""" |
---|
604 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
605 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
606 | |
---|
607 | def testEval_2D(self): |
---|
608 | """ Test 2D model for a EllipticalCylinder with evalDistribution""" |
---|
609 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
610 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
611 | |
---|
612 | |
---|
613 | def testCriticalPoint(self): |
---|
614 | """ Test EllipticalCylinder at the critical point""" |
---|
615 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
616 | |
---|
617 | |
---|
618 | class TestEllipsoidModel(unittest.TestCase): |
---|
619 | """ Unit tests for Ellipsoid Model""" |
---|
620 | |
---|
621 | def setUp(self): |
---|
622 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
623 | self.comp = EllipsoidModel() |
---|
624 | self.comp.setParam("scale",1.0) |
---|
625 | self.comp.setParam("radius_a",20.0) |
---|
626 | self.comp.setParam("radius_b",400.0) |
---|
627 | self.comp.setParam("sldEll",4e-006) |
---|
628 | self.comp.setParam("sldSolv",1e-006) |
---|
629 | self.comp.setParam("background",0.0) |
---|
630 | self.comp.setParam("axis_theta",1.57) |
---|
631 | self.comp.setParam("axis_phi",0.0) |
---|
632 | |
---|
633 | self.x = numpy.array([0.4, 1.3]) |
---|
634 | self.y = numpy.array([0.5, 1.57]) |
---|
635 | self.x_array = self.comp.evalDistribution(self.x) |
---|
636 | self.y_array = self.comp.evalDistribution(self.y) |
---|
637 | |
---|
638 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
639 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
640 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
641 | |
---|
642 | self.q = 0.001 |
---|
643 | self.phi= math.pi/2 |
---|
644 | self.qx= self.q*math.cos(self.phi) |
---|
645 | self.qy= self.q*math.sin(self.phi) |
---|
646 | |
---|
647 | def test1D(self): |
---|
648 | """ Test 1D model for a Ellipsoid Model""" |
---|
649 | self.assertAlmostEqual(self.comp.run(1.0), 0.000733968, 4) |
---|
650 | |
---|
651 | def test1D_2(self): |
---|
652 | """ Test 2D model for a Ellipsoid Model""" |
---|
653 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
654 | self.comp.runXY([self.qx, self.qy]),1) |
---|
655 | def testEval_1D(self): |
---|
656 | """ Test 1D model for a Ellipsoid Model with evalDistribution""" |
---|
657 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
658 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
659 | |
---|
660 | def testEval_2D(self): |
---|
661 | """ Test 2D model for a Ellipsoid Model with evalDistribution""" |
---|
662 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
663 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
664 | |
---|
665 | |
---|
666 | def testCriticalPoint(self): |
---|
667 | """ Test Ellipsoid at the critical point""" |
---|
668 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
669 | |
---|
670 | class TestCoreShellEllipsoidModel(unittest.TestCase): |
---|
671 | """ Unit tests for CoreShellEllipsoid Model""" |
---|
672 | |
---|
673 | def setUp(self): |
---|
674 | from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel |
---|
675 | self.comp = CoreShellEllipsoidModel() |
---|
676 | #Give initial value to model |
---|
677 | self.comp.setParam("scale", 1.0) |
---|
678 | self.comp.setParam("equat_core", 200.0) |
---|
679 | self.comp.setParam("polar_core", 20.0) |
---|
680 | self.comp.setParam("equat_shell",250.0) |
---|
681 | self.comp.setParam("polar_shell", 30.0) |
---|
682 | self.comp.setParam("sld_shell",1e-006) |
---|
683 | self.comp.setParam("sld_core",2e-006) |
---|
684 | self.comp.setParam("sld_solvent",6.3e-006) |
---|
685 | self.comp.setParam("background",0.001) |
---|
686 | self.comp.setParam("axis_theta", 0.0) |
---|
687 | self.comp.setParam("axis_phi",0.0) |
---|
688 | |
---|
689 | self.x = numpy.array([0.4, 1.3]) |
---|
690 | self.y = numpy.array([0.5, 1.57]) |
---|
691 | self.x_array = self.comp.evalDistribution(self.x) |
---|
692 | self.y_array = self.comp.evalDistribution(self.y) |
---|
693 | |
---|
694 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
695 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
696 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
697 | |
---|
698 | self.q = 0.001 |
---|
699 | self.phi= math.pi/2 |
---|
700 | self.qx= self.q*math.cos(self.phi) |
---|
701 | self.qy= self.q*math.sin(self.phi) |
---|
702 | |
---|
703 | def test1D(self): |
---|
704 | """ Test 1D model for a CoreShellEllipsoid Model""" |
---|
705 | self.assertAlmostEqual(self.comp.run(1.0), 0.001894, 4) |
---|
706 | |
---|
707 | def test1D_2(self): |
---|
708 | """ Test 2D model for a CoreShellEllipsoid Model""" |
---|
709 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
710 | self.comp.runXY([self.qx, self.qy]),1) |
---|
711 | |
---|
712 | def testEval_1D(self): |
---|
713 | """ Test 1D model for a CoreShellEllipsoid with evalDistribution""" |
---|
714 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
715 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
716 | |
---|
717 | def testEval_2D(self): |
---|
718 | """ Test 2D model for a CoreShellEllipsoid with evalDistribution""" |
---|
719 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
720 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
721 | |
---|
722 | |
---|
723 | def testCriticalPoint(self): |
---|
724 | """ Test CoreShellEllipsoid at the critical point""" |
---|
725 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
726 | |
---|
727 | class TestTriaxialEllipsoidModel(unittest.TestCase): |
---|
728 | """ Unit tests for TriaxialEllipsoid Model""" |
---|
729 | |
---|
730 | def setUp(self): |
---|
731 | from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel |
---|
732 | self.comp = TriaxialEllipsoidModel() |
---|
733 | self.comp.setParam("scale",1.0) |
---|
734 | self.comp.setParam("semi_axisA",35.0) |
---|
735 | self.comp.setParam("semi_axisB", 100.0) |
---|
736 | self.comp.setParam("semi_axisC",400.0 ) |
---|
737 | self.comp.setParam("sldSolv",6.3e-6) |
---|
738 | self.comp.setParam("sldEll",1e-6) |
---|
739 | self.comp.setParam("background",0.0) |
---|
740 | self.comp.setParam("axis_theta", 1.0) |
---|
741 | self.comp.setParam("axis_phi",0.0 ) |
---|
742 | self.comp.setParam("axis_psi",0.0 ) |
---|
743 | |
---|
744 | self.x = numpy.array([0.4, 1.3]) |
---|
745 | self.y = numpy.array([0.5, 1.57]) |
---|
746 | |
---|
747 | self.x_array = self.comp.evalDistribution(self.x) |
---|
748 | self.y_array = self.comp.evalDistribution(self.y) |
---|
749 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
750 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
751 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
752 | |
---|
753 | self.q = 0.001 |
---|
754 | self.phi= math.pi/2 |
---|
755 | self.qx= self.q*math.cos(self.phi) |
---|
756 | self.qy= self.q*math.sin(self.phi) |
---|
757 | |
---|
758 | |
---|
759 | def test1D(self): |
---|
760 | """ Test 1D model for a TriaxialEllipsoid Model""" |
---|
761 | self.assertAlmostEquals(self.comp.run(0.001),16285.6, 1) |
---|
762 | |
---|
763 | def test1D_2(self): |
---|
764 | """ Test 2D model for a TriaxialEllipsoid Model""" |
---|
765 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
766 | self.comp.runXY([self.qx, self.qy]),1) |
---|
767 | |
---|
768 | def testEval_1D(self): |
---|
769 | """ Test 1D model for a TriaxialEllipsoid Model with evalDistribution""" |
---|
770 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
771 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
772 | |
---|
773 | def testEval_2D(self): |
---|
774 | """ Test 2D model for a TriaxialEllipsoid Model with evalDistribution""" |
---|
775 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
776 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
777 | |
---|
778 | |
---|
779 | def testCriticalPoint(self): |
---|
780 | """ Test TriaxialEllipsoid at the critical point""" |
---|
781 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
782 | |
---|
783 | class TestLamellarModel(unittest.TestCase): |
---|
784 | """ Unit tests for Lamellar Model""" |
---|
785 | |
---|
786 | def setUp(self): |
---|
787 | from sans.models.LamellarModel import LamellarModel |
---|
788 | self.comp = LamellarModel() |
---|
789 | self.comp.setParam("scale",1.0) |
---|
790 | self.comp.setParam("bi_thick",50.0) |
---|
791 | self.comp.setParam("sld_bi",1e-006) |
---|
792 | self.comp.setParam("sld_sol",6.3e-006) |
---|
793 | self.comp.setParam("background",0.0) |
---|
794 | |
---|
795 | self.x = numpy.array([0.4, 1.3]) |
---|
796 | self.y = numpy.array([0.5, 1.57]) |
---|
797 | |
---|
798 | self.x_array = self.comp.evalDistribution(self.x) |
---|
799 | self.y_array = self.comp.evalDistribution(self.y) |
---|
800 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
801 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
802 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
803 | |
---|
804 | def test1D(self): |
---|
805 | """ Test 1D model for a Lamellar Model""" |
---|
806 | self.assertAlmostEquals(self.comp.run(0.001), 882289.54309, 3) |
---|
807 | |
---|
808 | def test1D_2(self): |
---|
809 | """ Test 2D model for a Lamellar Model""" |
---|
810 | self.assertAlmostEquals(self.comp.run([0.001, 1.3]),882289.54309, 3) |
---|
811 | |
---|
812 | def testEval_1D(self): |
---|
813 | """ Test 1D model for a Lamellar Model with evalDistribution""" |
---|
814 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
815 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
816 | |
---|
817 | def testEval_2D(self): |
---|
818 | """ Test 2D model for a Lamellar Model with evalDistribution""" |
---|
819 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
820 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
821 | |
---|
822 | # No more singular point |
---|
823 | #def testCriticalPoint(self): |
---|
824 | # """ Test Lamellar at the critical point""" |
---|
825 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
826 | |
---|
827 | class TestLamellarFFHGModel(unittest.TestCase): |
---|
828 | """ Unit tests for LamellarFFHG Model""" |
---|
829 | |
---|
830 | def setUp(self): |
---|
831 | from sans.models.LamellarFFHGModel import LamellarFFHGModel |
---|
832 | self.comp = LamellarFFHGModel() |
---|
833 | self.comp.setParam("scale",1.0) |
---|
834 | self.comp.setParam("t_length",15.0) |
---|
835 | self.comp.setParam("h_thickness",10.0) |
---|
836 | self.comp.setParam("sld_tail",4e-007) |
---|
837 | self.comp.setParam("sld_head",3e-006) |
---|
838 | self.comp.setParam("sld_solvent",6e-006) |
---|
839 | self.comp.setParam("background",0.0) |
---|
840 | |
---|
841 | self.x = numpy.array([0.4, 1.3]) |
---|
842 | self.y = numpy.array([0.5, 1.57]) |
---|
843 | |
---|
844 | self.x_array = self.comp.evalDistribution(self.x) |
---|
845 | self.y_array = self.comp.evalDistribution(self.y) |
---|
846 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
847 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
848 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
849 | |
---|
850 | |
---|
851 | def test1D(self): |
---|
852 | """ Test 1D model for a LamellarFFHG Model""" |
---|
853 | self.assertAlmostEquals(self.comp.run(0.001),653143.9209, 3) |
---|
854 | |
---|
855 | def test1D_2(self): |
---|
856 | """ Test 2D model for a LamellarFFHG Model""" |
---|
857 | self.assertAlmostEquals(self.comp.run([0.001, 1.3]),653143.9209, 3) |
---|
858 | |
---|
859 | def testEval_1D(self): |
---|
860 | """ Test 1D model for a LamellarFFHG Model with evalDistribution""" |
---|
861 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
862 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
863 | |
---|
864 | def testEval_2D(self): |
---|
865 | """ Test 2D model for a LamellarFFHG Model with evalDistribution""" |
---|
866 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
867 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
868 | |
---|
869 | # No more singular point |
---|
870 | #def testCriticalPoint(self): |
---|
871 | # """ Test LamellarFFHG at the critical point""" |
---|
872 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
873 | |
---|
874 | class TestLamellarPSModel(unittest.TestCase): |
---|
875 | """ Unit tests for LamellarPS Model""" |
---|
876 | |
---|
877 | def setUp(self): |
---|
878 | from sans.models.LamellarPSModel import LamellarPSModel |
---|
879 | self.comp = LamellarPSModel() |
---|
880 | self.comp.setParam("scale",1.0) |
---|
881 | self.comp.setParam("spacing",400.0) |
---|
882 | self.comp.setParam("delta",30.0) |
---|
883 | self.comp.setParam("sld_bi",6.3e-006) |
---|
884 | self.comp.setParam("sld_sol",1e-006) |
---|
885 | self.comp.setParam("n_plates",20.0) |
---|
886 | self.comp.setParam("caille", 0.1) |
---|
887 | self.comp.setParam("background",0.0) |
---|
888 | |
---|
889 | self.x = numpy.array([0.4, 1.3]) |
---|
890 | self.y = numpy.array([0.5, 1.57]) |
---|
891 | |
---|
892 | self.x_array = self.comp.evalDistribution(self.x) |
---|
893 | self.y_array = self.comp.evalDistribution(self.y) |
---|
894 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
895 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
896 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
897 | |
---|
898 | |
---|
899 | def test1D(self): |
---|
900 | """ Test 1D model for a LamellarPS Model""" |
---|
901 | self.assertAlmostEquals(self.comp.run(0.001), 27899.30836, 1) |
---|
902 | |
---|
903 | def test1D_2(self): |
---|
904 | """ Test 2D model for a LamellarPS Model""" |
---|
905 | self.assertAlmostEquals(self.comp.run([0.001, 1.3]),27899.30836, 1) |
---|
906 | |
---|
907 | def testEval_1D(self): |
---|
908 | """ Test 1D model for a LamellarPS Model with evalDistribution""" |
---|
909 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
910 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
911 | |
---|
912 | def testEval_2D(self): |
---|
913 | """ Test 2D model for a LamellarPS Model with evalDistribution""" |
---|
914 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
915 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
916 | |
---|
917 | # No more singular point |
---|
918 | #def testCriticalPoint(self): |
---|
919 | # """ Test LamellarPS at the critical point""" |
---|
920 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
921 | |
---|
922 | class TestLamellarPSHGModel(unittest.TestCase): |
---|
923 | """ Unit tests for LamellarPSHG Model""" |
---|
924 | |
---|
925 | def setUp(self): |
---|
926 | from sans.models.LamellarPSHGModel import LamellarPSHGModel |
---|
927 | self.comp = LamellarPSHGModel() |
---|
928 | self.comp.setParam("scale",1.0) |
---|
929 | self.comp.setParam("spacing",40.0) |
---|
930 | self.comp.setParam("deltaT",10.0) |
---|
931 | self.comp.setParam("deltaH",2.0) |
---|
932 | self.comp.setParam("sld_tail",4e-7) |
---|
933 | self.comp.setParam("sld_head",2e-6) |
---|
934 | self.comp.setParam("sld_solvent",6e-6) |
---|
935 | self.comp.setParam("n_plates",30) |
---|
936 | self.comp.setParam("caille",0.001) |
---|
937 | self.comp.setParam("background",0.001) |
---|
938 | |
---|
939 | self.x = numpy.array([0.4, 1.3]) |
---|
940 | self.y = numpy.array([0.5, 1.57]) |
---|
941 | |
---|
942 | self.x_array = self.comp.evalDistribution(self.x) |
---|
943 | self.y_array = self.comp.evalDistribution(self.y) |
---|
944 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
945 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
946 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
947 | |
---|
948 | def test1D(self): |
---|
949 | """ Test 1D model for a LamellarPSHG Model""" |
---|
950 | self.assertAlmostEquals(self.comp.run(0.001),6831387.29466, 3) |
---|
951 | |
---|
952 | def test1D_2(self): |
---|
953 | """ Test 2D model for a LamellarPSHG Model""" |
---|
954 | self.assertAlmostEquals(self.comp.run([0.001, 1.3]),6831387.29466,3) |
---|
955 | |
---|
956 | def testEval_1D(self): |
---|
957 | """ Test 1D model for a LamellarPSHG Model with evalDistribution""" |
---|
958 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
959 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
960 | |
---|
961 | def testEval_2D(self): |
---|
962 | """ Test 2D model for a LamellarPSHG Model with evalDistribution""" |
---|
963 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
964 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
965 | |
---|
966 | # No more singular point |
---|
967 | #def testCriticalPoint(self): |
---|
968 | # """ Test LamellarPSHG at the critical point""" |
---|
969 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
970 | |
---|
971 | class TestSquareWellStructure(unittest.TestCase): |
---|
972 | """ Unit tests for SquareWellStructure """ |
---|
973 | |
---|
974 | def setUp(self): |
---|
975 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
976 | self.comp = SquareWellStructure() |
---|
977 | self.comp.setParam("effect_radius",50.0) |
---|
978 | self.comp.setParam("volfraction",0.04) |
---|
979 | self.comp.setParam("welldepth",1.5 ) |
---|
980 | self.comp.setParam("wellwidth",1.2) |
---|
981 | |
---|
982 | self.x = numpy.array([0.4, 1.3]) |
---|
983 | self.y = numpy.array([0.5, 1.57]) |
---|
984 | |
---|
985 | self.x_array = self.comp.evalDistribution(self.x) |
---|
986 | self.y_array = self.comp.evalDistribution(self.y) |
---|
987 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
988 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
989 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
990 | |
---|
991 | |
---|
992 | def test1D(self): |
---|
993 | """ Test 1D model for a SquareWellStructure""" |
---|
994 | self.assertAlmostEqual(self.comp.run(0.001), 0.976657, 2) |
---|
995 | |
---|
996 | def test1D_2(self): |
---|
997 | """ Test 2D model for a SquareWellStructure""" |
---|
998 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.9776657,2) |
---|
999 | |
---|
1000 | def testEval_1D(self): |
---|
1001 | """ Test 1D model for a SquareWellStructure with evalDistribution""" |
---|
1002 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1003 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1004 | |
---|
1005 | def testEval_2D(self): |
---|
1006 | """ Test 2D model for a SquareWellStructure with evalDistribution""" |
---|
1007 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1008 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1009 | |
---|
1010 | # No more singular point |
---|
1011 | #def testCriticalPoint(self): |
---|
1012 | # """ Test SquareWellStructure at the critical point""" |
---|
1013 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1014 | |
---|
1015 | class TestHardsphereStructure(unittest.TestCase): |
---|
1016 | """ Unit tests for HardsphereStructure""" |
---|
1017 | |
---|
1018 | def setUp(self): |
---|
1019 | from sans.models.HardsphereStructure import HardsphereStructure |
---|
1020 | self.comp = HardsphereStructure() |
---|
1021 | self.comp.setParam("effect_radius",50.0) |
---|
1022 | self.comp.setParam("volfraction", 0.2) |
---|
1023 | self.x = numpy.array([0.4, 1.3]) |
---|
1024 | self.y = numpy.array([0.5, 1.57]) |
---|
1025 | |
---|
1026 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1027 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1028 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1029 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1030 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1031 | |
---|
1032 | |
---|
1033 | def test1D(self): |
---|
1034 | """ Test 1D model for a HardsphereStructure""" |
---|
1035 | self.assertAlmostEqual(self.comp.run(0.001),0.209128, 4) |
---|
1036 | |
---|
1037 | def test1D_2(self): |
---|
1038 | """ Test 2D model for a HardsphereStructure""" |
---|
1039 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.209128, 4) |
---|
1040 | |
---|
1041 | def testEval_1D(self): |
---|
1042 | """ Test 1D model for a HardsphereStructure with evalDistribution""" |
---|
1043 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1044 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1045 | |
---|
1046 | def testEval_2D(self): |
---|
1047 | """ Test 2D model for a HardsphereStructure with evalDistribution""" |
---|
1048 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1049 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1050 | |
---|
1051 | # No more singular point |
---|
1052 | #def testCriticalPoint(self): |
---|
1053 | # """ Test HardsphereStructure at the critical point""" |
---|
1054 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1055 | |
---|
1056 | class TestStickyHSStructure(unittest.TestCase): |
---|
1057 | """ Unit tests for StickyHSStructure""" |
---|
1058 | |
---|
1059 | def setUp(self): |
---|
1060 | from sans.models.StickyHSStructure import StickyHSStructure |
---|
1061 | self.comp = StickyHSStructure() |
---|
1062 | self.comp.setParam("effect_radius",50.0) |
---|
1063 | self.comp.setParam("volfraction",0.1) |
---|
1064 | self.comp.setParam("perturb",0.05) |
---|
1065 | self.comp.setParam("stickiness",0.2) |
---|
1066 | |
---|
1067 | self.x = numpy.array([0.4, 1.3]) |
---|
1068 | self.y = numpy.array([0.5, 1.57]) |
---|
1069 | |
---|
1070 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1071 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1072 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1073 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1074 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1075 | |
---|
1076 | def test1D(self): |
---|
1077 | """ Test 1D model for a StickyHSStructure""" |
---|
1078 | self.assertAlmostEqual(self.comp.run(0.001),1.09718, 4) |
---|
1079 | |
---|
1080 | def test1D_2(self): |
---|
1081 | """ Test 2D model for a StickyHSStructure""" |
---|
1082 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.09718, 4) |
---|
1083 | |
---|
1084 | def testEval_1D(self): |
---|
1085 | """ Test 1D model for a StickyHSStructure with evalDistribution""" |
---|
1086 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1087 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1088 | |
---|
1089 | def testEval_2D(self): |
---|
1090 | """ Test 2D model for a StickyHSStructure with evalDistribution""" |
---|
1091 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1092 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1093 | |
---|
1094 | # No more singular point |
---|
1095 | #def testCriticalPoint(self): |
---|
1096 | # """ Test StickyHSStructure at the critical point""" |
---|
1097 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1098 | |
---|
1099 | class TestHayterMSAStructure(unittest.TestCase): |
---|
1100 | """ Unit tests for HayterMSAStructure""" |
---|
1101 | |
---|
1102 | def setUp(self): |
---|
1103 | from sans.models.HayterMSAStructure import HayterMSAStructure |
---|
1104 | self.comp = HayterMSAStructure() |
---|
1105 | self.comp.setParam("effect_radius",20.75) |
---|
1106 | self.comp.setParam("charge",19.0) |
---|
1107 | self.comp.setParam("volfraction",0.0192 ) |
---|
1108 | self.comp.setParam("temperature",298) |
---|
1109 | self.comp.setParam("saltconc",0.0) |
---|
1110 | self.comp.setParam("dielectconst",78) |
---|
1111 | |
---|
1112 | self.x = numpy.array([0.4, 1.3]) |
---|
1113 | self.y = numpy.array([0.5, 1.57]) |
---|
1114 | |
---|
1115 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1116 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1117 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1118 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1119 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1120 | |
---|
1121 | def test1D(self): |
---|
1122 | """ Test 1D model for a HayterMSAStructure""" |
---|
1123 | self.assertAlmostEqual(self.comp.run(0.001),0.0712928, 4) |
---|
1124 | |
---|
1125 | def test1D_2(self): |
---|
1126 | """ Test 2D model for a HayterMSAStructure""" |
---|
1127 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.0712928, 4) |
---|
1128 | |
---|
1129 | def testEval_1D(self): |
---|
1130 | """ Test 1D model for a HayterMSAStructure with evalDistribution""" |
---|
1131 | self.assertTrue(math.fabs(self.comp.run(0.4)-self.x_array[0])<0.025, "Difference too big: %g" % math.fabs(self.comp.run(0.4)-self.x_array[0])) |
---|
1132 | self.assertTrue(math.fabs(self.comp.run(1.3)-self.x_array[1])<0.025, "Difference too big: %g" % math.fabs(self.comp.run(1.3)-self.x_array[1])) |
---|
1133 | |
---|
1134 | def testEval_2D(self): |
---|
1135 | """ Test 2D model for a HayterMSAStructure with evalDistribution""" |
---|
1136 | self.assertTrue(math.fabs(self.comp.runXY([0.4, 0.5])-self.xy_matrix[0])<0.05, "Difference too big: %g" % math.fabs(self.comp.runXY([0.4, 0.5])-self.xy_matrix[0])) |
---|
1137 | self.assertTrue(math.fabs(self.comp.runXY([1.3,1.57])-self.xy_matrix[1])<0.05, "Difference too big: %g" % math.fabs(self.comp.runXY([1.3,1.57])-self.xy_matrix[1])) |
---|
1138 | |
---|
1139 | |
---|
1140 | def testCriticalPoint(self): |
---|
1141 | """ Test HayterMSAStructure at the critical point""" |
---|
1142 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1143 | |
---|
1144 | |
---|
1145 | class TestBEPolyelectrolyte(unittest.TestCase): |
---|
1146 | """ Unit tests for BEPolyelectrolyte""" |
---|
1147 | |
---|
1148 | def setUp(self): |
---|
1149 | from sans.models.BEPolyelectrolyte import BEPolyelectrolyte |
---|
1150 | self.comp = BEPolyelectrolyte() |
---|
1151 | |
---|
1152 | self.comp.setParam('k',10) |
---|
1153 | self.comp.setParam('lb',7.1) |
---|
1154 | self.comp.setParam('h',12) |
---|
1155 | self.comp.setParam('b',10) |
---|
1156 | self.comp.setParam('cs', 0.0) |
---|
1157 | self.comp.setParam('alpha',0.05) |
---|
1158 | self.comp.setParam('c', 0.7) |
---|
1159 | self.comp.setParam('background',0.001) |
---|
1160 | |
---|
1161 | self.x = numpy.array([0.4, 1.3]) |
---|
1162 | self.y = numpy.array([0.5, 1.57]) |
---|
1163 | |
---|
1164 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1165 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1166 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1167 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1168 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1169 | |
---|
1170 | def test1D(self): |
---|
1171 | """ Test 1D model for a BEPolyelectrolyte""" |
---|
1172 | self.assertAlmostEqual(self.comp.run(0.001),0.0948, 3) |
---|
1173 | |
---|
1174 | def test1D_2(self): |
---|
1175 | """ Test 2D model for a BEPolyelectrolyte""" |
---|
1176 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.0948, 3) |
---|
1177 | |
---|
1178 | def testEval_1D(self): |
---|
1179 | """ Test 1D model for a BEPolyelectrolyte with evalDistribution""" |
---|
1180 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1181 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1182 | |
---|
1183 | def testEval_2D(self): |
---|
1184 | """ Test 2D model for a BEPolyelectrolyte with evalDistribution""" |
---|
1185 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1186 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1187 | |
---|
1188 | |
---|
1189 | def testCriticalPoint(self): |
---|
1190 | """ Test BEPolyelectrolyte at the critical point""" |
---|
1191 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1192 | |
---|
1193 | |
---|
1194 | class TestDABModel(unittest.TestCase): |
---|
1195 | """ Unit tests for DABModel""" |
---|
1196 | |
---|
1197 | def setUp(self): |
---|
1198 | from sans.models.DABModel import DABModel |
---|
1199 | self.comp = DABModel() |
---|
1200 | self.comp.setParam('length',40.0) |
---|
1201 | self.comp.setParam('scale',10.0) |
---|
1202 | self.comp.setParam('background',1.0) |
---|
1203 | |
---|
1204 | self.x = numpy.array([0.4, 1.3]) |
---|
1205 | self.y = numpy.array([0.5, 1.57]) |
---|
1206 | |
---|
1207 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1208 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1209 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1210 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1211 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1212 | |
---|
1213 | def test1D(self): |
---|
1214 | """ Test 1D model for a DABModel""" |
---|
1215 | self.assertAlmostEqual(self.comp.run(0.001),637957.9047, 3) |
---|
1216 | |
---|
1217 | def test1D_2(self): |
---|
1218 | """ Test 2D model for a DABModel""" |
---|
1219 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),637957.90473, 3) |
---|
1220 | |
---|
1221 | def testEval_1D(self): |
---|
1222 | """ Test 1D model for a DABModel with evalDistribution""" |
---|
1223 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1224 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1225 | |
---|
1226 | def testEval_2D(self): |
---|
1227 | """ Test 2D model for a DABModel with evalDistribution""" |
---|
1228 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1229 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1230 | |
---|
1231 | |
---|
1232 | def testCriticalPoint(self): |
---|
1233 | """ Test DABModel at the critical point""" |
---|
1234 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1235 | |
---|
1236 | class TestStarPolymer(unittest.TestCase): |
---|
1237 | """ Unit tests for StarPolymer""" |
---|
1238 | |
---|
1239 | def setUp(self): |
---|
1240 | from sans.models.StarPolymer import StarPolymer |
---|
1241 | self.comp = StarPolymer() |
---|
1242 | self.comp.setParam('arms',3.0) |
---|
1243 | self.comp.setParam('scale',5.0) |
---|
1244 | self.comp.setParam('background',1.0) |
---|
1245 | self.comp.setParam('R2',100.0) |
---|
1246 | |
---|
1247 | |
---|
1248 | def test1D(self): |
---|
1249 | """ Test 1D model for a StarPolymer""" |
---|
1250 | # our variables |
---|
1251 | q = 0.001 |
---|
1252 | rg = 100.0 |
---|
1253 | f = 3.0 |
---|
1254 | bkg = 1.0 |
---|
1255 | scale = 5.0 |
---|
1256 | |
---|
1257 | # equation set up |
---|
1258 | u = rg * q * q |
---|
1259 | v = u * u * f / (3*f - 2) |
---|
1260 | p = 2 / (f * v * v) |
---|
1261 | temp = v - 1 + math.exp(-v) |
---|
1262 | temp += (f - 1)/2 * math.pow(1 - math.exp(-v), 2) |
---|
1263 | p *= (temp * scale) |
---|
1264 | p += bkg |
---|
1265 | |
---|
1266 | self.assertAlmostEquals(self.comp.run(q), p, 5) |
---|
1267 | |
---|
1268 | def test1D_2(self): |
---|
1269 | """ Test 2D model for a StarPolymer""" |
---|
1270 | qx = 0.001 |
---|
1271 | qy = 1.3 |
---|
1272 | q = math.sqrt(qx*qx + qy*qy) |
---|
1273 | rg = 100.0 |
---|
1274 | f = 3.0 |
---|
1275 | bkg = 1.0 |
---|
1276 | scale = 5.0 |
---|
1277 | |
---|
1278 | # equation set up |
---|
1279 | u = rg * q * q |
---|
1280 | v = u * u * f / (3*f - 2) |
---|
1281 | p = 2 / (f * v * v) |
---|
1282 | temp = v - 1 + math.exp(-v) |
---|
1283 | temp += (f - 1)/2 * math.pow(1 - math.exp(-v), 2) |
---|
1284 | p *= (temp * scale) |
---|
1285 | p += bkg |
---|
1286 | |
---|
1287 | self.assertAlmostEqual(self.comp.runXY([0.001, 1.3]), p, 5) |
---|
1288 | |
---|
1289 | |
---|
1290 | class TestGuinierModel(unittest.TestCase): |
---|
1291 | """ Unit tests for Guinier Model""" |
---|
1292 | |
---|
1293 | def setUp(self): |
---|
1294 | from sans.models.GuinierModel import GuinierModel |
---|
1295 | self.comp = GuinierModel() |
---|
1296 | self.comp.setParam('scale',1.0) |
---|
1297 | self.comp.setParam('rg', 1) |
---|
1298 | |
---|
1299 | self.x = numpy.array([0.4, 1.3]) |
---|
1300 | self.y = numpy.array([0.5, 1.57]) |
---|
1301 | |
---|
1302 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1303 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1304 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1305 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1306 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1307 | |
---|
1308 | def test1D(self): |
---|
1309 | """ Test 1D model for a GuinierModel""" |
---|
1310 | self.assertAlmostEqual(self.comp.run(1.0),0.716531, 4) |
---|
1311 | |
---|
1312 | def test1D_2(self): |
---|
1313 | """ Test 2D model for a GuinierModel""" |
---|
1314 | self.assertAlmostEqual(self.comp.run([1.0, 1.3]),0.716531, 4) |
---|
1315 | |
---|
1316 | def testEval_1D(self): |
---|
1317 | """ Test 1D model for a GuinierModel with evalDistribution""" |
---|
1318 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1319 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1320 | |
---|
1321 | def testEval_2D(self): |
---|
1322 | """ Test 2D model for a GuinierModel with evalDistribution""" |
---|
1323 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1324 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1325 | |
---|
1326 | |
---|
1327 | def testCriticalPoint(self): |
---|
1328 | """ Test GuinierModel at the critical point""" |
---|
1329 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1330 | |
---|
1331 | |
---|
1332 | class TestDebyeModel(unittest.TestCase): |
---|
1333 | """ Unit tests for Debye Model""" |
---|
1334 | |
---|
1335 | def setUp(self): |
---|
1336 | from sans.models.DebyeModel import DebyeModel |
---|
1337 | self.comp = DebyeModel() |
---|
1338 | self.comp.setParam('rg', 50.0) |
---|
1339 | self.comp.setParam('scale',1.0) |
---|
1340 | self.comp.setParam('background',0.001) |
---|
1341 | |
---|
1342 | self.x = numpy.array([0.4, 1.3]) |
---|
1343 | self.y = numpy.array([0.5, 1.57]) |
---|
1344 | |
---|
1345 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1346 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1347 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1348 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1349 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1350 | |
---|
1351 | def test1D(self): |
---|
1352 | """ Test 1D model for a DebyeModel""" |
---|
1353 | self.assertAlmostEqual(self.comp.run(0.001),1.00017,4) |
---|
1354 | |
---|
1355 | def test1D_2(self): |
---|
1356 | """ Test 2D model for a DebyeModel""" |
---|
1357 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.00017,4) |
---|
1358 | |
---|
1359 | def testEval_1D(self): |
---|
1360 | """ Test 1D model for a DebyeModel with evalDistribution""" |
---|
1361 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1362 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1363 | |
---|
1364 | def testEval_2D(self): |
---|
1365 | """ Test 2D model for a DebyeModel with evalDistribution""" |
---|
1366 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1367 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1368 | |
---|
1369 | |
---|
1370 | def testCriticalPoint(self): |
---|
1371 | """ Test DebyeModel at the critical point""" |
---|
1372 | self.assertEquals(self.comp.run(0.0),1.001) |
---|
1373 | |
---|
1374 | |
---|
1375 | class TestPorodModel(unittest.TestCase): |
---|
1376 | """ Unit tests for PorodModel""" |
---|
1377 | |
---|
1378 | def setUp(self): |
---|
1379 | from sans.models.PorodModel import PorodModel |
---|
1380 | self.comp = PorodModel() |
---|
1381 | self.comp.setParam('scale', 1.0) |
---|
1382 | self.comp.setParam('background', 0.0) |
---|
1383 | |
---|
1384 | self.x = numpy.array([0.4, 1.3]) |
---|
1385 | self.y = numpy.array([0.5, 1.57]) |
---|
1386 | |
---|
1387 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1388 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1389 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1390 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1391 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1392 | |
---|
1393 | def test1D(self): |
---|
1394 | """ Test 1D model for a PorodModel""" |
---|
1395 | self.assertEquals(self.comp.run(0.5), 16) |
---|
1396 | |
---|
1397 | def test1D_2(self): |
---|
1398 | """ Test 2D model for a PorodModel""" |
---|
1399 | self.assertEquals(self.comp.run([0.5, 1.3]),16) |
---|
1400 | |
---|
1401 | def testEval_1D(self): |
---|
1402 | """ Test 1D model for a PorodModel with evalDistribution""" |
---|
1403 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1404 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1405 | |
---|
1406 | def testEval_2D(self): |
---|
1407 | """ Test 2D model for a PorodModel with evalDistribution""" |
---|
1408 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1409 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1410 | |
---|
1411 | |
---|
1412 | def testCreaticalPoint(self): |
---|
1413 | """ Test for critical point for PorodModel run""" |
---|
1414 | self.assertRaises(ZeroDivisionError, self.comp.run, 0.0) |
---|
1415 | |
---|
1416 | |
---|
1417 | class TestPeakGaussModel(unittest.TestCase): |
---|
1418 | """ Unit tests for PeakGaussModel""" |
---|
1419 | |
---|
1420 | def setUp(self): |
---|
1421 | from sans.models.PeakGaussModel import PeakGaussModel |
---|
1422 | self.comp = PeakGaussModel() |
---|
1423 | self.comp.setParam('scale', 100) |
---|
1424 | self.comp.setParam('B', 0.005) |
---|
1425 | self.comp.setParam('q0',0.05) |
---|
1426 | self.comp.setParam('background',1.0) |
---|
1427 | |
---|
1428 | self.x = numpy.array([0.4, 1.3]) |
---|
1429 | self.y = numpy.array([0.5, 1.57]) |
---|
1430 | |
---|
1431 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1432 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1433 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1434 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1435 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1436 | |
---|
1437 | def test1D(self): |
---|
1438 | """ Test 1D model for a PeakGauss Model""" |
---|
1439 | self.assertEquals(self.comp.run(0.001),1) |
---|
1440 | |
---|
1441 | def test1D_2(self): |
---|
1442 | """ Test 2D model for a PeakGauss Model""" |
---|
1443 | self.assertEquals(self.comp.run([0.001, 1.3]),1) |
---|
1444 | |
---|
1445 | def testEval_1D(self): |
---|
1446 | """ Test 1D model for a PeakGauss Model with evalDistribution""" |
---|
1447 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1448 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1449 | |
---|
1450 | def testEval_2D(self): |
---|
1451 | """ Test 2D model for a PeakGauss Model with evalDistribution""" |
---|
1452 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1453 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1454 | |
---|
1455 | def testCriticalPoint(self): |
---|
1456 | """ Test PeakGauss at the critical point""" |
---|
1457 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1458 | |
---|
1459 | class TestPeakLorentzModel(unittest.TestCase): |
---|
1460 | """ Unit tests for PeakLorentzModel""" |
---|
1461 | |
---|
1462 | def setUp(self): |
---|
1463 | from sans.models.PeakLorentzModel import PeakLorentzModel |
---|
1464 | self.comp = PeakLorentzModel() |
---|
1465 | self.comp.setParam('scale', 100) |
---|
1466 | self.comp.setParam('B', 0.005) |
---|
1467 | self.comp.setParam('q0',0.05) |
---|
1468 | self.comp.setParam('background',1.0) |
---|
1469 | |
---|
1470 | self.x = numpy.array([0.4, 1.3]) |
---|
1471 | self.y = numpy.array([0.5, 1.57]) |
---|
1472 | |
---|
1473 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1474 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1475 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1476 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1477 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1478 | |
---|
1479 | def test1D(self): |
---|
1480 | """ Test 1D model for a PeakLorentz Model""" |
---|
1481 | self.assertAlmostEqual(self.comp.run(0.001), 2.0305, 3) |
---|
1482 | |
---|
1483 | def test1D_2(self): |
---|
1484 | """ Test 2D model for a PeakLorentz Model""" |
---|
1485 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 2.0305, 3) |
---|
1486 | |
---|
1487 | def testEval_1D(self): |
---|
1488 | """ Test 1D model for a PeakLorentz Model with evalDistribution""" |
---|
1489 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1490 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1491 | |
---|
1492 | def testEval_2D(self): |
---|
1493 | """ Test 2D model for a PeakLorentz Model with evalDistribution""" |
---|
1494 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1495 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1496 | |
---|
1497 | |
---|
1498 | def testCriticalPoint(self): |
---|
1499 | """ Test PeakLorentz at the critical point""" |
---|
1500 | self.comp.setParam('B', 0.0) |
---|
1501 | self.assertRaises(ZeroDivisionError, self.comp.run, 10) |
---|
1502 | #self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1503 | |
---|
1504 | class TestFractalModel(unittest.TestCase): |
---|
1505 | """ Unit tests for FractalModel""" |
---|
1506 | |
---|
1507 | def setUp(self): |
---|
1508 | from sans.models.FractalModel import FractalModel |
---|
1509 | self.comp = FractalModel() |
---|
1510 | self.comp.setParam('scale', 0.05) |
---|
1511 | self.comp.setParam('radius', 5.0) |
---|
1512 | self.comp.setParam('fractal_dim', 2.0) |
---|
1513 | self.comp.setParam('cor_length',100.0) |
---|
1514 | self.comp.setParam('sldBlock', 2.0e-6) |
---|
1515 | self.comp.setParam('sldSolv', 6.35e-6) |
---|
1516 | self.comp.setParam('background',0.0) |
---|
1517 | |
---|
1518 | self.x = numpy.array([0.4, 1.3]) |
---|
1519 | self.y = numpy.array([0.5, 1.57]) |
---|
1520 | |
---|
1521 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1522 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1523 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1524 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1525 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1526 | |
---|
1527 | def test1D(self): |
---|
1528 | """ Test 1D model for a Fractal Model""" |
---|
1529 | self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3) |
---|
1530 | |
---|
1531 | def test1D_2(self): |
---|
1532 | """ Test 2D model for a Fractal Model""" |
---|
1533 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3) |
---|
1534 | |
---|
1535 | def testEval_1D(self): |
---|
1536 | """ Test 1D model for a Fractal Model with evalDistribution""" |
---|
1537 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1538 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1539 | |
---|
1540 | def testEval_2D(self): |
---|
1541 | """ Test 2D model for a Fractal Model with evalDistribution""" |
---|
1542 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1543 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1544 | |
---|
1545 | # No more singular point |
---|
1546 | #def testCriticalPoint(self): |
---|
1547 | # """ Test Fractal at the critical point""" |
---|
1548 | # self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1549 | |
---|
1550 | class TestLorentzModel(unittest.TestCase): |
---|
1551 | """ Unit tests for LorentzModel""" |
---|
1552 | |
---|
1553 | def setUp(self): |
---|
1554 | from sans.models.LorentzModel import LorentzModel |
---|
1555 | self.comp = LorentzModel() |
---|
1556 | self.comp.setParam("background",1) |
---|
1557 | self.comp.setParam("length",50) |
---|
1558 | self.comp.setParam("scale",100) |
---|
1559 | |
---|
1560 | self.x = numpy.array([0.4, 1.3]) |
---|
1561 | self.y = numpy.array([0.5, 1.57]) |
---|
1562 | |
---|
1563 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1564 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1565 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1566 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1567 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1568 | |
---|
1569 | def test1D(self): |
---|
1570 | """ Test 1D model for a Lorentz Model""" |
---|
1571 | self.assertAlmostEqual(self.comp.run(0.001),100.751, 2) |
---|
1572 | |
---|
1573 | def test1D_2(self): |
---|
1574 | """ Test 2D model for a Lorentz Model""" |
---|
1575 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),100.751, 2) |
---|
1576 | |
---|
1577 | def testEval_1D(self): |
---|
1578 | """ Test 1D model for a Lorentz Model with evalDistribution""" |
---|
1579 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1580 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1581 | |
---|
1582 | def testEval_2D(self): |
---|
1583 | """ Test 2D model for a Lorentz Model with evalDistribution""" |
---|
1584 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1585 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1586 | |
---|
1587 | |
---|
1588 | def testCriticalPoint(self): |
---|
1589 | """ Test Lorentz at the critical point""" |
---|
1590 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1591 | |
---|
1592 | |
---|
1593 | class TestPowerLawAbsModel(unittest.TestCase): |
---|
1594 | """ Unit tests for PowerLawAbsModel""" |
---|
1595 | |
---|
1596 | def setUp(self): |
---|
1597 | from sans.models.PowerLawAbsModel import PowerLawAbsModel |
---|
1598 | self.comp = PowerLawAbsModel() |
---|
1599 | self.comp.setParam("background",1) |
---|
1600 | self.comp.setParam("m",4) |
---|
1601 | self.comp.setParam("scale",1e-6) |
---|
1602 | |
---|
1603 | self.x = numpy.array([0.4, 1.3]) |
---|
1604 | self.y = numpy.array([0.5, 1.57]) |
---|
1605 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1606 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1607 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1608 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1609 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1610 | |
---|
1611 | def test1D(self): |
---|
1612 | """ Test 1D model for a PowerLawAbs Model""" |
---|
1613 | self.assertAlmostEqual(self.comp.run(0.19189), 1.00074,4) |
---|
1614 | |
---|
1615 | def test1D_2(self): |
---|
1616 | """ Test 2D model for a PowerLawAbs Model""" |
---|
1617 | self.assertAlmostEqual(self.comp.run([0.19189,1.3]), 1.00074,4) |
---|
1618 | |
---|
1619 | def testEval_1D(self): |
---|
1620 | """ Test 1D model for a PowerLawAbs Model with evalDistribution""" |
---|
1621 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1622 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1623 | |
---|
1624 | def testEval_2D(self): |
---|
1625 | """ Test 2D model for a PowerLawAbs Model with evalDistribution""" |
---|
1626 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1627 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1628 | |
---|
1629 | |
---|
1630 | def testCriticalPoint(self): |
---|
1631 | """ Test PowerLawAbs at the critical point""" |
---|
1632 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1633 | |
---|
1634 | |
---|
1635 | class TestPowerLawModel(unittest.TestCase): |
---|
1636 | """ Unit tests for PowerLawModel""" |
---|
1637 | |
---|
1638 | def setUp(self): |
---|
1639 | from sans.models.PowerLawModel import PowerLawModel |
---|
1640 | self.comp = PowerLawModel() |
---|
1641 | self.comp.setParam("background",1) |
---|
1642 | self.comp.setParam("m",4) |
---|
1643 | self.comp.setParam("scale",1e-6) |
---|
1644 | |
---|
1645 | self.x = numpy.array([0.4, 1.3]) |
---|
1646 | self.y = numpy.array([0.5, 1.57]) |
---|
1647 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1648 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1649 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1650 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1651 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1652 | |
---|
1653 | def test1D(self): |
---|
1654 | """ Test 1D model for a PowerLaw Model""" |
---|
1655 | self.assertAlmostEquals(self.comp.run(0.19189), 1.00074,4) |
---|
1656 | |
---|
1657 | def test1D_2(self): |
---|
1658 | """ Test 2D model for a PowerLawModel""" |
---|
1659 | self.assertAlmostEquals(self.comp.run([0.19189,1.3]), 1.00074,4) |
---|
1660 | |
---|
1661 | def testEval_1D(self): |
---|
1662 | """ Test 1D model for a PowerLawModel with evalDistribution""" |
---|
1663 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1664 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1665 | |
---|
1666 | def testEval_2D(self): |
---|
1667 | """ Test 2D model for a PowerLawModel with evalDistribution""" |
---|
1668 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1669 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1670 | |
---|
1671 | |
---|
1672 | def testCriticalPoint(self): |
---|
1673 | """ Test PowerLawModel at the critical point""" |
---|
1674 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1675 | |
---|
1676 | |
---|
1677 | class TestTeubnerStreyModel(unittest.TestCase): |
---|
1678 | """ Unit tests for TeubnerStreyModel""" |
---|
1679 | |
---|
1680 | def setUp(self): |
---|
1681 | from sans.models.TeubnerStreyModel import TeubnerStreyModel |
---|
1682 | self.comp = TeubnerStreyModel() |
---|
1683 | self.comp.setParam("background",0.1) |
---|
1684 | self.comp.setParam("c1",-30) |
---|
1685 | self.comp.setParam("c2",5000) |
---|
1686 | self.comp.setParam("scale",0.1) |
---|
1687 | |
---|
1688 | self.x = numpy.array([0.4, 1.3]) |
---|
1689 | self.y = numpy.array([0.5, 1.57]) |
---|
1690 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1691 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1692 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1693 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1694 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1695 | |
---|
1696 | def test1D(self): |
---|
1697 | """ Test 1D model for a TeubnerStrey Model""" |
---|
1698 | self.assertAlmostEqual(self.comp.run(0.001),10.103, 1) |
---|
1699 | |
---|
1700 | def test1D_2(self): |
---|
1701 | """ Test 2D model for a TeubnerStrey Model""" |
---|
1702 | self.assertAlmostEqual(self.comp.run([0.001, 1.3]),10.103, 1) |
---|
1703 | |
---|
1704 | def testEval_1D(self): |
---|
1705 | """ Test 1D model for a TeubnerStrey with evalDistribution""" |
---|
1706 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1707 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1708 | |
---|
1709 | def testEval_2D(self): |
---|
1710 | """ Test 2D model for a TeubnerStrey with evalDistribution""" |
---|
1711 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
1712 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1713 | |
---|
1714 | |
---|
1715 | def testCriticalPoint(self): |
---|
1716 | """ Test TeubnerStrey at the critical point""" |
---|
1717 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1718 | |
---|
1719 | |
---|
1720 | class TestLineModel(unittest.TestCase): |
---|
1721 | """ Unit tests for LineModel""" |
---|
1722 | |
---|
1723 | def setUp(self): |
---|
1724 | from sans.models.LineModel import LineModel |
---|
1725 | self.comp = LineModel() |
---|
1726 | self.comp.setParam("A",1) |
---|
1727 | self.comp.setParam("B",1) |
---|
1728 | |
---|
1729 | self.x = numpy.array([0.4, 1.3]) |
---|
1730 | self.y = numpy.array([0.5, 1.57]) |
---|
1731 | self.x_array = self.comp.evalDistribution(self.x) |
---|
1732 | self.y_array = self.comp.evalDistribution(self.y) |
---|
1733 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
1734 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
1735 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
1736 | |
---|
1737 | def test1D(self): |
---|
1738 | """ Test 1D model for a Line Model""" |
---|
1739 | self.assertEquals(self.comp.run(1.0),2) |
---|
1740 | |
---|
1741 | def testEval_1D(self): |
---|
1742 | """ Test 1D model for a Line with evalDistribution""" |
---|
1743 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
1744 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
1745 | |
---|
1746 | def testEval_2D(self): |
---|
1747 | """ Test 2D model for a Line with evalDistribution""" |
---|
1748 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0], 8) |
---|
1749 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
1750 | |
---|
1751 | |
---|
1752 | def testCriticalPoint(self): |
---|
1753 | """ Test line at the critical point""" |
---|
1754 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
1755 | |
---|
1756 | class TestMassFractalModel(unittest.TestCase): |
---|
1757 | """ Unit tests for MassFractalModel: Need to verify the test value""" |
---|
1758 | |
---|
1759 | def setUp(self): |
---|
1760 | from sans.models.MassFractalModel import MassFractalModel |
---|
1761 | self.comp = MassFractalModel() |
---|
1762 | |
---|
1763 | def testEval_1D(self): |
---|
1764 | """ Test 1D model for a MassFractalModel""" |
---|
1765 | self.assertAlmostEquals(self.comp.run(0.05), 279.59322, 4) |
---|
1766 | |
---|
1767 | class TestSurfaceFractalModel(unittest.TestCase): |
---|
1768 | """ Unit tests for SurfaceFractalModel: Need to verify the test value""" |
---|
1769 | |
---|
1770 | def setUp(self): |
---|
1771 | from sans.models.SurfaceFractalModel import SurfaceFractalModel |
---|
1772 | self.comp = SurfaceFractalModel() |
---|
1773 | |
---|
1774 | def testEval_1D(self): |
---|
1775 | """ Test 1D model for a SurfaceFractal""" |
---|
1776 | self.assertAlmostEquals(self.comp.run(0.05), 301428.65916, 4) |
---|
1777 | |
---|
1778 | class TestMassSurfaceFractal(unittest.TestCase): |
---|
1779 | """ Unit tests for MassSurfaceFractal: Need to verify the test value""" |
---|
1780 | |
---|
1781 | def setUp(self): |
---|
1782 | from sans.models.MassSurfaceFractal import MassSurfaceFractal |
---|
1783 | self.comp = MassSurfaceFractal() |
---|
1784 | |
---|
1785 | def testEval_1D(self): |
---|
1786 | """ Test 1D model for a MassSurfaceFractal""" |
---|
1787 | self.assertAlmostEquals(self.comp.run(0.05), 1.77537e-05, 4) |
---|
1788 | |
---|
1789 | if __name__ == '__main__': |
---|
1790 | unittest.main() |
---|