1 | """ |
---|
2 | Unit tests for data manipulations |
---|
3 | """ |
---|
4 | |
---|
5 | |
---|
6 | import unittest |
---|
7 | import numpy, math |
---|
8 | from DataLoader.loader import Loader |
---|
9 | from DataLoader.data_info import Data1D, Data2D |
---|
10 | #from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection |
---|
11 | from sans.models.qsmearing import SlitSmearer, QSmearer, smear_selection |
---|
12 | import os.path |
---|
13 | |
---|
14 | class smear_tests(unittest.TestCase): |
---|
15 | |
---|
16 | def setUp(self): |
---|
17 | self.data = Loader().load("cansas1d_slit.xml") |
---|
18 | |
---|
19 | x = 0.001*numpy.arange(1,11) |
---|
20 | y = 12.0-numpy.arange(1,11) |
---|
21 | dxl = 0.00*numpy.ones(10) |
---|
22 | dxw = 0.00*numpy.ones(10) |
---|
23 | dx = 0.00*numpy.ones(10) |
---|
24 | |
---|
25 | self.data.dx = dx |
---|
26 | self.data.x = x |
---|
27 | self.data.y = y |
---|
28 | self.data.dxl = dxl |
---|
29 | self.data.dxw = dxw |
---|
30 | |
---|
31 | def test_slit(self): |
---|
32 | """ |
---|
33 | Test identity smearing |
---|
34 | """ |
---|
35 | # Create smearer for our data |
---|
36 | s = SlitSmearer(self.data) |
---|
37 | |
---|
38 | input = 12.0-numpy.arange(1,11) |
---|
39 | output = s(input) |
---|
40 | for i in range(len(input)): |
---|
41 | self.assertEquals(input[i], output[i]) |
---|
42 | |
---|
43 | def test_slit2(self): |
---|
44 | """ |
---|
45 | Test basic smearing |
---|
46 | """ |
---|
47 | dxl = 0.005*numpy.ones(10) |
---|
48 | dxw = 0.0*numpy.ones(10) |
---|
49 | self.data.dxl = dxl |
---|
50 | self.data.dxw = dxw |
---|
51 | # Create smearer for our data |
---|
52 | s = SlitSmearer(self.data) |
---|
53 | |
---|
54 | input = 12.0-numpy.arange(1,11) |
---|
55 | output = s(input) |
---|
56 | # The following commented line was the correct output for even bins [see smearer.cpp for details] |
---|
57 | #answer = [ 9.666, 9.056, 8.329, 7.494, 6.642, 5.721, 4.774, 3.824, 2.871, 2. ] |
---|
58 | answer = [ 9.0618, 8.6401, 8.1186, 7.1391, 6.1528, 5.5555, 4.5584, 3.5606, 2.5623, 2. ] |
---|
59 | for i in range(len(input)): |
---|
60 | self.assertAlmostEqual(answer[i], output[i], 3) |
---|
61 | |
---|
62 | def test_q(self): |
---|
63 | """ |
---|
64 | Test identity resolution smearing |
---|
65 | """ |
---|
66 | # Create smearer for our data |
---|
67 | s = QSmearer(self.data) |
---|
68 | |
---|
69 | input = 12.0-numpy.arange(1,11) |
---|
70 | output = s(input) |
---|
71 | for i in range(len(input)): |
---|
72 | self.assertAlmostEquals(input[i], output[i], 5) |
---|
73 | |
---|
74 | def test_q2(self): |
---|
75 | """ |
---|
76 | Test basic smearing |
---|
77 | """ |
---|
78 | dx = 0.001*numpy.ones(10) |
---|
79 | self.data.dx = dx |
---|
80 | |
---|
81 | # Create smearer for our data |
---|
82 | s = QSmearer(self.data) |
---|
83 | |
---|
84 | input = 12.0-numpy.arange(1,11) |
---|
85 | output = s(input) |
---|
86 | |
---|
87 | answer = [ 10.44785079, 9.84991299, 8.98101708, |
---|
88 | 7.99906585, 6.99998311, 6.00001689, |
---|
89 | 5.00093415, 4.01898292, 3.15008701, 2.55214921] |
---|
90 | for i in range(len(input)): |
---|
91 | self.assertAlmostEqual(answer[i], output[i], 2) |
---|
92 | |
---|
93 | |
---|
94 | if __name__ == '__main__': |
---|
95 | unittest.main() |
---|
96 | |
---|