1 | |
---|
2 | import unittest |
---|
3 | |
---|
4 | from DataLoader.loader import Loader |
---|
5 | from DataLoader.manipulations import Ring, CircularAverage |
---|
6 | |
---|
7 | import os.path |
---|
8 | |
---|
9 | class data_info_tests(unittest.TestCase): |
---|
10 | |
---|
11 | def setUp(self): |
---|
12 | self.data = Loader().load('MAR07232_rest.ASC') |
---|
13 | |
---|
14 | def test_ring(self): |
---|
15 | """ |
---|
16 | Test ring averaging |
---|
17 | """ |
---|
18 | r = Ring(r_min=.005, r_max=.01, |
---|
19 | center_x=self.data.detector[0].beam_center.x, |
---|
20 | center_y=self.data.detector[0].beam_center.y) |
---|
21 | r.nbins_phi = 20 |
---|
22 | |
---|
23 | o = r(self.data) |
---|
24 | answer = Loader().load('ring_testdata.txt') |
---|
25 | for i in range(r.nbins_phi): |
---|
26 | self.assertAlmostEqual(o.x[i], answer.x[i], 4) |
---|
27 | self.assertAlmostEqual(o.y[i], answer.y[i], 4) |
---|
28 | self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) |
---|
29 | |
---|
30 | def test_circularavg(self): |
---|
31 | """ |
---|
32 | Test circular averaging |
---|
33 | The test data was not generated by IGOR. |
---|
34 | """ |
---|
35 | r = CircularAverage(r_min=.00, r_max=.025, |
---|
36 | bin_width=0.0003) |
---|
37 | r.nbins_phi = 20 |
---|
38 | |
---|
39 | o = r(self.data) |
---|
40 | answer = Loader().load('avg_testdata.txt') |
---|
41 | for i in range(r.nbins_phi): |
---|
42 | self.assertAlmostEqual(o.x[i], answer.x[i], 4) |
---|
43 | self.assertAlmostEqual(o.y[i], answer.y[i], 4) |
---|
44 | self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) |
---|
45 | |
---|
46 | def test_box(self): |
---|
47 | """ |
---|
48 | Test circular averaging |
---|
49 | The test data was not generated by IGOR. |
---|
50 | """ |
---|
51 | from DataLoader.manipulations import Boxsum, Boxavg |
---|
52 | |
---|
53 | r = Boxsum(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) |
---|
54 | s, ds = r(self.data) |
---|
55 | self.assertAlmostEqual(s, 151.81809601016641, 4) |
---|
56 | self.assertAlmostEqual(ds, 16.245399156009537, 4) |
---|
57 | |
---|
58 | r = Boxavg(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) |
---|
59 | s, ds = r(self.data) |
---|
60 | self.assertAlmostEqual(s, 0.11195555855955155, 4) |
---|
61 | self.assertAlmostEqual(ds, 0.011979881083557541, 4) |
---|
62 | |
---|
63 | |
---|
64 | if __name__ == '__main__': |
---|
65 | unittest.main() |
---|