import unittest from DataLoader.loader import Loader from DataLoader.manipulations import Ring, CircularAverage import os.path class data_info_tests(unittest.TestCase): def setUp(self): self.data = Loader().load('MAR07232_rest.ASC') def test_ring(self): """ Test ring averaging """ r = Ring(r_min=.005, r_max=.01, center_x=self.data.detector[0].beam_center.x, center_y=self.data.detector[0].beam_center.y) r.nbins_phi = 20 o = r(self.data) answer = Loader().load('ring_testdata.txt') for i in range(r.nbins_phi): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) def test_circularavg(self): """ Test circular averaging The test data was not generated by IGOR. """ r = CircularAverage(r_min=.00, r_max=.025, bin_width=0.0003) r.nbins_phi = 20 o = r(self.data) answer = Loader().load('avg_testdata.txt') for i in range(r.nbins_phi): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) def test_box(self): """ Test circular averaging The test data was not generated by IGOR. """ from DataLoader.manipulations import Boxsum, Boxavg r = Boxsum(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) s, ds = r(self.data) self.assertAlmostEqual(s, 151.81809601016641, 4) self.assertAlmostEqual(ds, 16.245399156009537, 4) r = Boxavg(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) s, ds = r(self.data) self.assertAlmostEqual(s, 0.11195555855955155, 4) self.assertAlmostEqual(ds, 0.011979881083557541, 4) def test_slabX(self): """ Test slab in X The test data was not generated by IGOR. """ from DataLoader.manipulations import SlabX r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, y_max=0.0002, bin_width=0.0004) r.fold = False o = r(self.data) answer = Loader().load('slabx_testdata.txt') for i in range(len(o.x)): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) def test_slabY(self): """ Test slab in Y The test data was not generated by IGOR. """ from DataLoader.manipulations import SlabY r = SlabY(x_min=.005, x_max=.01, y_min=-0.01, y_max=0.01, bin_width=0.0004) r.fold = False o = r(self.data) answer = Loader().load('slaby_testdata.txt') for i in range(len(o.x)): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) def test_sectorphi_full(self): """ Test sector averaging I(phi) When considering the whole azimuthal range (2pi), the answer should be the same as ring averaging. The test data was not generated by IGOR. """ from DataLoader.manipulations import SectorPhi import math r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi*2.0) r.nbins_phi = 20 o = r(self.data) answer = Loader().load('ring_testdata.txt') for i in range(len(o.x)): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) def test_sectorphi_quarter(self): """ Test sector averaging I(phi) The test data was not generated by IGOR. """ from DataLoader.manipulations import SectorPhi import math r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) r.nbins_phi = 20 o = r(self.data) answer = Loader().load('sectorphi_testdata.txt') for i in range(len(o.x)): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) def test_sectorq_full(self): """ Test sector averaging I(q) The test data was not generated by IGOR. """ from DataLoader.manipulations import SectorQ import math r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) r.nbins_phi = 20 o = r(self.data) answer = Loader().load('sectorq_testdata.txt') for i in range(len(o.x)): self.assertAlmostEqual(o.x[i], answer.x[i], 4) self.assertAlmostEqual(o.y[i], answer.y[i], 4) self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) if __name__ == '__main__': unittest.main()