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 |
---|
11 | |
---|
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 | |
---|
24 | self.data.x = x |
---|
25 | self.data.y = y |
---|
26 | self.data.dxl = dxl |
---|
27 | self.data.dxw = dxw |
---|
28 | |
---|
29 | def test_slit(self): |
---|
30 | """ |
---|
31 | Test identity smearing |
---|
32 | """ |
---|
33 | # Create smearer for our data |
---|
34 | s = SlitSmearer(self.data) |
---|
35 | |
---|
36 | input = 12.0-numpy.arange(1,11) |
---|
37 | output = s(input) |
---|
38 | for i in range(len(input)): |
---|
39 | self.assertEquals(input[i], output[i]) |
---|
40 | |
---|
41 | def test_slit2(self): |
---|
42 | """ |
---|
43 | Test basic smearing |
---|
44 | """ |
---|
45 | dxl = 0.005*numpy.ones(10) |
---|
46 | dxw = 0.0*numpy.ones(10) |
---|
47 | self.data.dxl = dxl |
---|
48 | self.data.dxw = dxw |
---|
49 | # Create smearer for our data |
---|
50 | s = SlitSmearer(self.data) |
---|
51 | |
---|
52 | input = 12.0-numpy.arange(1,11) |
---|
53 | output = s(input) |
---|
54 | answer = [ 9.666, 9.056, 8.329, 7.494, 6.642, 5.721, 4.774, 3.824, 2.871, 2. ] |
---|
55 | for i in range(len(input)): |
---|
56 | self.assertAlmostEqual(answer[i], output[i], 5) |
---|
57 | |
---|
58 | def test_q(self): |
---|
59 | """ |
---|
60 | Test identity resolution smearing |
---|
61 | """ |
---|
62 | # Create smearer for our data |
---|
63 | s = QSmearer(self.data) |
---|
64 | |
---|
65 | input = 12.0-numpy.arange(1,11) |
---|
66 | output = s(input) |
---|
67 | for i in range(len(input)): |
---|
68 | self.assertEquals(input[i], output[i]) |
---|
69 | |
---|
70 | def test_q2(self): |
---|
71 | """ |
---|
72 | Test basic smearing |
---|
73 | """ |
---|
74 | dx = 0.001*numpy.ones(10) |
---|
75 | self.data.dx = dx |
---|
76 | |
---|
77 | # Create smearer for our data |
---|
78 | s = QSmearer(self.data) |
---|
79 | |
---|
80 | input = 12.0-numpy.arange(1,11) |
---|
81 | output = s(input) |
---|
82 | |
---|
83 | answer = [ 10.44785079, 9.84991299, 8.98101708, |
---|
84 | 7.99906585, 6.99998311, 6.00001689, |
---|
85 | 5.00093415, 4.01898292, 3.15008701, 2.55214921] |
---|
86 | for i in range(len(input)): |
---|
87 | self.assertAlmostEqual(answer[i], output[i], 5) |
---|
88 | |
---|
89 | |
---|
90 | if __name__ == '__main__': |
---|
91 | unittest.main() |
---|
92 | |
---|