Changeset eba9885 in sasview for sansmodels/src/sans/models/test
- Timestamp:
- Aug 5, 2009 5:39:03 PM (15 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- f88624d
- Parents:
- 8344c50
- Location:
- sansmodels/src/sans/models/test
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/test/utest_dispersity.py
r8809e48 reba9885 57 57 58 58 new_model = self.model.clone() 59 print "gaussian",self.model.run(0.001) 59 60 self.assertAlmostEqual(new_model.run(0.001), 4723.32213339, 3) 60 61 self.assertAlmostEqual(new_model.runXY([0.001,0.001]), 4743.56, 2) 62 63 def test_schulz_zero(self): 64 from sans.models.dispersion_models import SchulzDispersion 65 disp = SchulzDispersion() 66 self.model.set_dispersion('radius', disp) 67 self.model.dispersion['radius']['width'] = 5.0 68 #self.model.dispersion['radius']['width'] = 0.0 69 self.model.dispersion['radius']['npts'] = 100 70 #self.model.setParam('scale', 1.0) 71 self.model.setParam('scale', 10.0) 72 print "schulz",self.model.run(0.001), self.model.dispersion 73 self.assertAlmostEqual(self.model.run(0.001), 450.355, 3) 74 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3) 75 76 def test_lognormal_zero(self): 77 from sans.models.dispersion_models import LogNormalDispersion 78 disp = LogNormalDispersion() 79 self.model.set_dispersion('radius', disp) 80 self.model.dispersion['radius']['width'] = 5.0 81 #self.model.dispersion['radius']['width'] = 0.0 82 self.model.dispersion['radius']['npts'] = 100 83 #self.model.setParam('scale', 1.0) 84 self.model.setParam('scale', 10.0) 85 print "model dispersion",self.model.dispersion 86 print "lognormal",self.model.run(0.001) 87 self.assertAlmostEqual(self.model.run(0.001), 450.355, 3) 88 self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 452.299, 3) 61 89 62 90 def test_gaussian_zero(self): -
sansmodels/src/sans/models/test/utest_models.py
rae60f86 reba9885 24 24 def test1D(self): 25 25 """ Test 1D model for a sphere """ 26 self.assertAlmostEqual(self.comp.run(1.0), 5 6.3878, 4)26 self.assertAlmostEqual(self.comp.run(1.0), 5.6387e-5, 4) 27 27 28 28 def test1D_2(self): 29 29 """ Test 2D model for a sphere """ 30 self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 5 6.3878, 4)30 self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 5.63878e-5, 4) 31 31 32 32 class TestCyl(unittest.TestCase): -
sansmodels/src/sans/models/test/utest_models_array.py
r812b901 reba9885 8 8 9 9 class TestSphere(unittest.TestCase): 10 """ Unit tests for sphere model """10 """ Unit tests for sphere model using evalDistribution function """ 11 11 12 12 def setUp(self): … … 18 18 def test1D(self): 19 19 """ Test 1D model for a sphere with vector as input""" 20 answer =numpy.array([5.63877831e-05,2.57231782e-06,2.73704050e-07,2.54229069e-08])20 answer = numpy.array([5.63877831e-05,2.57231782e-06,2.73704050e-07,2.54229069e-08]) 21 21 22 testvector= self.comp.run(self.x) 22 23 testvector= self.comp.evalDistribution(self.x) 23 24 24 25 self.assertAlmostEqual(len(testvector),4) … … 33 34 """ Test 2D model for a sphere for 2 scalar """ 34 35 self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878e-06, 4) 35 36 37 def test1D_3(self): 38 """ Test 2D model for a Shpere for 2 vectors as input """ 39 x= numpy.reshape(self.x, [len(self.x),1]) 40 y= numpy.reshape(self.y, [1,len(self.y)]) 41 vect = self.comp.evalDistribution([x,y]) 42 self.assertAlmostEqual(vect[0][0],9.2985e-07, 4) 43 self.assertAlmostEqual(vect[len(self.x)-1][len(self.y)-1],1.3871e-08, 4) 44 36 45 37 46 class TestCylinder(unittest.TestCase): 38 """ Unit tests for sphere model"""47 """ Unit tests for Cylinder model using evalDistribution function """ 39 48 40 49 def setUp(self): … … 42 51 self.comp = CylinderModel() 43 52 self.x = numpy.array([1.0,2.0,3.0, 4.0]) 44 self.y = numpy.array([1.0,2.0,3.0, 4.0])53 self.y = self.x +1 45 54 46 55 def test1D(self): 47 """ Test 1D model for a Cylinder with vector as input""" 56 """ Test 1D model for a cylinder with vector as input""" 57 48 58 answer = numpy.array([1.98860592e-04,7.03686335e-05,2.89144683e-06,2.04282827e-06]) 49 testvector= self.comp.run(self.x) 50 59 60 testvector= self.comp.evalDistribution(self.x) 51 61 self.assertAlmostEqual(len(testvector),4) 52 62 for i in xrange(len(answer)): … … 54 64 55 65 def test1D_1(self): 56 """ Test 2D model for a Cylinderwith scalar as input"""57 self.assertAlmostEqual(self.comp.run( 1.0),1.9886e-04, 4)66 """ Test 2D model for a cylinder with scalar as input""" 67 self.assertAlmostEqual(self.comp.run(0.2), 0.041761386790780453, 4) 58 68 59 69 def test1D_2(self): 60 """ Test 2D model for a Cylinder for 2 scalar """ 61 self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878e-06, 4) 70 """ Test 2D model of a cylinder """ 71 self.comp.setParam('cyl_theta', 1.0) 72 self.comp.setParam('cyl_phi', 1.0) 73 self.assertAlmostEqual(self.comp.run([0.2, 2.5]), 74 0.038176446608393366, 4) 62 75 63 76 def test1D_3(self): 64 """ Test 2D model for a Cylinder for 2 vectors as input """ 65 ans_input = numpy.zeros(len(self.x)) 66 temp_x = numpy.zeros(len(self.x)) 67 temp_y = numpy.zeros(len(self.y)) 77 """ Test 2D model for a cylinder for 2 vectors as input """ 78 x= numpy.reshape(self.x, [len(self.x),1]) 79 y= numpy.reshape(self.y, [1,len(self.y)]) 80 vect = self.comp.evalDistribution([x,y]) 81 82 self.assertAlmostEqual(vect[0][0],5.06121018e-08,4) 83 self.assertAlmostEqual(vect[len(self.x)-1][len(self.y)-1],2.5978e-11, 4) 68 84 69 for i in xrange(len(self.x)):70 qx = self.x[i]71 qy = self.y[i]72 73 temp_x[i]= qx*math.cos(qy)74 temp_y[i]= qx*math.sin(qy)75 76 value = math.sqrt(temp_x[i]*temp_x[i]+ temp_y[i]*temp_y[i] )#qx*qx +qy*qy)77 ans_input[i]= value78 79 vect_runXY_qx_qy = self.comp.runXY([temp_x, temp_y])80 vect_run_x_y = self.comp.run([self.x, self.y])81 85 82 for i in xrange(len(vect_runXY_qx_qy)):83 self.assertAlmostEqual(vect_runXY_qx_qy[i], vect_run_x_y[i])84 85 vect_run_x = self.comp.run(self.x)86 vect_run_answer = self.comp.run(ans_input)87 88 for i in xrange(len(vect_run_x )):89 self.assertAlmostEqual(vect_run_x [i], vect_run_answer[i])90 91 92 86 93 87 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.