- Timestamp:
- Apr 17, 2017 3:16:39 PM (8 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- da8bb53
- Parents:
- b09095a
- git-author:
- Jeff Krzywon <krzywon@…> (04/17/17 15:16:39)
- git-committer:
- krzywon <krzywon@…> (04/17/17 15:16:39)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
test/sasdataloader/test/utest_averaging.py
rb09095a r8ffafd1 1 1 2 import math 2 3 import unittest 3 import math4 5 from sas.sascalc.dataloader.loader import Loader6 from sas.sascalc.dataloader.manipulations import Ring, CircularAverage, SectorPhi, get_q,reader2D_converter7 8 4 import numpy as np 9 5 import sas.sascalc.dataloader.data_info as data_info 6 from sas.sascalc.dataloader.loader import Loader 7 from sas.sascalc.dataloader.manipulations import Boxsum, Boxavg, Ring, get_q,\ 8 CircularAverage, SectorPhi, SectorQ, reader2D_converter, SlabX, SlabY 9 10 10 11 11 class Averaging(unittest.TestCase): … … 18 18 should return the predefined height of the distribution (1.0). 19 19 """ 20 x_0 20 x_0 = np.ones([100,100]) 21 21 dx_0 = np.ones([100,100]) 22 22 23 23 self.data = data_info.Data2D(data=x_0, err_data=dx_0) 24 24 detector = data_info.Detector() 25 detector.distance = 1000.0 # mm26 detector.pixel_size.x = 1.0 # mm27 detector.pixel_size.y = 1.0 # mm28 25 detector.distance = 1000.0 # mm 26 detector.pixel_size.x = 1.0 # mm 27 detector.pixel_size.y = 1.0 # mm 28 29 29 # center in pixel position = (len(x_0)-1)/2 30 detector.beam_center.x = (len(x_0)-1)/2 # pixel number31 detector.beam_center.y = (len(x_0)-1)/2 # pixel number30 detector.beam_center.x = (len(x_0)-1)/2 # pixel number 31 detector.beam_center.y = (len(x_0)-1)/2 # pixel number 32 32 self.data.detector.append(detector) 33 33 34 34 source = data_info.Source() 35 source.wavelength = 10.0 # A35 source.wavelength = 10.0 # A 36 36 self.data.source = source 37 38 # get_q(dx, dy, det_dist, wavelength) where units are mm, mm,mm,and A respectively.37 38 # get_q(dx, dy, det_dist, wavelength) where units are mm, mm, mm, and A 39 39 self.qmin = get_q(1.0, 1.0, detector.distance, source.wavelength) 40 41 40 self.qmax = get_q(49.5, 49.5, detector.distance, source.wavelength) 42 41 43 42 self.qstep = len(x_0) 44 43 x= np.linspace(start= -1*self.qmax, … … 53 52 self.data.y_bins=y 54 53 self.data = reader2D_converter(self.data) 55 54 56 55 def test_ring_flat_distribution(self): 57 56 """ … … 62 61 center_y=self.data.detector[0].beam_center.y) 63 62 r.nbins_phi = 20 64 63 65 64 o = r(self.data) 66 65 for i in range(20): 67 66 self.assertEqual(o.y[i], 1.0) 68 67 69 68 def test_sectorphi_full(self): 70 69 """ … … 77 76 for i in range(7): 78 77 self.assertEqual(o.y[i], 1.0) 79 80 78 81 79 def test_sectorphi_partial(self): 82 80 """ … … 91 89 for i in range(17): 92 90 self.assertEqual(o.y[i], 1.0) 93 94 95 96 class data_info_tests(unittest.TestCase): 97 91 92 93 class DataInfoTests(unittest.TestCase): 94 98 95 def setUp(self): 99 96 self.data = Loader().load('MAR07232_rest.ASC') 100 97 101 98 def test_ring(self): 102 99 """ … … 107 104 center_y=self.data.detector[0].beam_center.y, 108 105 nbins = 20) 109 # #r.nbins_phi = 20110 106 # r.nbins_phi = 20 107 111 108 o = r(self.data) 112 109 data_list = Loader().load('ring_testdata.txt') 113 110 answer = data_list[0] 114 111 115 112 for i in range(r.nbins_phi - 1): 116 113 self.assertAlmostEqual(o.x[i + 1], answer.x[i], 4) 117 114 self.assertAlmostEqual(o.y[i + 1], answer.y[i], 4) 118 115 self.assertAlmostEqual(o.dy[i + 1], answer.dy[i], 4) 119 120 def test_circular avg(self):116 117 def test_circular_avg(self): 121 118 """ 122 119 Test circular averaging … … 126 123 bin_width=0.0003) 127 124 r.nbins_phi = 20 128 129 o = r(self.data) 130 131 answer = Loader().load('avg_testdata.txt')125 o = r(self.data) 126 127 output = Loader().load('avg_testdata.txt') 128 answer = output[0] 132 129 for i in range(r.nbins_phi): 133 130 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 134 131 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 135 132 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 136 133 137 134 def test_box(self): 138 135 """ … … 140 137 The test data was not generated by IGOR. 141 138 """ 142 from sas.sascalc.dataloader.manipulations import Boxsum, Boxavg143 144 139 r = Boxsum(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 145 140 s, ds, npoints = r(self.data) … … 147 142 self.assertAlmostEqual(ds, 7.8007981835194293, 4) 148 143 self.assertAlmostEqual(npoints, 324.0000, 4) 149 144 150 145 r = Boxavg(x_min=.01, x_max=.015, y_min=0.01, y_max=0.015) 151 146 s, ds = r(self.data) 152 147 self.assertAlmostEqual(s, 0.10579935462962962, 4) 153 148 self.assertAlmostEqual(ds, 0.024076537603455028, 4) 154 149 155 150 def test_slabX(self): 156 151 """ … … 158 153 The test data was not generated by IGOR. 159 154 """ 160 from sas.sascalc.dataloader.manipulations import SlabX161 162 155 r = SlabX(x_min=-.01, x_max=.01, y_min=-0.0002, y_max=0.0002, bin_width=0.0004) 163 156 r.fold = False 164 157 o = r(self.data) 165 158 166 answer = Loader().load('slabx_testdata.txt') 167 for i in range(len(o.x)): 168 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 169 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 170 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 171 159 output = Loader().load('slabx_testdata.txt') 160 answer = output[0] 161 for i in range(len(o.x)): 162 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 163 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 164 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 165 172 166 def test_slabY(self): 173 167 """ … … 175 169 The test data was not generated by IGOR. 176 170 """ 177 from sas.sascalc.dataloader.manipulations import SlabY178 179 171 r = SlabY(x_min=.005, x_max=.01, y_min=-0.01, y_max=0.01, bin_width=0.0004) 180 172 r.fold = False 181 173 o = r(self.data) 182 174 183 answer = Loader().load('slaby_testdata.txt') 184 for i in range(len(o.x)): 185 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 186 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 187 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 188 175 output = Loader().load('slaby_testdata.txt') 176 answer = output[0] 177 for i in range(len(o.x)): 178 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 179 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 180 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 181 189 182 def test_sectorphi_full(self): 190 183 """ … … 194 187 The test data was not generated by IGOR. 195 188 """ 196 from sas.sascalc.dataloader.manipulations import SectorPhi197 import math198 199 189 nbins = 19 200 190 phi_min = math.pi / (nbins + 1) 201 191 phi_max = math.pi * 2 - phi_min 202 192 203 193 r = SectorPhi(r_min=.005, 204 194 r_max=.01, … … 208 198 o = r(self.data) 209 199 210 answer = Loader().load('ring_testdata.txt') 200 output = Loader().load('ring_testdata.txt') 201 answer = output[0] 211 202 for i in range(len(o.x)): 212 203 self.assertAlmostEqual(o.x[i], answer.x[i], 4) … … 219 210 The test data was not generated by IGOR. 220 211 """ 221 from sas.sascalc.dataloader.manipulations import SectorPhi222 import math223 224 212 r = SectorPhi(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) 225 213 r.nbins_phi = 20 226 214 o = r(self.data) 227 215 228 answer = Loader().load('sectorphi_testdata.txt') 216 output = Loader().load('sectorphi_testdata.txt') 217 answer = output[0] 229 218 for i in range(len(o.x)): 230 219 self.assertAlmostEqual(o.x[i], answer.x[i], 4) … … 237 226 The test data was not generated by IGOR. 238 227 """ 239 from sas.sascalc.dataloader.manipulations import SectorQ240 import math241 242 228 r = SectorQ(r_min=.005, r_max=.01, phi_min=0, phi_max=math.pi/2.0) 243 229 r.nbins_phi = 20 244 230 o = r(self.data) 245 231 246 answer = Loader().load('sectorq_testdata.txt') 247 for i in range(len(o.x)): 248 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 249 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 250 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 251 232 output = Loader().load('sectorq_testdata.txt') 233 answer = output[0] 234 for i in range(len(o.x)): 235 self.assertAlmostEqual(o.x[i], answer.x[i], 4) 236 self.assertAlmostEqual(o.y[i], answer.y[i], 4) 237 self.assertAlmostEqual(o.dy[i], answer.dy[i], 4) 238 252 239 253 240 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.