1 | # rkh 4Apr14, hacked from utest_other_models, then run sansrealspace\utest_sansview.py as python |
---|
2 | # (some OTHER tests compare data files produced by igor nist e.g. see utest_sphere_dispersity ) |
---|
3 | # this one checks output at a single point in I(Q) against a value from igor code. |
---|
4 | # Here have used same results as original CoreShellEllipsoidModel |
---|
5 | # !!!!!!!!!!!!!!!!! THERE ARE NO TESTS ON THE POLYDISPERS VERSION !!!!!!!!!!!!!!!!! |
---|
6 | import unittest |
---|
7 | import numpy |
---|
8 | import math |
---|
9 | import time |
---|
10 | |
---|
11 | class TestCoreShellEllipsoidXTModel(unittest.TestCase): |
---|
12 | """ Unit tests for CoreShellEllipsoidXT Model""" |
---|
13 | |
---|
14 | def setUp(self): |
---|
15 | from sans.models.CoreShellEllipsoidXTModel import CoreShellEllipsoidXTModel |
---|
16 | self.comp = CoreShellEllipsoidXTModel() |
---|
17 | #Give initial value to model |
---|
18 | self.comp.setParam("scale", 1.0) |
---|
19 | self.comp.setParam("equat_core", 200.0) |
---|
20 | # self.comp.setParam("polar_core", 20.0) |
---|
21 | # self.comp.setParam("equat_shell",250.0) |
---|
22 | # self.comp.setParam("polar_shell", 30.0) |
---|
23 | self.comp.setParam("X_core", 0.1) |
---|
24 | self.comp.setParam("T_shell", 50.0) |
---|
25 | self.comp.setParam("XpolarShell",0.2) |
---|
26 | self.comp.setParam("sld_shell",1e-006) |
---|
27 | self.comp.setParam("sld_core",2e-006) |
---|
28 | self.comp.setParam("sld_solvent",6.3e-006) |
---|
29 | self.comp.setParam("background",0.001) |
---|
30 | self.comp.setParam("axis_theta", 0.0) |
---|
31 | self.comp.setParam("axis_phi",0.0) |
---|
32 | |
---|
33 | self.x = numpy.array([0.4, 1.3]) |
---|
34 | self.y = numpy.array([0.5, 1.57]) |
---|
35 | self.x_array = self.comp.evalDistribution(self.x) |
---|
36 | self.y_array = self.comp.evalDistribution(self.y) |
---|
37 | |
---|
38 | qx_prime = numpy.reshape(self.x, [1,len(self.x)]) |
---|
39 | qy_prime = numpy.reshape(self.y, [len(self.y),1]) |
---|
40 | self.xy_matrix = self.comp.evalDistribution([self.x, self.y]) |
---|
41 | |
---|
42 | self.q = 0.001 |
---|
43 | self.phi= math.pi/2 |
---|
44 | self.qx= self.q*math.cos(self.phi) |
---|
45 | self.qy= self.q*math.sin(self.phi) |
---|
46 | |
---|
47 | def test1D(self): |
---|
48 | """ Test 1D model for a CoreShellEllipsoid Model""" |
---|
49 | self.assertAlmostEqual(self.comp.run(1.0), 0.001894, 4) |
---|
50 | |
---|
51 | def test1D_2(self): |
---|
52 | """ Test 2D model for a CoreShellEllipsoid Model""" |
---|
53 | self.assertAlmostEqual(self.comp.run([self.q, self.phi]), |
---|
54 | self.comp.runXY([self.qx, self.qy]),1) |
---|
55 | |
---|
56 | def testEval_1D(self): |
---|
57 | """ Test 1D model for a CoreShellEllipsoid with evalDistribution""" |
---|
58 | self.assertEquals(self.comp.run(0.4),self.x_array[0]) |
---|
59 | self.assertEquals(self.comp.run(1.3),self.x_array[1]) |
---|
60 | |
---|
61 | def testEval_2D(self): |
---|
62 | """ Test 2D model for a CoreShellEllipsoid with evalDistribution""" |
---|
63 | self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0],8) |
---|
64 | self.assertAlmostEquals(self.comp.runXY([1.3,1.57]),self.xy_matrix[1], 8) |
---|
65 | |
---|
66 | |
---|
67 | def testCriticalPoint(self): |
---|
68 | """ Test CoreShellEllipsoid at the critical point""" |
---|
69 | self.assert_(numpy.isfinite(self.comp.run(0.0))) |
---|
70 | |
---|
71 | # rkh 05Apr14 hacked from utest_model_calculate_ER |
---|
72 | class TestCoreShellEllipsoidXT(unittest.TestCase): |
---|
73 | """ Unit tests for calculate_ER (CoreShellEllipsoidXT model) """ |
---|
74 | |
---|
75 | def setUp(self): |
---|
76 | from sans.models.CoreShellEllipsoidXTModel import CoreShellEllipsoidXTModel |
---|
77 | from sans.models.DiamEllipFunc import DiamEllipFunc |
---|
78 | self.comp = CoreShellEllipsoidXTModel() |
---|
79 | self.diam = DiamEllipFunc() |
---|
80 | |
---|
81 | def test(self): |
---|
82 | """ Test 1D model for a CoreShellEllipsoidXT """ |
---|
83 | #self.comp.setParam("polar_shell", 20) |
---|
84 | #self.comp.setParam("equat_shell",400) |
---|
85 | self.comp.setParam("equat_core",350) |
---|
86 | self.comp.setParam("X_core", .05) |
---|
87 | self.comp.setParam("T_shell", 50.0) |
---|
88 | self.comp.setParam("XpolarShell",0.05) |
---|
89 | self.diam.setParam("radius_a", 20) |
---|
90 | self.diam.setParam("radius_b",400) |
---|
91 | self.assertAlmostEqual(self.comp.calculate_ER(), self.diam.run(0.1)/2) |
---|
92 | |
---|