[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) |
---|
| 56 | answer = [ 9.666, 9.056, 8.329, 7.494, 6.642, 5.721, 4.774, 3.824, 2.871, 2. ] |
---|
| 57 | for i in range(len(input)): |
---|
| 58 | self.assertAlmostEqual(answer[i], output[i], 5) |
---|
| 59 | |
---|
| 60 | def test_q(self): |
---|
| 61 | """ |
---|
| 62 | Test identity resolution smearing |
---|
| 63 | """ |
---|
| 64 | # Create smearer for our data |
---|
| 65 | s = QSmearer(self.data) |
---|
| 66 | |
---|
| 67 | input = 12.0-numpy.arange(1,11) |
---|
| 68 | output = s(input) |
---|
| 69 | for i in range(len(input)): |
---|
| 70 | self.assertEquals(input[i], output[i]) |
---|
| 71 | |
---|
| 72 | def test_q2(self): |
---|
| 73 | """ |
---|
| 74 | Test basic smearing |
---|
| 75 | """ |
---|
| 76 | dx = 0.001*numpy.ones(10) |
---|
| 77 | self.data.dx = dx |
---|
| 78 | |
---|
| 79 | # Create smearer for our data |
---|
| 80 | s = QSmearer(self.data) |
---|
| 81 | |
---|
| 82 | input = 12.0-numpy.arange(1,11) |
---|
| 83 | output = s(input) |
---|
| 84 | |
---|
| 85 | answer = [ 10.44785079, 9.84991299, 8.98101708, |
---|
| 86 | 7.99906585, 6.99998311, 6.00001689, |
---|
| 87 | 5.00093415, 4.01898292, 3.15008701, 2.55214921] |
---|
| 88 | for i in range(len(input)): |
---|
| 89 | self.assertAlmostEqual(answer[i], output[i], 5) |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | if __name__ == '__main__': |
---|
| 93 | unittest.main() |
---|
| 94 | |
---|