source: sasview/sansmodels/src/sans/models/test/utest_modelmultiplication.py @ 996fd35

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 996fd35 was c9636f7, checked in by Gervaise Alina <gervyh@…>, 16 years ago

model multiplication and testing

  • Property mode set to 100644
File size: 2.7 KB
Line 
1"""
2    Unit tests for specific models
3    @author: Gervaise Alina / UTK
4"""
5
6import unittest, numpy,math
7
8from sans.models.MultiplicationModel import MultiplicationModel
9from sans.models.SphereModel import SphereModel
10from sans.models.SquareWellStructure import SquareWellStructure
11     
12class TestDisperser(unittest.TestCase):
13    """ Unit tests for sphere model * SquareWellStructure"""
14    model1= SphereModel()
15    model2= SquareWellStructure()
16    model3= MultiplicationModel(model1, model2)
17    details={}
18    details['scale'] = ['', None, None]
19    details['radius'] = ['A', None, None]
20    details['contrast'] = ['A-2', None, None]
21    details['background'] = ['cm-1', None, None]
22    details['volfraction'] = ['', None, None]
23    details['welldepth'] = ['kT', None, None]
24    details['wellwidth'] = ['', None, None]
25   
26    ## fittable parameters
27    fixed=[]
28    fixed=['radius.width']
29    def testMultiplicationModel(self):
30        """ Test Multiplication  sphere with SquareWellStructure"""
31        ## test details dictionary
32        self.assertEqual(self.model3.details, self.details)
33       
34        ## test parameters list
35        list3= self.model3.getParamList()
36        for item in self.model1.getParamList():
37            self.assert_(item in list3)
38        for item in self.model2.getParamList():
39            self.assert_(item in list3)
40           
41        ## test set value for parameters and get paramaters
42        self.model3.setParam("scale", 15)
43        self.assertEqual(self.model3.getParam("scale"), 15)
44        self.model3.setParam("radius", 20)
45        self.assertEqual(self.model3.getParam("radius"), 20)
46        self.model3.setParam("radius.width", 15)
47        self.assertEqual(self.model3.getParam("radius.width"), 15)
48       
49        ## Dispersity
50        list3= self.model3.getDispParamList()
51        self.assertEqual(list3, ['radius.npts', 'radius.nsigmas', 'radius.width'])
52       
53        from sans.models.dispersion_models import ArrayDispersion
54        disp_th = ArrayDispersion()
55       
56        values_th = numpy.zeros(100)
57        weights   = numpy.zeros(100)
58        for i in range(100):
59            values_th[i]=(math.pi/99.0*i)
60            weights[i]=(1.0)
61   
62        disp_th.set_weights(values_th, weights)
63       
64        self.model3.set_dispersion('radius', disp_th)
65       
66        val_1d = self.model3.run(math.sqrt(0.0002))
67        val_2d = self.model3.runXY([0.01,0.01]) 
68       
69        self.assertTrue(math.fabs(val_1d-val_2d)/val_1d < 0.02)
70        model4= self.model3.clone()
71        self.assertEqual(model4.getParam("radius"), 20)
72       
73if __name__ == '__main__':
74    unittest.main()
Note: See TracBrowser for help on using the repository browser.