source: sasview/test/sansmodels/test/utest_coreshellellipsoidXTmodel.py @ 3600c12

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 3600c12 was 3600c12, checked in by Peter Parker, 10 years ago

Refs #244 - Also add test.

  • Property mode set to 100644
File size: 4.0 KB
Line 
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 !!!!!!!!!!!!!!!!!
6import unittest
7import numpy 
8import math
9import time
10
11class 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       
72class 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 
Note: See TracBrowser for help on using the repository browser.