[b99ac227] | 1 | """ |
---|
| 2 | Unit tests for data manipulations |
---|
| 3 | """ |
---|
| 4 | |
---|
| 5 | import unittest |
---|
| 6 | import numpy, math |
---|
| 7 | from DataLoader.loader import Loader |
---|
| 8 | from DataLoader.data_info import Data1D |
---|
| 9 | |
---|
| 10 | import os.path |
---|
| 11 | |
---|
| 12 | class abs_reader(unittest.TestCase): |
---|
| 13 | |
---|
| 14 | def setUp(self): |
---|
| 15 | self.data = Loader().load("jan08002.ABS") |
---|
| 16 | |
---|
| 17 | def test_checkdata(self): |
---|
| 18 | """ |
---|
| 19 | Check the data content to see whether |
---|
| 20 | it matches the specific file we loaded. |
---|
| 21 | Check the units too to see whether the |
---|
| 22 | Data1D defaults changed. Otherwise the |
---|
| 23 | tests won't pass |
---|
| 24 | """ |
---|
| 25 | self.assertEqual(self.data.filename, "jan08002.ABS") |
---|
| 26 | |
---|
| 27 | self.assertEqual(self.data.source.wavelength_unit, 'A') |
---|
| 28 | self.assertEqual(self.data.source.wavelength, 6.0) |
---|
| 29 | |
---|
| 30 | self.assertEqual(self.data.detector[0].distance_unit, 'mm') |
---|
| 31 | self.assertEqual(self.data.detector[0].distance, 1000.0) |
---|
| 32 | |
---|
| 33 | self.assertEqual(self.data.sample.transmission, 0.5667) |
---|
| 34 | |
---|
| 35 | self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') |
---|
| 36 | center_x = 114.58*5.0 |
---|
| 37 | center_y = 64.22*5.0 |
---|
| 38 | self.assertEqual(self.data.detector[0].beam_center.x, center_x) |
---|
| 39 | self.assertEqual(self.data.detector[0].beam_center.y, center_y) |
---|
| 40 | |
---|
| 41 | self.assertEqual(self.data.y_unit, '1/cm') |
---|
| 42 | self.assertEqual(self.data.x[0], 0.002618) |
---|
| 43 | self.assertEqual(self.data.x[1], 0.007854) |
---|
| 44 | self.assertEqual(self.data.x[2], 0.01309) |
---|
| 45 | self.assertEqual(self.data.x[126], 0.5828) |
---|
| 46 | |
---|
| 47 | self.assertEqual(self.data.y[0], 0.02198) |
---|
| 48 | self.assertEqual(self.data.y[1], 0.02201) |
---|
| 49 | self.assertEqual(self.data.y[2], 0.02695) |
---|
| 50 | self.assertEqual(self.data.y[126], 0.2958) |
---|
| 51 | |
---|
| 52 | self.assertEqual(self.data.dy[0], 0.002704) |
---|
| 53 | self.assertEqual(self.data.dy[1], 0.001643) |
---|
| 54 | self.assertEqual(self.data.dy[2], 0.002452) |
---|
| 55 | self.assertEqual(self.data.dy[126], 1) |
---|
| 56 | |
---|
| 57 | def test_checkdata2(self): |
---|
| 58 | self.assertEqual(self.data.dy[126], 1) |
---|
| 59 | |
---|
| 60 | class igor_reader(unittest.TestCase): |
---|
| 61 | |
---|
| 62 | def setUp(self): |
---|
| 63 | self.data = Loader().load("MAR07232_rest.ASC") |
---|
| 64 | |
---|
| 65 | def test_checkdata(self): |
---|
| 66 | """ |
---|
| 67 | Check the data content to see whether |
---|
| 68 | it matches the specific file we loaded. |
---|
| 69 | Check the units too to see whether the |
---|
| 70 | Data1D defaults changed. Otherwise the |
---|
| 71 | tests won't pass |
---|
| 72 | """ |
---|
| 73 | self.assertEqual(self.data.filename, "MAR07232_rest.ASC") |
---|
| 74 | |
---|
| 75 | self.assertEqual(self.data.source.wavelength_unit, 'A') |
---|
| 76 | self.assertEqual(self.data.source.wavelength, 8.4) |
---|
| 77 | |
---|
| 78 | self.assertEqual(self.data.detector[0].distance_unit, 'mm') |
---|
| 79 | self.assertEqual(self.data.detector[0].distance, 13705) |
---|
| 80 | |
---|
| 81 | self.assertEqual(self.data.sample.transmission, 0.84357) |
---|
| 82 | |
---|
| 83 | self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') |
---|
| 84 | center_x = 68.76*5.0 |
---|
| 85 | center_y = 62.47*5.0 |
---|
| 86 | self.assertEqual(self.data.detector[0].beam_center.x, center_x) |
---|
| 87 | self.assertEqual(self.data.detector[0].beam_center.y, center_y) |
---|
| 88 | |
---|
| 89 | self.assertEqual(self.data.I_unit, '1/cm') |
---|
| 90 | self.assertEqual(self.data.data[0][0], 0.279783) |
---|
| 91 | self.assertEqual(self.data.data[0][1], 0.28951) |
---|
| 92 | self.assertEqual(self.data.data[0][2], 0.167634) |
---|
| 93 | |
---|
| 94 | class danse_reader(unittest.TestCase): |
---|
| 95 | |
---|
| 96 | def setUp(self): |
---|
| 97 | self.data = Loader().load("MP_New.sans") |
---|
| 98 | |
---|
| 99 | def test_checkdata(self): |
---|
| 100 | """ |
---|
| 101 | Check the data content to see whether |
---|
| 102 | it matches the specific file we loaded. |
---|
| 103 | Check the units too to see whether the |
---|
| 104 | Data1D defaults changed. Otherwise the |
---|
| 105 | tests won't pass |
---|
| 106 | """ |
---|
| 107 | self.assertEqual(self.data.filename, "MP_New.sans") |
---|
| 108 | |
---|
| 109 | self.assertEqual(self.data.source.wavelength_unit, 'A') |
---|
| 110 | self.assertEqual(self.data.source.wavelength, 7.5) |
---|
| 111 | |
---|
| 112 | self.assertEqual(self.data.detector[0].distance_unit, 'mm') |
---|
| 113 | self.assertAlmostEqual(self.data.detector[0].distance, 5414.99, 3) |
---|
| 114 | |
---|
| 115 | self.assertEqual(self.data.detector[0].beam_center_unit, 'mm') |
---|
| 116 | center_x = 68.74*5.0 |
---|
| 117 | center_y = 64.77*5.0 |
---|
| 118 | self.assertEqual(self.data.detector[0].beam_center.x, center_x) |
---|
| 119 | self.assertEqual(self.data.detector[0].beam_center.y, center_y) |
---|
| 120 | |
---|
| 121 | self.assertEqual(self.data.I_unit, '1/cm') |
---|
| 122 | self.assertEqual(self.data.data[0][0], 1.57831) |
---|
| 123 | self.assertEqual(self.data.data[0][1], 2.70983) |
---|
| 124 | self.assertEqual(self.data.data[0][2], 3.83422) |
---|
| 125 | |
---|
| 126 | self.assertEqual(self.data.err_data[0][0], 1.37607) |
---|
| 127 | self.assertEqual(self.data.err_data[0][1], 1.77569) |
---|
| 128 | self.assertEqual(self.data.err_data[0][2], 2.06313) |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | class cansas_reader(unittest.TestCase): |
---|
| 132 | |
---|
| 133 | def setUp(self): |
---|
| 134 | self.data = Loader().load("cansas1d.xml") |
---|
| 135 | |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | if __name__ == '__main__': |
---|
| 142 | unittest.main() |
---|
| 143 | |
---|