1 | """ |
---|
2 | Unit tests for Gauss and Shulz dispersion functionality of |
---|
3 | C++ model classes |
---|
4 | """ |
---|
5 | |
---|
6 | import unittest, math, numpy |
---|
7 | from sans.dataloader.loader import Loader |
---|
8 | |
---|
9 | |
---|
10 | class TestSphereGauss(unittest.TestCase): |
---|
11 | """ |
---|
12 | Testing C++ Polydispersion w/ sphere comparing to IGOR/NIST computation |
---|
13 | """ |
---|
14 | def setUp(self): |
---|
15 | loader = Loader() |
---|
16 | ## IGOR/NIST computation |
---|
17 | self.output_gauss=loader.load('Gausssphere.txt') |
---|
18 | self.output_shulz=loader.load('Schulzsphere.txt') |
---|
19 | |
---|
20 | from sans.models.SphereModel import SphereModel |
---|
21 | self.model= SphereModel() |
---|
22 | |
---|
23 | self.model.setParam('scale', 0.01) |
---|
24 | self.model.setParam('radius', 60.0) |
---|
25 | self.model.setParam('sldSph', 1.e-6) |
---|
26 | self.model.setParam('sldSolv', 3.e-6) |
---|
27 | self.model.setParam('background', 0.001) |
---|
28 | |
---|
29 | def test_gauss(self): |
---|
30 | from sans.models.dispersion_models import GaussianDispersion |
---|
31 | disp_g = GaussianDispersion() |
---|
32 | self.model.set_dispersion('radius', disp_g) |
---|
33 | self.model.dispersion['radius']['width'] = 0.2 |
---|
34 | self.model.dispersion['radius']['npts'] = 100 |
---|
35 | self.model.dispersion['radius']['nsigmas'] = 10 |
---|
36 | for ind in range(len(self.output_gauss.x)): |
---|
37 | self.assertAlmostEqual(self.model.run(self.output_gauss.x[ind]), |
---|
38 | self.output_gauss.y[ind], 2) |
---|
39 | |
---|
40 | def test_shulz(self): |
---|
41 | from sans.models.dispersion_models import SchulzDispersion |
---|
42 | disp_s = SchulzDispersion() |
---|
43 | self.model.set_dispersion('radius', disp_s) |
---|
44 | self.model.dispersion['radius']['width'] = 0.2 |
---|
45 | self.model.dispersion['radius']['npts'] = 100 |
---|
46 | self.model.dispersion['radius']['nsigmas'] = 10 |
---|
47 | for ind in range(len(self.output_shulz.x)): |
---|
48 | self.assertAlmostEqual(self.model.run(self.output_gauss.x[ind]), |
---|
49 | self.output_shulz.y[ind], 3) |
---|
50 | |
---|
51 | if __name__ == '__main__': |
---|
52 | unittest.main() |
---|
53 | |
---|