Changeset eba9885 in sasview for sansmodels/src/sans/models/test


Ignore:
Timestamp:
Aug 5, 2009 5:39:03 PM (15 years ago)
Author:
Gervaise Alina <gervyh@…>
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
Message:

code for evalDistribution

Location:
sansmodels/src/sans/models/test
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sansmodels/src/sans/models/test/utest_dispersity.py

    r8809e48 reba9885  
    5757         
    5858        new_model = self.model.clone() 
     59        print "gaussian",self.model.run(0.001) 
    5960        self.assertAlmostEqual(new_model.run(0.001), 4723.32213339, 3) 
    6061        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) 
    6189         
    6290    def test_gaussian_zero(self): 
  • sansmodels/src/sans/models/test/utest_models.py

    rae60f86 reba9885  
    2424    def test1D(self): 
    2525        """ Test 1D model for a sphere """ 
    26         self.assertAlmostEqual(self.comp.run(1.0), 56.3878, 4) 
     26        self.assertAlmostEqual(self.comp.run(1.0), 5.6387e-5, 4) 
    2727         
    2828    def test1D_2(self): 
    2929        """ Test 2D model for a sphere """ 
    30         self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 56.3878, 4) 
     30        self.assertAlmostEqual(self.comp.run([1.0, 1.3]), 5.63878e-5, 4) 
    3131 
    3232class TestCyl(unittest.TestCase): 
  • sansmodels/src/sans/models/test/utest_models_array.py

    r812b901 reba9885  
    88         
    99class TestSphere(unittest.TestCase): 
    10     """ Unit tests for sphere model """ 
     10    """ Unit tests for sphere model using evalDistribution function """ 
    1111     
    1212    def setUp(self): 
     
    1818    def test1D(self): 
    1919        """ 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]) 
    2121        
    22         testvector= self.comp.run(self.x) 
     22        
     23        testvector= self.comp.evalDistribution(self.x) 
    2324        
    2425        self.assertAlmostEqual(len(testvector),4) 
     
    3334        """ Test 2D model for a sphere for 2 scalar """ 
    3435        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         
    3645         
    3746class TestCylinder(unittest.TestCase): 
    38     """ Unit tests for sphere model """ 
     47    """ Unit tests for Cylinder model using evalDistribution function """ 
    3948     
    4049    def setUp(self): 
     
    4251        self.comp = CylinderModel() 
    4352        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 
    4554         
    4655    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         
    4858        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) 
    5161        self.assertAlmostEqual(len(testvector),4) 
    5262        for i in xrange(len(answer)): 
     
    5464        
    5565    def test1D_1(self): 
    56         """ Test 2D model for a Cylinder with 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) 
    5868          
    5969    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) 
    6275         
    6376    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) 
    6884         
    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]= value 
    78           
    79         vect_runXY_qx_qy = self.comp.runXY([temp_x, temp_y]) 
    80         vect_run_x_y = self.comp.run([self.x, self.y]) 
    8185         
    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  
    9286 
    9387if __name__ == '__main__': 
Note: See TracChangeset for help on using the changeset viewer.