source: sasview/sansmodels/test/utest_extra_models.py @ e55a472

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 e55a472 was 18e250c, checked in by Gervaise Alina <gervyh@…>, 13 years ago

move test to sansmodels top level

  • Property mode set to 100644
File size: 15.4 KB
Line 
1"""
2Unit tests for extra models,PolymerexclVolume, RPA10Model
3The reference values are calculated on IGOR/NIST package(Oct.,2010)
4@author: JHJ Cho / UTK
5"""
6import unittest
7class TestPolymerExclVolume(unittest.TestCase):
8    """
9    Unit tests for PolymerexclVolume (non-shape) function
10    """
11    def setUp(self):
12        from sans.models.PolymerExclVolume import PolymerExclVolume
13        self.model= PolymerExclVolume()
14       
15    def test1D(self):         
16        # the values are from Igor pro calculation   
17        self.assertAlmostEqual(self.model.run(0.001), 0.998801, 6)
18        self.assertAlmostEqual(self.model.run(0.21571), 0.00192041, 6)
19        self.assertAlmostEqual(self.model.runXY(0.41959), 0.000261302, 6)
20       
21class TestRPA10Case(unittest.TestCase):
22    """
23    Unit tests for RPA10Model (non-shape) function
24    """
25    def setUp(self):
26        from sans.models.RPA10Model import RPA10Model
27        self.model0= RPA10Model(0)
28        self.model1= RPA10Model(1)
29        self.model2= RPA10Model(2)
30        self.model3= RPA10Model(3)
31        self.model4= RPA10Model(4)
32        self.model5= RPA10Model(5)
33        self.model6= RPA10Model(6)
34        self.model7= RPA10Model(7)
35        self.model8= RPA10Model(8)
36        self.model9= RPA10Model(9)
37       
38    def test1D(self):         
39        # the test values are from Igor pro calculation   
40        # case 0
41        # set default of vol fration consistent with IGor
42        self.model0.setParam('Phic',0.5)
43        self.model0.setParam('Phid',0.5)
44        self.assertAlmostEqual(self.model0.run(0.001), 0.0716863, 6)
45        self.assertAlmostEqual(self.model0.runXY(0.414955), 0.00396997, 6)
46        # case 1
47        # set default of vol fration consistent with IGor
48        self.model1.setParam('Phic',0.5)
49        self.model1.setParam('Phid',0.5)
50        self.assertAlmostEqual(self.model1.run(0.001), 0.00395016, 6)
51        self.assertAlmostEqual(self.model1.runXY(0.414955), 0.00396735, 6)
52        # case 2
53        # set default of vol fration consistent with IGor
54        self.model2.setParam('Phib',0.33)
55        self.model2.setParam('Phic',0.33)
56        self.model2.setParam('Phid',0.33)
57        self.assertAlmostEqual(self.model2.run(0.001), 0.0932902, 6)
58        self.assertAlmostEqual(self.model2.runXY(0.414955), 0.00355736, 6)
59        # case 3
60        # set default of vol fration consistent with IGor
61        self.model3.setParam('Phib',0.33)
62        self.model3.setParam('Phic',0.33)
63        self.model3.setParam('Phid',0.33)
64        self.assertAlmostEqual(self.model3.run(0.001), 0.026254, 6)
65        self.assertAlmostEqual(self.model3.runXY(0.414955), 0.00355577, 6)
66        # case 4
67        # set default of vol fration consistent with IGor
68        self.model4.setParam('Phib',0.33)
69        self.model4.setParam('Phic',0.33)
70        self.model4.setParam('Phid',0.33)
71        self.assertAlmostEqual(self.model4.run(0.001), 0.0067433, 6)
72        self.assertAlmostEqual(self.model4.runXY(0.414955), 0.00355656, 6)
73        # case 5
74        self.assertAlmostEqual(self.model5.run(0.001), 0.102636, 6)
75        self.assertAlmostEqual(self.model5.runXY(0.414955), 0.00305812, 6)
76        # case 6
77        self.assertAlmostEqual(self.model6.run(0.001), 0.0370357, 6)
78        self.assertAlmostEqual(self.model6.runXY(0.414955), 0.00305708, 6)
79        # case 7
80        self.assertAlmostEqual(self.model7.run(0.001), 0.0167775, 6)
81        self.assertAlmostEqual(self.model7.runXY(0.414955), 0.00305743, 6)
82        # case 8
83        self.assertAlmostEqual(self.model8.run(0.001), 0.0378691, 6)
84        self.assertAlmostEqual(self.model8.runXY(0.414955), 0.00305743, 6)
85        # case 9
86        self.assertAlmostEqual(self.model9.run(0.001), 0.00839376, 6)
87        self.assertAlmostEqual(self.model9.runXY(0.414955), 0.00305777, 6) 
88             
89class TestBarBell(unittest.TestCase):
90    """
91    Unit tests for BarBell function
92    """
93    def setUp(self):
94        from sans.models.BarBellModel import BarBellModel
95        self.model= BarBellModel()
96       
97    def test1D(self):         
98        # the values are from Igor pro calculation   
99        self.assertAlmostEqual(self.model.run(0.001), 2864.7, 1)
100        self.assertAlmostEqual(self.model.run(0.215268), 0.526351, 4)
101        self.assertAlmostEqual(self.model.runXY(0.414467), 0.0685892, 6)
102
103class TestCappedCylinder(unittest.TestCase):
104    """
105    Unit tests for CappedCylinder function
106    """
107    def setUp(self):
108        from sans.models.CappedCylinderModel import CappedCylinderModel
109        self.model= CappedCylinderModel()
110       
111    def test1D(self):         
112        # the values are from Igor pro calculation 
113        # the different digits are due to precision of q values 
114        self.assertAlmostEqual(self.model.run(0.001), 1424.72, 2)
115        self.assertAlmostEqual(self.model.run(0.215268), 0.360736, 4)
116        self.assertAlmostEqual(self.model.runXY(0.414467), 0.110283, 5)
117
118class TestLamellarParaCrystal(unittest.TestCase):
119    """
120    Unit tests for LamellarParaCystal function
121    """
122    def setUp(self):
123        from sans.models.LamellarPCrystalModel import LamellarPCrystalModel
124        self.model= LamellarPCrystalModel()
125       
126    def test1D(self):   
127        self.model.setParam("pd_spacing", 0.2)     
128        # the values are from Igor pro calculation 
129        # the different digits are due to precision of q values 
130        self.assertAlmostEqual(self.model.run(0.001), 21829.3, 1)
131        self.assertAlmostEqual(self.model.run(0.215268), 0.00487686, 6)
132        self.assertAlmostEqual(self.model.runXY(0.414467), 0.00062029, 6)
133
134
135class TestSCParaCrystal(unittest.TestCase):
136    """
137    Unit tests for Simple Cubic ParaCrystal Model function
138    """
139    def setUp(self):
140        from sans.models.SCCrystalModel import SCCrystalModel
141        self.model= SCCrystalModel()
142       
143    def test1D(self):       
144        # the values are from Igor pro calculation 
145        # the different digits are due to precision of q values 
146        self.assertAlmostEqual(self.model.run(0.001), 10.3038, 4)
147        self.assertAlmostEqual(self.model.run(0.215268), 0.00714905, 6)
148        self.assertAlmostEqual(self.model.runXY(0.414467), 0.000313289, 6)
149
150class TestFCParaCrystal(unittest.TestCase):
151    """
152    Unit tests for Face Centered Cubic ParaCrystal Model function
153    """
154    def setUp(self):
155        from sans.models.FCCrystalModel import FCCrystalModel
156        self.model= FCCrystalModel()
157       
158    def test1D(self):       
159        self.model.setParam("d_factor", 0.05) 
160        # the values are from Igor pro calculation 
161        # the different digits are due to precision of q values 
162        self.assertAlmostEqual(self.model.run(0.001), 0.121017, 6)
163        self.assertAlmostEqual(self.model.run(0.215268), 0.0107218, 6)
164        self.assertAlmostEqual(self.model.runXY(0.414467), 0.000443282, 6)
165
166class TestBCParaCrystal(unittest.TestCase):
167    """
168    Unit tests for Body Centered Cubic ParaCrystal Model function
169    """
170    def setUp(self):
171        from sans.models.BCCrystalModel import BCCrystalModel
172        self.model= BCCrystalModel()
173       
174    def test1D(self):       
175        # the values are from Igor pro calculation 
176        # the different digits are due to precision of q values 
177        self.assertAlmostEqual(self.model.run(0.001), 1.77267, 4)
178        self.assertAlmostEqual(self.model.run(0.215268), 0.00927739, 6)
179        self.assertAlmostEqual(self.model.runXY(0.414467), 0.000406973, 6)
180                               
181
182class TestGuinierPorod(unittest.TestCase):
183    """
184    Unit tests for GuinierPorod Model function
185    """
186    def setUp(self):
187        from sans.models.GuinierPorodModel import GuinierPorodModel
188        self.model= GuinierPorodModel()
189       
190    def test1D(self):       
191        # the values are from Igor pro calculation 
192        # the different digits are due to precision of q values 
193        self.assertAlmostEqual(self.model.run(0.001), 995.112, 3)
194        self.assertAlmostEqual(self.model.run(0.105363), 0.162904, 5)
195        self.assertAlmostEqual(self.model.runXY(0.441623), 0.100854, 6)
196
197class TestGaussLorentzGel(unittest.TestCase):
198    """
199    Unit tests for GuinierPorod Model function
200    """
201    def setUp(self):
202        from sans.models.GaussLorentzGelModel import GaussLorentzGelModel
203        self.model= GaussLorentzGelModel()
204       
205    def test1D(self):       
206        # the values are from Igor pro calculation 
207        # the different digits are due to precision of q values 
208        self.assertAlmostEqual(self.model.run(0.001), 149.481, 3)
209        self.assertAlmostEqual(self.model.run(0.105363), 9.1903, 4)
210        self.assertAlmostEqual(self.model.runXY(0.441623), 0.632811, 5)
211                               
212
213class TestTwoPowerLaw(unittest.TestCase):
214    """
215    Unit tests for TwoPowerLaw Model function
216    """
217    def setUp(self):
218        from sans.models.TwoPowerLawModel import TwoPowerLawModel
219        self.model= TwoPowerLawModel()
220       
221    def test1D(self):       
222        # the values are from Igor pro calculation 
223        # the different digits are due to precision of q values 
224        self.assertEqual(self.model.run(0.001), 1000)
225        self.assertAlmostEqual(self.model.run(0.150141), 0.125945, 5)
226        self.assertAlmostEqual(self.model.runXY(0.442528), 0.00166884, 7)
227                               
228class TestTwoLorentzian(unittest.TestCase):
229    """
230    Unit tests for TwoLorentzian Model function
231    """
232    def setUp(self):
233        from sans.models.TwoLorentzianModel import TwoLorentzianModel
234        self.model= TwoLorentzianModel()
235       
236    def test1D(self):       
237        # the values are from Igor pro calculation 
238        # the different digits are due to precision of q values 
239        self.assertAlmostEqual(self.model.run(0.001), 11.0899, 3)
240        self.assertAlmostEqual(self.model.run(0.150141), 0.410245, 5)
241        self.assertAlmostEqual(self.model.runXY(0.442528), 0.148699, 6)
242                               
243
244class TestCorrLengthLaw(unittest.TestCase):
245    """
246    Unit tests for CorrLength Model function
247    """
248    def setUp(self):
249        from sans.models.CorrLengthModel import CorrLengthModel
250        self.model= CorrLengthModel()
251       
252    def test1D(self):       
253        # the values are from Igor pro calculation 
254        # the different digits are due to precision of q values 
255        self.assertAlmostEqual(self.model.run(0.001), 1010.08, 1)
256        self.assertAlmostEqual(self.model.run(0.150141), 0.274645, 5)
257        self.assertAlmostEqual(self.model.runXY(0.442528), 0.120396, 6)
258                               
259
260class TestBroadPeak(unittest.TestCase):
261    """
262    Unit tests for BroadPeak Model function
263    """
264    def setUp(self):
265        from sans.models.BroadPeakModel import BroadPeakModel
266        self.model= BroadPeakModel()
267       
268    def test1D(self):       
269        # the values are from Igor pro calculation 
270        # the different digits are due to precision of q values 
271        self.assertAlmostEqual(self.model.run(0.001), 10000.5, 1)
272        self.assertAlmostEqual(self.model.run(0.1501412), 1.47557, 5)
273        self.assertAlmostEqual(self.model.runXY(0.4425284), 0.134093, 6)
274       
275class TestFractalCoreShell(unittest.TestCase):
276    """
277    Unit tests for FractalCoreShell Model function
278    """
279    def setUp(self):
280        from sans.models.FractalCoreShellModel import FractalCoreShellModel
281        self.model= FractalCoreShellModel()
282       
283    def test1D(self):       
284        #self.model.setParam('radius.width', 2.0)
285        # the values are from Igor pro calculation 
286        # the different digits are due to precision of q values 
287        self.assertAlmostEqual(self.model.run(0.001), 273.742, 3)
288        self.assertAlmostEqual(self.model.run(0.1501412), 0.040079, 6)
289        self.assertAlmostEqual(self.model.runXY(0.4425284), 0.00141167, 8) 
290         
291    def test1DSchulzDispersion(self):     
292        # Same test w/ test1D up there but w/ Schulzdispersion
293        from sans.models.dispersion_models import SchulzDispersion
294        disp = SchulzDispersion()
295        self.model.set_dispersion('radius', disp)
296        # 'width' is a ratio now for non-angular parameters
297        self.model.dispersion['radius']['width'] = 0.1
298        self.model.dispersion['radius']['npts'] = 100
299        self.model.dispersion['radius']['nsigmas'] = 3.0
300        # the values are from Igor pro calculation
301        # the run does not neccessary to be exactly same with NIST
302        # 'cause we used different method.
303        self.assertAlmostEqual(self.model.run(0.001), 287.851, -1)
304        self.assertAlmostEqual(self.model.run(0.1501412), 0.0500775, 3)
305        self.assertAlmostEqual(self.model.runXY(0.4425284), 0.00390948, 3)         
306       
307
308class TestUnifiedPowerRg(unittest.TestCase):
309    """
310    Unit tests for FractalCoreShell Model function
311    """
312    def setUp(self):
313        from sans.models.UnifiedPowerRgModel import UnifiedPowerRgModel
314        self.model1= UnifiedPowerRgModel(1)
315        self.model4= UnifiedPowerRgModel(4)
316       
317    def test1DLabel1(self):       
318        # Label #1
319        # the values are from Igor pro calculation 
320        # the different digits are due to precision of q values 
321        self.assertAlmostEqual(self.model1.run(0.001), 2.99956, 5)
322        self.assertAlmostEqual(self.model1.run(0.1501412), 0.126506, 6)
323        self.assertAlmostEqual(self.model1.runXY(0.4425284), 0.00306386, 8)                             
324 
325    def test1DLabel4(self):       
326        # Label #4
327        # Set params consistent w/NIST
328        # No. 4 already same
329        # No. 3
330        self.model4.setParam('Rg3', 200)
331        self.model4.setParam('B3', 5e-06)
332        self.model4.setParam('G3', 400)
333        # No. 2
334        self.model4.setParam('Rg2', 600)
335        self.model4.setParam('B2', 2e-07)
336        self.model4.setParam('G2', 4000)
337        # No. 1
338        self.model4.setParam('Rg1', 2000)
339        self.model4.setParam('B1', 1e-08)
340        self.model4.setParam('G1', 40000)
341       
342        # the values are from Igor pro calculation 
343        # the different digits are due to precision of q values 
344        self.assertAlmostEqual(self.model4.run(0.001), 14778.4, 1)
345        self.assertAlmostEqual(self.model4.run(0.0301614), 7.88115, 4)
346        self.assertAlmostEqual(self.model4.run(0.1501412), 0.126864, 6)
347        self.assertAlmostEqual(self.model4.runXY(0.4425284), 0.00306386, 8) 
348                                                                             
349
350class TestCSPP(unittest.TestCase):
351    """
352    Unit tests for CSParallelepiped Model function
353    """
354    def setUp(self):
355        from sans.models.CSParallelepipedModel import CSParallelepipedModel
356        self.model= CSParallelepipedModel()
357       
358    def test1D(self):       
359        # the values are from Igor pro calculation 
360        # the different digits are due to precision of q values 
361        self.assertAlmostEqual(self.model.run(0.001), 1383.96, 2)
362        self.assertAlmostEqual(self.model.run(0.1501412), 2.51932, 4)
363        self.assertAlmostEqual(self.model.runXY(0.4425284), 0.0736735, 6)
364                                                                                                                                                         
365if __name__ == '__main__':
366    unittest.main()
Note: See TracBrowser for help on using the repository browser.