[d00f8ff] | 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 |
---|
[4fe4394] | 10 | from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection |
---|
[d00f8ff] | 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) |
---|
[4fe4394] | 23 | dx = 0.00*numpy.ones(10) |
---|
[d00f8ff] | 24 | |
---|
[4fe4394] | 25 | self.data.dx = dx |
---|
[d00f8ff] | 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) |
---|
[5859862] | 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.2302, 8.6806, 7.9533, 7.1673, 6.2889, 5.4, 4.5028, 3.5744, 2.6083, 2. ] |
---|
[d00f8ff] | 59 | for i in range(len(input)): |
---|
[a3f8d58] | 60 | self.assertAlmostEqual(answer[i], output[i], 2) |
---|
[d00f8ff] | 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)): |
---|
[a3f8d58] | 72 | self.assertAlmostEquals(input[i], output[i], 5) |
---|
[d00f8ff] | 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)): |
---|
[f867cd9] | 91 | self.assertAlmostEqual(answer[i], output[i], 4) |
---|
[d00f8ff] | 92 | |
---|
| 93 | |
---|
| 94 | if __name__ == '__main__': |
---|
| 95 | unittest.main() |
---|
| 96 | |
---|