""" Unit tests for specific models. @since: 08/25/2009 @note: The models are running also with numpy array as input. Some models return limit of the function at critical point . So the user should expect finite value for some critical points. Initial values for models are given as the one of Igo software. @author: Gervaise Alina / UTK """ import unittest import numpy import math class TestCoreShell(unittest.TestCase): """ Unit tests for coreshell model """ def setUp(self): from sans.models.CoreShellModel import CoreShellModel self.comp = CoreShellModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("radius", 60.0) self.comp.setParam("thickness", 10.0) self.comp.setParam("core_sld", 1.0e-6) self.comp.setParam("shell_sld",2.0e-6) self.comp.setParam("solvent_sld",3.0e-6) self.comp.setParam("Background", 0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a coreshell """ self.assertAlmostEquals(self.comp.run(0.4),0.00169, 4) def test1D_2(self): """ Test 2D model for a coreshell """ self.assertAlmostEquals(self.comp.run([0.4, 1.3]),0.00169, 4) def testEval_1D(self): """ Test 1D model for a coreshell with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a coreshell with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestMultiShellModel(unittest.TestCase): """ Unit tests for MultiShell Model """ def setUp(self): from sans.models.MultiShellModel import MultiShellModel self.comp = MultiShellModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("core_radius", 60.0) self.comp.setParam("s_thickness", 10.0) self.comp.setParam("w_thickness",10.0 ) self.comp.setParam("core_sld",6.4e-6) self.comp.setParam("shell_sld",4e-7) self.comp.setParam("n_pairs", 2) self.comp.setParam("Background", 0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a MultiShell Model """ self.assertAlmostEquals(self.comp.run(0.001), 2442.81, 2) def test1D_2(self): """ Test 2D model for a MultiShell Model""" self.assertAlmostEquals(self.comp.run([0.001, 0.30903]), 2442.81, 2) def testEval_1D(self): """ Test 1D model for a MultiShell with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a MultiShell with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestVesicleModel(unittest.TestCase): """ Unit tests for Vesicle Model """ def setUp(self): from sans.models.VesicleModel import VesicleModel self.comp = VesicleModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("radius", 100.0) self.comp.setParam("core_sld", 6.36e-6) self.comp.setParam("shell_sld",5e-7) self.comp.setParam("thickness",30.0 ) self.comp.setParam("Background", 0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a Vesicle Model """ self.assertAlmostEquals(self.comp.run(0.001), 1.71399e4,1) def test1D_2(self): """ Test 2D model for a Vesicle Model""" self.assertAlmostEquals(self.comp.run([0.001, 1.3]), 1.71399e4,1) def testEval_1D(self): """ Test 1D model for a Vesicle with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Vesicle with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestBinaryHSModel(unittest.TestCase): """ Unit tests for BinaryHS Model""" def setUp(self): from sans.models.BinaryHSModel import BinaryHSModel self.comp = BinaryHSModel() #Give initial value to model self.comp.setParam("l_radius", 100.0) self.comp.setParam("ls_sld", 3.5e-6) self.comp.setParam("s_radius",25) self.comp.setParam("solvent_sld",6.36e-6 ) self.comp.setParam("ss_sld", 5e-7) self.comp.setParam("vol_frac_ss", 0.1) self.comp.setParam("vol_frac_ls", 0.2) self.comp.setParam("Background", 0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a BinaryHS Model""" self.assertAlmostEquals(self.comp.run(0.001),60.6785, 4) def test1D_2(self): """ Test 2D model for a BinaryHS Model""" self.assertAlmostEquals(self.comp.run([0.001, 1.3]),60.6785, 4) def testEval_1D(self): """ Test 1D model for a BinaryHS with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a BinaryHS with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestCoreShellCylinderModel(unittest.TestCase): """ Unit tests for CoreShellCylinder Model""" def setUp(self): from sans.models.CoreShellCylinderModel import CoreShellCylinderModel self.comp = CoreShellCylinderModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("core_sld", 1e-6) self.comp.setParam("length", 400) self.comp.setParam("radius",20) self.comp.setParam("solvent_sld",1e-6 ) self.comp.setParam("shell_sld", 4e-6) self.comp.setParam("thickness", 10.0) self.comp.setParam("Background", 0.01) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a CoreShellCylinder Model""" self.assertAlmostEqual(self.comp.run(0.001), 353.56,1) def test1D_2(self): """ Test 2D model for a CoreShellCylinder Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a CoreShellCylinder with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a CoreShellCylinder with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestHollowCylinderModel(unittest.TestCase): """ Unit tests for HollowCylinder Model""" def setUp(self): from sans.models.HollowCylinderModel import HollowCylinderModel self.comp = HollowCylinderModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("core_radius",20.0) self.comp.setParam("radius",30) self.comp.setParam("length", 400) self.comp.setParam("contrast",5.3e-6 ) self.comp.setParam("Background", 0.01) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a HollowCylinder Model""" self.assertAlmostEqual(self.comp.run(0.001), 1756.76, 1) def test1D_2(self): """ Test 2D model for a HollowCylinder Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a HollowCylinder with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a HollowCylinder with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestFlexibleCylinderModel(unittest.TestCase): """ Unit tests for FlexibleCylinder Model""" def setUp(self): from sans.models.FlexibleCylinderModel import FlexibleCylinderModel self.comp = FlexibleCylinderModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("contrast",5.3e-6 ) self.comp.setParam("kuhn_length",100) self.comp.setParam("length", 1000) self.comp.setParam("radius",20) self.comp.setParam("Background", 0.0001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a FlexibleCylinder Model""" self.assertAlmostEqual(self.comp.run(0.001), 3509.22, 1) def test1D_2(self): """ Test 2D model for a FlexibleCylinder Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a FlexibleCylinder Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a FlexibleCylinder Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestStackedDisksModel(unittest.TestCase): """ Unit tests for StackedDisks Model""" def setUp(self): from sans.models.StackedDisksModel import StackedDisksModel self.comp = StackedDisksModel() #Give initial value to model self.comp.setParam("scale", 0.01 ) self.comp.setParam("radius",3000.0 ) self.comp.setParam("core_thick", 10.0) self.comp.setParam("layer_thick",15.0 ) self.comp.setParam("core_sld",4e-006 ) self.comp.setParam("layer_sld",-4e-007 ) self.comp.setParam("solvent_sld", 5e-006 ) self.comp.setParam("n_stacking",1.0 ) self.comp.setParam("sigma_d", 0.0) self.comp.setParam("background",0.001) self.comp.setParam("axis_theta", 0.0 ) self.comp.setParam("axis_phi",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a StackedDisks Model""" self.assertAlmostEqual(self.comp.run(0.001), 5075.12, 1) def test1D_2(self): """ Test 2D model for a StackedDisks Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a StackedDisks Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a StackedDisks Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestParallelepipedModel(unittest.TestCase): """ Unit tests for Parallelepiped Model""" def setUp(self): from sans.models.ParallelepipedModel import ParallelepipedModel self.comp = ParallelepipedModel() #Give initial value to model self.comp.setParam("background", 0.0 ) self.comp.setParam("short_a",35) self.comp.setParam("short_b", 75) self.comp.setParam("long_c",400 ) self.comp.setParam("contrast", 5.3e-006 ) self.comp.setParam("scale",1.0 ) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a Parallelepiped Model""" self.assertAlmostEqual(self.comp.run(0.001), 2935.82, 2) def test1D_2(self): """ Test 2D model for a Parallelepiped Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a Parallelepiped Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Parallelepiped Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestEllipticalCylinderModel(unittest.TestCase): """ Unit tests for EllipticalCylinder Model""" def setUp(self): from sans.models.EllipticalCylinderModel import EllipticalCylinderModel self.comp = EllipticalCylinderModel() self.comp.setParam("scale",1.0) self.comp.setParam("r_minor",20.0) self.comp.setParam("r_ratio",1.5) self.comp.setParam("length",400.0) self.comp.setParam("contrast",5.3e-006) self.comp.setParam("background",0.0) self.comp.setParam("cyl_theta",0.0) self.comp.setParam("cyl_phi",0.0) self.comp.setParam("cyl_psi",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a EllipticalCylinder Model""" self.assertAlmostEqual(self.comp.run(0.001),2108.32, 1) def test1D_2(self): """ Test 2D model for a EllipticalCylinder Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a EllipticalCylinder with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a EllipticalCylinder with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestEllipsoidModel(unittest.TestCase): """ Unit tests for Ellipsoid Model""" def setUp(self): from sans.models.EllipsoidModel import EllipsoidModel self.comp = EllipsoidModel() self.comp.setParam("scale",1.0) self.comp.setParam("radius_a",20.0) self.comp.setParam("radius_b",400.0) self.comp.setParam("contrast",3e-006) self.comp.setParam("background",0.0) self.comp.setParam("axis_theta",1.57) self.comp.setParam("axis_phi",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a Ellipsoid Model""" self.assertAlmostEqual(self.comp.run(1.0), 0.000733968, 4) def test1D_2(self): """ Test 2D model for a Ellipsoid Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a Ellipsoid Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Ellipsoid Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestCoreShellEllipsoidModel(unittest.TestCase): """ Unit tests for CoreShellEllipsoid Model""" def setUp(self): from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel self.comp = CoreShellEllipsoidModel() #Give initial value to model self.comp.setParam("scale", 1.0) self.comp.setParam("equat_core", 200.0) self.comp.setParam("polar_core", 20.0) self.comp.setParam("equat_shell",250.0) self.comp.setParam("polar_shell", 30.0) self.comp.setParam("contrast",1e-006) self.comp.setParam("sld_solvent",6.3e-006) self.comp.setParam("background",0.001) self.comp.setParam("axis_theta", 0.0) self.comp.setParam("axis_phi",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a CoreShellEllipsoid Model""" self.assertAlmostEqual(self.comp.run(1.0), 0.002578943, 4) def test1D_2(self): """ Test 2D model for a CoreShellEllipsoid Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a CoreShellEllipsoid with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a CoreShellEllipsoid with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestTriaxialEllipsoidModel(unittest.TestCase): """ Unit tests for TriaxialEllipsoid Model""" def setUp(self): from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel self.comp = TriaxialEllipsoidModel() self.comp.setParam("scale",1.0) self.comp.setParam("semi_axisA",35.0) self.comp.setParam("semi_axisB", 100.0) self.comp.setParam("semi_axisC",400.0 ) self.comp.setParam("contrast",5.3e-6) self.comp.setParam("background",0.0) self.comp.setParam("axis_theta", 1.0) self.comp.setParam("axis_phi",0.0 ) self.comp.setParam("axis_psi",0.0 ) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) self.q = 0.001 self.phi= math.pi/2 self.qx= self.q*math.cos(self.phi) self.qy= self.q*math.sin(self.phi) def test1D(self): """ Test 1D model for a TriaxialEllipsoid Model""" self.assertAlmostEquals(self.comp.run(0.001),16285.6, 1) def test1D_2(self): """ Test 2D model for a TriaxialEllipsoid Model""" self.assertAlmostEqual(self.comp.run([self.q, self.phi]), self.comp.runXY([self.qx, self.qy]),1) def testEval_1D(self): """ Test 1D model for a TriaxialEllipsoid Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a TriaxialEllipsoid Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestLamellarModel(unittest.TestCase): """ Unit tests for Lamellar Model""" def setUp(self): from sans.models.LamellarModel import LamellarModel self.comp = LamellarModel() self.comp.setParam("scale",1.0) self.comp.setParam("bi_thick",50.0) self.comp.setParam("sld_bi",1e-006) self.comp.setParam("sld_sol",6.3e-006) self.comp.setParam("background",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a Lamellar Model""" self.assertAlmostEquals(self.comp.run(0.001), 902120) def test1D_2(self): """ Test 2D model for a Lamellar Model""" self.assertAlmostEquals(self.comp.run([0.001, 1.3]),902120) def testEval_1D(self): """ Test 1D model for a Lamellar Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Lamellar Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestLamellarFFHGModel(unittest.TestCase): """ Unit tests for LamellarFFHG Model""" def setUp(self): from sans.models.LamellarFFHGModel import LamellarFFHGModel self.comp = LamellarFFHGModel() self.comp.setParam("scale",1.0) self.comp.setParam("t_length",15.0) self.comp.setParam("h_thickness",10.0) self.comp.setParam("sld_tail",4e-007) self.comp.setParam("sld_head",3e-006) self.comp.setParam("sld_solvent",6e-006) self.comp.setParam("background",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a LamellarFFHG Model""" self.assertAlmostEquals(self.comp.run(0.001),653144) def test1D_2(self): """ Test 2D model for a LamellarFFHG Model""" self.assertAlmostEquals(self.comp.run([0.001, 1.3]),653144) def testEval_1D(self): """ Test 1D model for a LamellarFFHG Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a LamellarFFHG Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestLamellarPSModel(unittest.TestCase): """ Unit tests for LamellarPS Model""" def setUp(self): from sans.models.LamellarPSModel import LamellarPSModel self.comp = LamellarPSModel() self.comp.setParam("scale",1.0) self.comp.setParam("spacing",400.0) self.comp.setParam("delta",30.0) self.comp.setParam("contrast",5.3e-006) self.comp.setParam("n_plates",20.0) self.comp.setParam("caille", 0.1) self.comp.setParam("background",0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a LamellarPS Model""" self.assertAlmostEquals(self.comp.run(0.001), 28526.8, 1) def test1D_2(self): """ Test 2D model for a LamellarPS Model""" self.assertAlmostEquals(self.comp.run([0.001, 1.3]),28526.8, 1) def testEval_1D(self): """ Test 1D model for a LamellarPS Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a LamellarPS Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestLamellarPSHGModel(unittest.TestCase): """ Unit tests for LamellarPSHG Model""" def setUp(self): from sans.models.LamellarPSHGModel import LamellarPSHGModel self.comp = LamellarPSHGModel() self.comp.setParam("scale",1.0) self.comp.setParam("spacing",40.0) self.comp.setParam("deltaT",10.0) self.comp.setParam("deltaH",2.0) self.comp.setParam("sld_tail",4e-7) self.comp.setParam("sld_head",2e-6) self.comp.setParam("sld_solvent",6e-6) self.comp.setParam("n_plates",30) self.comp.setParam("caille",0.001) self.comp.setParam("background",0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a LamellarPSHG Model""" self.assertAlmostEquals(self.comp.run(0.001),6.83139e6, 3) def test1D_2(self): """ Test 2D model for a LamellarPSHG Model""" self.assertAlmostEquals(self.comp.run([0.001, 1.3]),6.83139e6,3) def testEval_1D(self): """ Test 1D model for a LamellarPSHG Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a LamellarPSHG Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestSquareWellStructure(unittest.TestCase): """ Unit tests for SquareWellStructure """ def setUp(self): from sans.models.SquareWellStructure import SquareWellStructure self.comp = SquareWellStructure() self.comp.setParam("effect_radius",50.0) self.comp.setParam("volfraction",0.04) self.comp.setParam("welldepth",1.5 ) self.comp.setParam("wellwidth",1.2) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a SquareWellStructure""" self.assertAlmostEqual(self.comp.run(0.001), 0.976657, 2) def test1D_2(self): """ Test 2D model for a SquareWellStructure""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.9776657,2) def testEval_1D(self): """ Test 1D model for a SquareWellStructure with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a SquareWellStructure with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestHardsphereStructure(unittest.TestCase): """ Unit tests for HardsphereStructure""" def setUp(self): from sans.models.HardsphereStructure import HardsphereStructure self.comp = HardsphereStructure() self.comp.setParam("effect_radius",50.0) self.comp.setParam("volfraction", 0.2) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a HardsphereStructure""" self.assertAlmostEqual(self.comp.run(0.001),0.209128, 4) def test1D_2(self): """ Test 2D model for a HardsphereStructure""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.209128, 4) def testEval_1D(self): """ Test 1D model for a HardsphereStructure with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a HardsphereStructure with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestStickyHSStructure(unittest.TestCase): """ Unit tests for StickyHSStructure""" def setUp(self): from sans.models.StickyHSStructure import StickyHSStructure self.comp = StickyHSStructure() self.comp.setParam("effect_radius",50.0) self.comp.setParam("volfraction",0.1) self.comp.setParam("perturb",0.05) self.comp.setParam("stickiness",0.2) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a StickyHSStructure""" self.assertAlmostEqual(self.comp.run(0.001),1.09718, 4) def test1D_2(self): """ Test 2D model for a StickyHSStructure""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.09718, 4) def testEval_1D(self): """ Test 1D model for a StickyHSStructure with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a StickyHSStructure with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestHayterMSAStructure(unittest.TestCase): """ Unit tests for HayterMSAStructure""" def setUp(self): from sans.models.HayterMSAStructure import HayterMSAStructure self.comp = HayterMSAStructure() self.comp.setParam("effect_radius",20.75) self.comp.setParam("charge",19.0) self.comp.setParam("volfraction",0.0192 ) self.comp.setParam("temperature",298) self.comp.setParam("saltconc",0.0) self.comp.setParam("dielectconst",78) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a HayterMSAStructure""" self.assertAlmostEqual(self.comp.run(0.001),0.0712928, 4) def test1D_2(self): """ Test 2D model for a HayterMSAStructure""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.0712928, 4) def testEval_1D(self): """ Test 1D model for a HayterMSAStructure with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a HayterMSAStructure with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestBEPolyelectrolyte(unittest.TestCase): """ Unit tests for BEPolyelectrolyte""" def setUp(self): from sans.models.BEPolyelectrolyte import BEPolyelectrolyte self.comp = BEPolyelectrolyte() self.comp.setParam('k',10) self.comp.setParam('lb',7.1) self.comp.setParam('h',12) self.comp.setParam('b',10) self.comp.setParam('cs', 0.0) self.comp.setParam('alpha',0.05) self.comp.setParam('c', 0.7) self.comp.setParam('background',0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a BEPolyelectrolyte""" self.assertAlmostEqual(self.comp.run(0.001),0.0948, 3) def test1D_2(self): """ Test 2D model for a BEPolyelectrolyte""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),0.0948, 3) def testEval_1D(self): """ Test 1D model for a BEPolyelectrolyte with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a BEPolyelectrolyte with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestDABModel(unittest.TestCase): """ Unit tests for DABModel""" def setUp(self): from sans.models.DABModel import DABModel self.comp = DABModel() self.comp.setParam('length',40.0) self.comp.setParam('scale',10.0) self.comp.setParam('background',1.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a DABModel""" self.assertAlmostEqual(self.comp.run(0.001),10.9681, 3) def test1D_2(self): """ Test 2D model for a DABModel""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),10.9681, 3) def testEval_1D(self): """ Test 1D model for a DABModel with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a DABModel with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestGuinierModel(unittest.TestCase): """ Unit tests for Guinier Model""" def setUp(self): from sans.models.GuinierModel import GuinierModel self.comp = GuinierModel() self.comp.setParam('scale',1.0) self.comp.setParam('rg', 60) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a GuinierModel""" self.assertAlmostEqual(self.comp.run(1.0), 5.6387e-5, 4) def test1D_2(self): """ Test 2D model for a GuinierModel""" self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 5.6387e-5, 4) from sans.models.GuinierModel import GuinierModel self.shape_indep_list.append(GuinierModel ) def testEval_1D(self): """ Test 1D model for a GuinierModel with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a GuinierModel with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestDebyeModel(unittest.TestCase): """ Unit tests for Debye Model""" def setUp(self): from sans.models.DebyeModel import DebyeModel self.comp = DebyeModel() self.comp.setParam('rg', 50.0) self.comp.setParam('scale',1.0) self.comp.setParam('background',0.001) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a DebyeModel""" self.assertAlmostEqual(self.comp.run(0.001),1.00017,4) def test1D_2(self): """ Test 2D model for a DebyeModel""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),1.00017,4) def testEval_1D(self): """ Test 1D model for a DebyeModel with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a DebyeModel with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestPorodModel(unittest.TestCase): """ Unit tests for PorodModel""" def setUp(self): from sans.models.PorodModel import PorodModel self.comp = PorodModel() self.comp.setParam('scale', 1.0) self.comp.setParam('background', 0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a PorodModel""" self.assertEquals(self.comp.run(0.5), 16) def test1D_2(self): """ Test 2D model for a PorodModel""" self.assertEquals(self.comp.run([0.5, 1.3]),16) def testEval_1D(self): """ Test 1D model for a PorodModel with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a PorodModel with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) def testCreaticalPt(self): """ Test for critical point for PorodModel run""" self.assertRaises(ZeroDivisionError, self.comp.run, 0.0) class TestPeakGaussModel(unittest.TestCase): """ Unit tests for PeakGaussModel""" def setUp(self): from sans.models.PeakGaussModel import PeakGaussModel self.comp = PeakGaussModel() self.comp.setParam('scale', 100) self.comp.setParam('B', 0.005) self.comp.setParam('q0',0.05) self.comp.setParam('background',1.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a PeakGauss Model""" self.assertEquals(self.comp.run(0.001),1) def test1D_2(self): """ Test 2D model for a PeakGauss Model""" self.assertEquals(self.comp.run([0.001, 1.3]),1) def testEval_1D(self): """ Test 1D model for a PeakGauss Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a PeakGauss Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestPeakLorentzModel(unittest.TestCase): """ Unit tests for PeakLorentzModel""" def setUp(self): from sans.models.PeakLorentzModel import PeakLorentzModel self.comp = PeakLorentzModel() self.comp.setParam('scale', 100) self.comp.setParam('B', 0.005) self.comp.setParam('q0',0.05) self.comp.setParam('background',1.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a PeakLorentz Model""" self.assertAlmostEqual(self.comp.run(0.001), 2.0305, 3) def test1D_2(self): """ Test 2D model for a PeakLorentz Model""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 2.0305, 3) def testEval_1D(self): """ Test 1D model for a PeakLorentz Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a PeakLorentz Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestFractalAbsModel(unittest.TestCase): """ Unit tests for FractalAbsModel""" def setUp(self): from sans.models.FractalAbsModel import FractalAbsModel self.comp = FractalAbsModel() self.comp.setParam('scale', 0.05) self.comp.setParam('radius', 5.0) self.comp.setParam('fractal_dim', 2.0) self.comp.setParam('corr_length',100.0) self.comp.setParam('block_sld', 2.0e-6) self.comp.setParam('solvent_sld', 6.35e-6) self.comp.setParam('background',0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a Fractal Abs Model""" self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3) def test1D_2(self): """ Test 2D model for a Fractal Abs Model""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3) def testEval_1D(self): """ Test 1D model for a Fractal Abs Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Fractal Abs Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestFractalModel(unittest.TestCase): """ Unit tests for FractalModel""" def setUp(self): from sans.models.FractalModel import FractalModel self.comp = FractalModel() self.comp.setParam('scale', 0.05) self.comp.setParam('radius', 5.0) self.comp.setParam('fractal_dim', 2.0) self.comp.setParam('corr_length',100.0) self.comp.setParam('block_sld', 2.0e-6) self.comp.setParam('solvent_sld', 6.35e-6) self.comp.setParam('background',0.0) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a Fractal Model""" self.assertAlmostEqual(self.comp.run(0.001), 39.2881, 3) def test1D_2(self): """ Test 2D model for a Fractal Model""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]), 39.2881, 3) def testEval_1D(self): """ Test 1D model for a Fractal Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Fractal Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestLorentzModel(unittest.TestCase): """ Unit tests for LorentzModel""" def setUp(self): from sans.models.LorentzModel import LorentzModel self.comp = LorentzModel() self.comp.setParam("background",1) self.comp.setParam("length",50) self.comp.setParam("scale",100) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a Lorentz Model""" self.assertAlmostEqual(self.comp.run(0.001),100.751, 2) def test1D_2(self): """ Test 2D model for a Lorentz Model""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),100.751, 2) def testEval_1D(self): """ Test 1D model for a Lorentz Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Lorentz Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestPowerLawAbsModel(unittest.TestCase): """ Unit tests for PowerLawAbsModel""" def setUp(self): from sans.models.PowerLawAbsModel import PowerLawAbsModel self.comp = PowerLawAbsModel() self.comp.setParam("background",1) self.comp.setParam("m",4) self.comp.setParam("scale",1e-6) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a PowerLawAbs Model""" self.assertAlmostEqual(self.comp.run(0.19189), 1.00074,4) def test1D_2(self): """ Test 2D model for a PowerLawAbs Model""" self.assertAlmostEqual(self.comp.run([0.19189,1.3]), 1.00074,4) def testEval_1D(self): """ Test 1D model for a PowerLawAbs Model with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a PowerLawAbs Model with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestPowerLawModel(unittest.TestCase): """ Unit tests for PowerLawModel""" def setUp(self): from sans.models.PowerLawModel import PowerLawModel self.comp = PowerLawModel() self.comp.setParam("background",1) self.comp.setParam("m",4) self.comp.setParam("scale",1e-6) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a PowerLaw Model""" self.assertAlmostEquals(self.comp.run(0.19189), 1.00074,4) def test1D_2(self): """ Test 2D model for a PowerLawModel""" self.assertAlmostEquals(self.comp.run([0.19189,1.3]), 1.00074,4) def testEval_1D(self): """ Test 1D model for a PowerLawModel with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a PowerLawModel with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestTeubnerStreyModel(unittest.TestCase): """ Unit tests for TeubnerStreyModel""" def setUp(self): from sans.models.TeubnerStreyModel import TeubnerStreyModel self.comp = TeubnerStreyModel() self.comp.setParam("background",0.1) self.comp.setParam("c1",-30) self.comp.setParam("c2",5000) self.comp.setParam("scale",0.1) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a TeubnerStrey Model""" self.assertAlmostEqual(self.comp.run(0.001),10.103, 1) def test1D_2(self): """ Test 2D model for a TeubnerStrey Model""" self.assertAlmostEqual(self.comp.run([0.001, 1.3]),10.103, 1) def testEval_1D(self): """ Test 1D model for a TeubnerStrey with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a TeubnerStrey with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) class TestLineModel(unittest.TestCase): """ Unit tests for LineModel""" def setUp(self): from sans.models.LineModel import LineModel self.comp = LineModel() self.comp.setParam("A",1) self.comp.setParam("B",1) self.x = numpy.array([0.4, 1.3]) self.y = numpy.array([0.5, 1.57]) self.x_array = self.comp.evalDistribution(self.x) self.y_array = self.comp.evalDistribution(self.y) qx_prime = numpy.reshape(self.x, [1,len(self.x)]) qy_prime = numpy.reshape(self.y, [len(self.y),1]) self.xy_matrix = self.comp.evalDistribution([qx_prime, qy_prime]) def test1D(self): """ Test 1D model for a Line Model""" self.assertEquals(self.comp.run(1.0),2) def testEval_1D(self): """ Test 1D model for a Line with evalDistribution""" self.assertEquals(self.comp.run(0.4),self.x_array[0]) self.assertEquals(self.comp.run(1.3),self.x_array[1]) def testEval_2D(self): """ Test 2D model for a Line with evalDistribution""" self.assertAlmostEquals(self.comp.runXY([0.4, 0.5]),self.xy_matrix[0][0],8) self.assertAlmostEquals(self.comp.runXY([0.4,1.57]),self.xy_matrix[1][0], 8) self.assertAlmostEquals(self.comp.runXY([1.3, 0.5]),self.xy_matrix[0][1],8) self.assertAlmostEquals(self.comp.runXY([1.3, 1.57]),self.xy_matrix[1][1],8) if __name__ == '__main__': unittest.main()