1 | """ |
---|
2 | Unit tests for dispersion functionality of |
---|
3 | C++ model classes |
---|
4 | """ |
---|
5 | |
---|
6 | #Note: The 'sans.models.DisperseModel' is for only the test. We use |
---|
7 | #'sans.models.dispersion_models', instead in the application. |
---|
8 | #The first uses width = sigma, while the second uses width = ratio (=sigma/mean) |
---|
9 | #for length parameters and width = sigma for angle parameters. |
---|
10 | #In Feb. 2011, we found and fixed the some precision problems in the C, so that |
---|
11 | #this test was updated too. |
---|
12 | |
---|
13 | |
---|
14 | import unittest, math, numpy |
---|
15 | |
---|
16 | class TestCylinder(unittest.TestCase): |
---|
17 | """ |
---|
18 | Testing C++ Cylinder model |
---|
19 | """ |
---|
20 | def setUp(self): |
---|
21 | from sans.models.CylinderModel import CylinderModel |
---|
22 | self.model= CylinderModel() |
---|
23 | |
---|
24 | self.model.setParam('scale', 1.0) |
---|
25 | self.model.setParam('radius', 20.0) |
---|
26 | self.model.setParam('length', 400.0) |
---|
27 | self.model.setParam('sldCyl', 4.e-6) |
---|
28 | self.model.setParam('sldSolv', 1.e-6) |
---|
29 | self.model.setParam('background', 0.0) |
---|
30 | self.model.setParam('cyl_theta', 0.0) |
---|
31 | self.model.setParam('cyl_phi', 0.0) |
---|
32 | |
---|
33 | def test_simple(self): |
---|
34 | self.assertAlmostEqual(self.model.run(0.001), 450.355, 3) |
---|
35 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3) |
---|
36 | |
---|
37 | def test_constant(self): |
---|
38 | from sans.models.dispersion_models import DispersionModel |
---|
39 | disp = DispersionModel() |
---|
40 | self.model.setParam('scale', 10.0) |
---|
41 | self.model.set_dispersion('radius', disp) |
---|
42 | self.model.dispersion['radius']['width'] = 0.25 |
---|
43 | self.model.dispersion['radius']['npts'] = 100 |
---|
44 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
45 | |
---|
46 | self.assertAlmostEqual(self.model.run(0.001), 1.021051*4527.47250339, 3) |
---|
47 | self.assertAlmostEqual(self.model.runXY([0.001, 0.001]), |
---|
48 | 1.021048*4546.997777604715, 2) |
---|
49 | |
---|
50 | def test_gaussian(self): |
---|
51 | from sans.models.dispersion_models import GaussianDispersion |
---|
52 | disp = GaussianDispersion() |
---|
53 | self.model.set_dispersion('radius', disp) |
---|
54 | self.model.dispersion['radius']['width'] = 0.25 |
---|
55 | self.model.dispersion['radius']['npts'] = 100 |
---|
56 | self.model.dispersion['radius']['nsigmas'] = 2 |
---|
57 | self.model.setParam('scale', 10.0) |
---|
58 | |
---|
59 | self.assertAlmostEqual(self.model.run(0.001), |
---|
60 | 1.1804794*4723.32213339, 3) |
---|
61 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
62 | 1.180454*4743.56, 2) |
---|
63 | |
---|
64 | def test_clone(self): |
---|
65 | from sans.models.dispersion_models import GaussianDispersion |
---|
66 | disp = GaussianDispersion() |
---|
67 | self.model.set_dispersion('radius', disp) |
---|
68 | self.model.dispersion['radius']['width'] = 0.25 |
---|
69 | self.model.dispersion['radius']['npts'] = 100 |
---|
70 | self.model.dispersion['radius']['nsigmas'] = 2 |
---|
71 | self.model.setParam('scale', 10.0) |
---|
72 | |
---|
73 | new_model = self.model.clone() |
---|
74 | self.assertAlmostEqual(new_model.run(0.001), |
---|
75 | 1.1804794*4723.32213339, 3) |
---|
76 | self.assertAlmostEqual(new_model.runXY([0.001,0.001]), |
---|
77 | 1.180454*4743.56, 2) |
---|
78 | |
---|
79 | def test_gaussian_zero(self): |
---|
80 | from sans.models.dispersion_models import GaussianDispersion |
---|
81 | disp = GaussianDispersion() |
---|
82 | self.model.set_dispersion('radius', disp) |
---|
83 | self.model.dispersion['radius']['width'] = 0.0 |
---|
84 | self.model.dispersion['radius']['npts'] = 100 |
---|
85 | self.model.dispersion['radius']['nsigmas'] = 2.5 |
---|
86 | self.model.setParam('scale', 1.0) |
---|
87 | |
---|
88 | self.assertAlmostEqual(self.model.run(0.001), 450.355, 3) |
---|
89 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3) |
---|
90 | |
---|
91 | def test_array(self): |
---|
92 | """ |
---|
93 | Perform complete rotational average and |
---|
94 | compare to 1D |
---|
95 | """ |
---|
96 | from sans.models.dispersion_models import ArrayDispersion |
---|
97 | disp_ph = ArrayDispersion() |
---|
98 | disp_th = ArrayDispersion() |
---|
99 | |
---|
100 | values_ph = numpy.zeros(100) |
---|
101 | values_th = numpy.zeros(100) |
---|
102 | weights = numpy.zeros(100) |
---|
103 | for i in range(100): |
---|
104 | values_ph[i]=(360/99.0*i) |
---|
105 | values_th[i]=(180/99.0*i) |
---|
106 | weights[i]=(1.0) |
---|
107 | |
---|
108 | disp_ph.set_weights(values_ph, weights) |
---|
109 | disp_th.set_weights(values_th, weights) |
---|
110 | |
---|
111 | self.model.set_dispersion('cyl_theta', disp_th) |
---|
112 | self.model.set_dispersion('cyl_phi', disp_ph) |
---|
113 | |
---|
114 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
115 | val_2d = self.model.runXY([0.01,0.01]) |
---|
116 | |
---|
117 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
118 | |
---|
119 | class TestCoreShellCylinder(unittest.TestCase): |
---|
120 | """ |
---|
121 | Testing C++ Cylinder model |
---|
122 | """ |
---|
123 | def setUp(self): |
---|
124 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
125 | self.model= CoreShellCylinderModel() |
---|
126 | |
---|
127 | self.model.setParam('scale', 1.0) |
---|
128 | self.model.setParam('radius', 20.0) |
---|
129 | self.model.setParam('thickness', 10.0) |
---|
130 | self.model.setParam('length', 400.0) |
---|
131 | self.model.setParam('core_sld', 1.e-6) |
---|
132 | self.model.setParam('shell_sld', 4.e-6) |
---|
133 | self.model.setParam('solvent_sld', 1.e-6) |
---|
134 | self.model.setParam('background', 0.0) |
---|
135 | self.model.setParam('axis_theta', 0.0) |
---|
136 | self.model.setParam('axis_phi', 0.0) |
---|
137 | |
---|
138 | def test_simple(self): |
---|
139 | """ |
---|
140 | Test simple 1D and 2D values |
---|
141 | Numbers taken from model that passed validation, before |
---|
142 | the update to C++ underlying class. |
---|
143 | """ |
---|
144 | self.assertAlmostEqual(self.model.run(0.001), 353.55013216754583, 3) |
---|
145 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
146 | 355.25355270620543, 3) |
---|
147 | |
---|
148 | def test_dispersion(self): |
---|
149 | """ |
---|
150 | Test with dispersion |
---|
151 | """ |
---|
152 | from sans.models.DisperseModel import DisperseModel |
---|
153 | disp = DisperseModel(self.model, ['radius', |
---|
154 | 'thickness', |
---|
155 | 'length'], [5, 2, 50]) |
---|
156 | disp.setParam('n_pts', 10) |
---|
157 | self.assertAlmostEqual(disp.run(0.001), 358.44062724936009, 3) |
---|
158 | self.assertAlmostEqual(disp.runXY([0.001,0.001]), 360.22673635224584, 3) |
---|
159 | |
---|
160 | def test_new_disp(self): |
---|
161 | from sans.models.dispersion_models import GaussianDispersion |
---|
162 | disp_rm = GaussianDispersion() |
---|
163 | self.model.set_dispersion('radius', disp_rm) |
---|
164 | self.model.dispersion['radius']['width'] = 0.25 |
---|
165 | self.model.dispersion['radius']['npts'] = 10 |
---|
166 | self.model.dispersion['radius']['nsigmas'] = 2 |
---|
167 | |
---|
168 | disp_rr = GaussianDispersion() |
---|
169 | self.model.set_dispersion('thickness', disp_rr) |
---|
170 | self.model.dispersion['thickness']['width'] = 0.2 |
---|
171 | self.model.dispersion['thickness']['npts'] = 10 |
---|
172 | self.model.dispersion['thickness']['nsigmas'] = 2 |
---|
173 | |
---|
174 | disp_len = GaussianDispersion() |
---|
175 | self.model.set_dispersion('length', disp_len) |
---|
176 | self.model.dispersion['length']['width'] = 1.0/8.0 |
---|
177 | self.model.dispersion['length']['npts'] = 10 |
---|
178 | self.model.dispersion['length']['nsigmas'] = 2 |
---|
179 | |
---|
180 | self.assertAlmostEqual(self.model.run(0.001), |
---|
181 | 1.07832610*358.44062724936009, 3) |
---|
182 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
183 | 1.07844010*360.22673635224584, 3) |
---|
184 | |
---|
185 | |
---|
186 | def test_array(self): |
---|
187 | """ |
---|
188 | Perform complete rotational average and |
---|
189 | compare to 1D |
---|
190 | """ |
---|
191 | from sans.models.dispersion_models import ArrayDispersion |
---|
192 | disp_ph = ArrayDispersion() |
---|
193 | disp_th = ArrayDispersion() |
---|
194 | |
---|
195 | values_ph = numpy.zeros(100) |
---|
196 | values_th = numpy.zeros(100) |
---|
197 | weights = numpy.zeros(100) |
---|
198 | for i in range(100): |
---|
199 | values_ph[i]=(360/99.0*i) |
---|
200 | values_th[i]=(180/99.0*i) |
---|
201 | weights[i]=(1.0) |
---|
202 | |
---|
203 | disp_ph.set_weights(values_ph, weights) |
---|
204 | disp_th.set_weights(values_th, weights) |
---|
205 | |
---|
206 | self.model.set_dispersion('axis_theta', disp_th) |
---|
207 | self.model.set_dispersion('axis_phi', disp_ph) |
---|
208 | |
---|
209 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
210 | val_2d = self.model.runXY([0.01,0.01]) |
---|
211 | |
---|
212 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
213 | |
---|
214 | |
---|
215 | |
---|
216 | class TestCoreShell(unittest.TestCase): |
---|
217 | """ |
---|
218 | Testing C++ Cylinder model |
---|
219 | """ |
---|
220 | def setUp(self): |
---|
221 | from sans.models.CoreShellModel import CoreShellModel |
---|
222 | self.model= CoreShellModel() |
---|
223 | |
---|
224 | self.model.setParam('scale', 1.0) |
---|
225 | self.model.setParam('radius', 60.0) |
---|
226 | self.model.setParam('thickness', 10.0) |
---|
227 | self.model.setParam('core_sld', 1.e-6) |
---|
228 | self.model.setParam('shell_sld', 2.e-6) |
---|
229 | self.model.setParam('solvent_sld', 3.e-6) |
---|
230 | self.model.setParam('background', 0.0) |
---|
231 | |
---|
232 | def test_simple(self): |
---|
233 | """ |
---|
234 | Test simple 1D and 2D values |
---|
235 | Numbers taken from model that passed validation, before |
---|
236 | the update to C++ underlying class. |
---|
237 | """ |
---|
238 | self.assertAlmostEqual(self.model.run(0.001), |
---|
239 | 381.27304697150055, 3) |
---|
240 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
241 | 380.93779156218682, 3) |
---|
242 | |
---|
243 | def test_dispersion(self): |
---|
244 | """ |
---|
245 | Test with dispersion |
---|
246 | """ |
---|
247 | from sans.models.DisperseModel import DisperseModel |
---|
248 | disp = DisperseModel(self.model, ['radius', 'thickness'], [10, 2]) |
---|
249 | disp.setParam('n_pts', 10) |
---|
250 | self.assertAlmostEqual(disp.run(0.001), 407.344127907553, 3) |
---|
251 | |
---|
252 | def test_new_disp(self): |
---|
253 | from sans.models.dispersion_models import GaussianDispersion |
---|
254 | disp_rm = GaussianDispersion() |
---|
255 | self.model.set_dispersion('radius', disp_rm) |
---|
256 | self.model.dispersion['radius']['width'] = 0.1666666667 |
---|
257 | self.model.dispersion['radius']['npts'] = 10 |
---|
258 | self.model.dispersion['radius']['nsigmas'] = 2 |
---|
259 | |
---|
260 | disp_rr = GaussianDispersion() |
---|
261 | self.model.set_dispersion('thickness', disp_rr) |
---|
262 | self.model.dispersion['thickness']['width'] = 0.2 |
---|
263 | self.model.dispersion['thickness']['npts'] = 10 |
---|
264 | self.model.dispersion['thickness']['nsigmas'] = 2 |
---|
265 | |
---|
266 | self.assertAlmostEqual(self.model.run(0.001), |
---|
267 | 1.16747510*407.344127907553, 3) |
---|
268 | |
---|
269 | |
---|
270 | class TestEllipsoid(unittest.TestCase): |
---|
271 | """ |
---|
272 | Testing C++ Cylinder model |
---|
273 | """ |
---|
274 | def setUp(self): |
---|
275 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
276 | self.model= EllipsoidModel() |
---|
277 | |
---|
278 | self.model.setParam('scale', 1.0) |
---|
279 | self.model.setParam('radius_a', 20.0) |
---|
280 | self.model.setParam('radius_b', 400.0) |
---|
281 | self.model.setParam('sldEll', 4.e-6) |
---|
282 | self.model.setParam('sldSolv', 1.e-6) |
---|
283 | self.model.setParam('background', 0.0) |
---|
284 | self.model.setParam('axis_theta', 89.95445) |
---|
285 | self.model.setParam('axis_phi', 0.0) |
---|
286 | |
---|
287 | def test_simple(self): |
---|
288 | """ |
---|
289 | Test simple 1D and 2D values |
---|
290 | Numbers taken from model that passed validation, before |
---|
291 | the update to C++ underlying class. |
---|
292 | """ |
---|
293 | self.assertAlmostEqual(self.model.run(0.001), |
---|
294 | 11808.842896863147, 3) |
---|
295 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
296 | 11681.990374929677, 3) |
---|
297 | |
---|
298 | def test_dispersion(self): |
---|
299 | """ |
---|
300 | Test with dispersion |
---|
301 | """ |
---|
302 | from sans.models.DisperseModel import DisperseModel |
---|
303 | disp = DisperseModel(self.model, ['radius_a', 'radius_b'], [5, 50]) |
---|
304 | disp.setParam('n_pts', 10) |
---|
305 | |
---|
306 | self.assertAlmostEqual(disp.run(0.001), 11948.72581312305, 3) |
---|
307 | self.assertAlmostEqual(disp.runXY([0.001,0.001]), 11811.972359807551, 3) |
---|
308 | |
---|
309 | def test_new_disp(self): |
---|
310 | from sans.models.dispersion_models import GaussianDispersion |
---|
311 | disp_rm = GaussianDispersion() |
---|
312 | self.model.set_dispersion('radius_a', disp_rm) |
---|
313 | self.model.dispersion['radius_a']['width'] = 0.25 |
---|
314 | self.model.dispersion['radius_a']['npts'] = 10 |
---|
315 | self.model.dispersion['radius_a']['nsigmas'] = 2 |
---|
316 | |
---|
317 | disp_rr = GaussianDispersion() |
---|
318 | self.model.set_dispersion('radius_b', disp_rr) |
---|
319 | self.model.dispersion['radius_b']['width'] = 0.125 |
---|
320 | self.model.dispersion['radius_b']['npts'] = 10 |
---|
321 | self.model.dispersion['radius_b']['nsigmas'] = 2 |
---|
322 | |
---|
323 | self.assertAlmostEqual(self.model.run(0.001), |
---|
324 | 1.10650710*11948.72581312305, 3) |
---|
325 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
326 | 1.105898*11811.972359807551, 2) |
---|
327 | |
---|
328 | def test_array(self): |
---|
329 | """ |
---|
330 | Perform complete rotational average and |
---|
331 | compare to 1D |
---|
332 | """ |
---|
333 | from sans.models.dispersion_models import ArrayDispersion |
---|
334 | disp_ph = ArrayDispersion() |
---|
335 | disp_th = ArrayDispersion() |
---|
336 | |
---|
337 | values_ph = numpy.zeros(100) |
---|
338 | values_th = numpy.zeros(100) |
---|
339 | weights = numpy.zeros(100) |
---|
340 | for i in range(100): |
---|
341 | values_ph[i]=(360/99.0*i) |
---|
342 | values_th[i]=(180/99.0*i) |
---|
343 | weights[i]=(1.0) |
---|
344 | |
---|
345 | disp_ph.set_weights(values_ph, weights) |
---|
346 | disp_th.set_weights(values_th, weights) |
---|
347 | |
---|
348 | self.model.set_dispersion('axis_theta', disp_th) |
---|
349 | self.model.set_dispersion('axis_phi', disp_ph) |
---|
350 | |
---|
351 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
352 | val_2d = self.model.runXY([0.01,0.01]) |
---|
353 | |
---|
354 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
355 | |
---|
356 | |
---|
357 | |
---|
358 | class TestSphere(unittest.TestCase): |
---|
359 | """ |
---|
360 | Testing C++ Cylinder model |
---|
361 | """ |
---|
362 | def setUp(self): |
---|
363 | from sans.models.SphereModel import SphereModel |
---|
364 | self.model= SphereModel() |
---|
365 | |
---|
366 | self.model.setParam('scale', 1.0) |
---|
367 | self.model.setParam('radius', 60.0) |
---|
368 | self.model.setParam('sldSph', 2.0) |
---|
369 | self.model.setParam('sldSolv', 1.0) |
---|
370 | self.model.setParam('background', 0.0) |
---|
371 | |
---|
372 | def test_simple(self): |
---|
373 | """ |
---|
374 | Test simple 1D and 2D values |
---|
375 | Numbers taken from model that passed validation, before |
---|
376 | the update to C++ underlying class. |
---|
377 | """ |
---|
378 | self.assertAlmostEqual(self.model.run(0.001), |
---|
379 | 90412744456148.094, delta=50.0) |
---|
380 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
381 | 90347660670656.391, 1) |
---|
382 | |
---|
383 | def test_dispersion(self): |
---|
384 | """ |
---|
385 | Test with dispersion |
---|
386 | """ |
---|
387 | from sans.models.DisperseModel import DisperseModel |
---|
388 | disp = DisperseModel(self.model, ['radius'], [10]) |
---|
389 | disp.setParam('n_pts', 10) |
---|
390 | disp.setParam('radius.npts', 10) |
---|
391 | disp.setParam('radius.nsigmas', 2.5) |
---|
392 | self.assertAlmostEqual(disp.run(0.001), 96795008379475.219, delta=50.0) |
---|
393 | |
---|
394 | def test_new_disp(self): |
---|
395 | from sans.models.dispersion_models import GaussianDispersion |
---|
396 | disp_rm = GaussianDispersion() |
---|
397 | self.model.set_dispersion('radius', disp_rm) |
---|
398 | self.model.dispersion['radius']['width'] = 0.1666666667 |
---|
399 | self.model.dispersion['radius']['npts'] = 10 |
---|
400 | self.model.dispersion['radius']['nsigmas'] = 2 |
---|
401 | |
---|
402 | #self.assertAlmostEqual(self.model.run(0.001), 96795008379475.25,3) |
---|
403 | |
---|
404 | |
---|
405 | |
---|
406 | class TestEllipticalCylinder(unittest.TestCase): |
---|
407 | """ |
---|
408 | Testing C++ Cylinder model |
---|
409 | """ |
---|
410 | def setUp(self): |
---|
411 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
412 | self.model= EllipticalCylinderModel() |
---|
413 | |
---|
414 | self.model.setParam('scale', 1.0) |
---|
415 | self.model.setParam('r_minor', 20.0) |
---|
416 | self.model.setParam('r_ratio', 1.5) |
---|
417 | self.model.setParam('length', 400.0) |
---|
418 | self.model.setParam('sldCyl', 4.0e-6) |
---|
419 | self.model.setParam('sldSolv', 1.0e-6) |
---|
420 | self.model.setParam('background', 0.0) |
---|
421 | self.model.setParam('cyl_theta', 90) |
---|
422 | self.model.setParam('cyl_phi', 0.0) |
---|
423 | self.model.setParam('cyl_psi', 0.0) |
---|
424 | |
---|
425 | def test_simple(self): |
---|
426 | """ |
---|
427 | Test simple 1D and 2D values |
---|
428 | Numbers taken from model that passed validation, before |
---|
429 | the update to C++ underlying class. |
---|
430 | """ |
---|
431 | self.assertAlmostEqual(self.model.run(0.001), |
---|
432 | 675.50440232504991, 3) |
---|
433 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
434 | 669.5173937622792, 0) |
---|
435 | |
---|
436 | def test_dispersion(self): |
---|
437 | """ |
---|
438 | Test with dispersion |
---|
439 | """ |
---|
440 | from sans.models.DisperseModel import DisperseModel |
---|
441 | disp = DisperseModel(self.model, ['r_minor', 'r_ratio', 'length'], |
---|
442 | [5, 0.25, 50]) |
---|
443 | disp.setParam('n_pts', 10) |
---|
444 | self.assertAlmostEqual(disp.run(0.001), 711.18048194151925, 3) |
---|
445 | self.assertAlmostEqual(disp.runXY([0.001,0.001]), 704.63525988095705, 0) |
---|
446 | |
---|
447 | def test_new_disp(self): |
---|
448 | from sans.models.dispersion_models import GaussianDispersion |
---|
449 | disp_rm = GaussianDispersion() |
---|
450 | self.model.set_dispersion('r_minor', disp_rm) |
---|
451 | self.model.dispersion['r_minor']['width'] = 0.25 |
---|
452 | self.model.dispersion['r_minor']['npts'] = 10 |
---|
453 | self.model.dispersion['r_minor']['nsigmas'] = 2 |
---|
454 | |
---|
455 | disp_rr = GaussianDispersion() |
---|
456 | self.model.set_dispersion('r_ratio', disp_rr) |
---|
457 | self.model.dispersion['r_ratio']['width'] = 0.25/1.5 |
---|
458 | self.model.dispersion['r_ratio']['npts'] = 10 |
---|
459 | self.model.dispersion['r_ratio']['nsigmas'] = 2 |
---|
460 | |
---|
461 | disp_len = GaussianDispersion() |
---|
462 | self.model.set_dispersion('length', disp_len) |
---|
463 | self.model.dispersion['length']['width'] = 50.0/400 |
---|
464 | self.model.dispersion['length']['npts'] = 10 |
---|
465 | self.model.dispersion['length']['nsigmas'] = 2 |
---|
466 | |
---|
467 | self.assertAlmostEqual(self.model.run(0.001), |
---|
468 | 1.23925910*711.18048194151925, 3) |
---|
469 | self.assertAlmostEqual(self.model.runXY([0.001,0.001]), |
---|
470 | 1.238955*704.63525988095705, 0) |
---|
471 | |
---|
472 | |
---|
473 | def test_array(self): |
---|
474 | """ |
---|
475 | Perform complete rotational average and |
---|
476 | compare to 1D |
---|
477 | """ |
---|
478 | from sans.models.dispersion_models import ArrayDispersion |
---|
479 | disp_ph = ArrayDispersion() |
---|
480 | disp_th = ArrayDispersion() |
---|
481 | disp_ps = ArrayDispersion() |
---|
482 | |
---|
483 | values_ph = numpy.zeros(100) |
---|
484 | values_th = numpy.zeros(100) |
---|
485 | values_ps = numpy.zeros(100) |
---|
486 | weights = numpy.zeros(100) |
---|
487 | for i in range(100): |
---|
488 | values_ps[i]=(360/99.0*i) |
---|
489 | values_ph[i]=(360/99.0*i) |
---|
490 | values_th[i]=(180/99.0*i) |
---|
491 | weights[i]=(1.0) |
---|
492 | |
---|
493 | disp_ph.set_weights(values_ph, weights) |
---|
494 | disp_th.set_weights(values_th, weights) |
---|
495 | disp_ps.set_weights(values_ps, weights) |
---|
496 | |
---|
497 | self.model.set_dispersion('cyl_theta', disp_th) |
---|
498 | self.model.set_dispersion('cyl_phi', disp_ph) |
---|
499 | self.model.set_dispersion('cyl_psi', disp_ps) |
---|
500 | |
---|
501 | val_1d = self.model.run(math.sqrt(0.0002)) |
---|
502 | val_2d = self.model.runXY([0.01,0.01]) |
---|
503 | |
---|
504 | self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02) |
---|
505 | |
---|
506 | class TestDispModel(unittest.TestCase): |
---|
507 | def setUp(self): |
---|
508 | from sans.models.CylinderModel import CylinderModel |
---|
509 | self.model = CylinderModel() |
---|
510 | |
---|
511 | |
---|
512 | def test_disp_params(self): |
---|
513 | |
---|
514 | self.assertEqual(self.model.dispersion['radius']['width'], 0.0) |
---|
515 | self.model.setParam('radius.width', 0.25) |
---|
516 | self.assertEqual(self.model.dispersion['radius']['width'], 0.25) |
---|
517 | self.assertEqual(self.model.getParam('radius.width'), 0.25) |
---|
518 | self.assertEqual(self.model.dispersion['radius']['type'], 'gaussian') |
---|
519 | |
---|
520 | |
---|
521 | if __name__ == '__main__': |
---|
522 | unittest.main() |
---|
523 | |
---|