source: sasview/DataLoader/test/utest_averaging.py @ 2e83ff3

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 2e83ff3 was 2e83ff3, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Added sector average (phi and q)

  • Property mode set to 100644
File size: 5.4 KB
Line 
1
2import unittest
3
4from DataLoader.loader import  Loader
5from DataLoader.manipulations import Ring, CircularAverage
6 
7import os.path
8
9class 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    def test_slabX(self):
64        """
65            Test slab in X
66            The test data was not generated by IGOR.
67        """
68        from DataLoader.manipulations import SlabX
69       
70        r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, y_max=0.0002, bin_width=0.0004)
71        r.fold = False
72        o = r(self.data)
73   
74        answer = Loader().load('slabx_testdata.txt')
75        for i in range(len(o.x)):
76            self.assertAlmostEqual(o.x[i], answer.x[i], 4)
77            self.assertAlmostEqual(o.y[i], answer.y[i], 4)
78            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4)
79           
80    def test_slabY(self):
81        """
82            Test slab in Y
83            The test data was not generated by IGOR.
84        """
85        from DataLoader.manipulations import SlabY
86       
87        r = SlabY(x_min=.005, x_max=.01, y_min=-0.01, y_max=0.01, bin_width=0.0004)
88        r.fold = False
89        o = r(self.data)
90   
91        answer = Loader().load('slaby_testdata.txt')
92        for i in range(len(o.x)):
93            self.assertAlmostEqual(o.x[i], answer.x[i], 4)
94            self.assertAlmostEqual(o.y[i], answer.y[i], 4)
95            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4)
96           
97    def test_sectorphi_full(self):
98        """
99            Test sector averaging I(phi)
100            When considering the whole azimuthal range (2pi),
101            the answer should be the same as ring averaging.
102            The test data was not generated by IGOR.
103        """
104        from DataLoader.manipulations import SectorPhi
105        import math
106       
107        r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi*2.0)
108        r.nbins_phi = 20
109        o = r(self.data)
110   
111        answer = Loader().load('ring_testdata.txt')
112        for i in range(len(o.x)):
113            self.assertAlmostEqual(o.x[i], answer.x[i], 4)
114            self.assertAlmostEqual(o.y[i], answer.y[i], 4)
115            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4)
116           
117    def test_sectorphi_quarter(self):
118        """
119            Test sector averaging I(phi)
120            The test data was not generated by IGOR.
121        """
122        from DataLoader.manipulations import SectorPhi
123        import math
124       
125        r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0)
126        r.nbins_phi = 20
127        o = r(self.data)
128   
129        answer = Loader().load('sectorphi_testdata.txt')
130        for i in range(len(o.x)):
131            self.assertAlmostEqual(o.x[i], answer.x[i], 4)
132            self.assertAlmostEqual(o.y[i], answer.y[i], 4)
133            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4)
134           
135    def test_sectorq_full(self):
136        """
137            Test sector averaging I(q)
138            The test data was not generated by IGOR.
139        """
140        from DataLoader.manipulations import SectorQ
141        import math
142       
143        r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0)
144        r.nbins_phi = 20
145        o = r(self.data)
146   
147        answer = Loader().load('sectorq_testdata.txt')
148        for i in range(len(o.x)):
149            self.assertAlmostEqual(o.x[i], answer.x[i], 4)
150            self.assertAlmostEqual(o.y[i], answer.y[i], 4)
151            self.assertAlmostEqual(o.dy[i], answer.dy[i], 4)
152           
153
154if __name__ == '__main__':
155    unittest.main()
Note: See TracBrowser for help on using the repository browser.