Changeset eb8474f in sasview for DataLoader
- Timestamp:
- Feb 3, 2011 3:00:33 PM (14 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 95f9cc4
- Parents:
- 45ffa5e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
DataLoader/test/utest_smearing.py
rcd2ced80 reb8474f 9 9 from DataLoader.data_info import Data1D, Data2D 10 10 from DataLoader.qsmearing import SlitSmearer, QSmearer, smear_selection 11 from sans.models.SphereModel import SphereModel 11 12 12 import os.path 13 13 … … 54 54 input = 12.0-numpy.arange(1,11) 55 55 output = s(input) 56 # The following commented line was the correct output for even bins 57 # [see smearer.cpp for details] 58 #answer = [ 9.666, 9.056, 8.329, 7.494, 6.642, 5.721, 4.774, \ 59 # 3.824, 2.871, 2. ] 60 # The following answer was from numerical weighting algorithm. 61 #answer = [ 9.2302, 8.6806, 7.9533, 7.1673, 6.2889, 5.4, \ 62 # 4.5028, 3.5744, 2.6083, 2. ] 63 # For the new analytical algorithm, the small difference between 64 #these two could be from the first edge of the q bin size. 65 answer = [ 9.0618, 8.64018, 8.11868, 7.13916, 6.15285, 5.55556, \ 66 4.55842, 3.56061, 2.56235, 2. ] 56 # The following commented line was the correct output for even bins [see smearer.cpp for details] 57 #answer = [ 9.666, 9.056, 8.329, 7.494, 6.642, 5.721, 4.774, 3.824, 2.871, 2. ] 58 answer = [ 9.0618, 8.6401, 8.1186, 7.1391, 6.1528, 5.5555, 4.5584, 3.5606, 2.5623, 2. ] 67 59 for i in range(len(input)): 68 self.assertAlmostEqual(answer[i], output[i], 2)60 self.assertAlmostEqual(answer[i], output[i], 3) 69 61 70 62 def test_q(self): … … 98 90 for i in range(len(input)): 99 91 self.assertAlmostEqual(answer[i], output[i], 2) 100 101 class smear_slit_h_w_tests(unittest.TestCase): 102 103 def setUp(self): 104 self.data = Loader().load("1000A_sphere_sm.xml") 105 self.model = SphereModel() 106 # The answer could be improved by developing better algorithm. 107 self.answer1 = Loader().load("slit_1000A_sphere_sm_w_0_0002.txt") 108 self.answer2 = Loader().load("slit_1000A_sphere_sm_h.txt") 109 self.answer3 = Loader().load("slit_1000A_sphere_sm_w_0_0001.txt") 110 # Get inputs 111 self.model.params['scale'] = 0.05 112 self.model.params['background'] = 0.01 113 self.model.params['radius'] = 10000.0 114 self.model.params['sldSolv'] = 6.3e-006 115 self.model.params['sldSph'] = 3.4e-006 116 117 def test_slit_h_w(self): 118 """ 119 Test identity slit smearing w/ h=0.117 w = 0.002 120 """ 121 # Set params and dQl 122 data = self.data 123 data.dxw = 0.0002 * numpy.ones(len(self.data.x)) 124 data.dxl = 0.117 * numpy.ones(len(self.data.x)) 125 # Create smearer for our data 126 s = SlitSmearer(data, self.model) 127 # Get smear 128 input = self.model.evalDistribution(data.x) 129 output = s(input) 130 # Get pre-calculated values 131 answer = self.answer1.y 132 # Now compare 133 for i in range(len(input)): 134 self.assertAlmostEqual(answer[i], output[i], 0) 135 136 def test_slit_h(self): 137 """ 138 Test identity slit smearing w/ h=0.117 w = 0.0 139 """ 140 # Set params and dQl 141 data = self.data 142 data.dxw = 0.0 * numpy.ones(len(self.data.x)) 143 data.dxl = 0.117 * numpy.ones(len(self.data.x)) 144 # Create smearer for our data 145 s = SlitSmearer(data, self.model) 146 # Get smear 147 input = self.model.evalDistribution(data.x) 148 output = s(input) 149 # Get pre-calculated values 150 answer = self.answer2.y 151 # Now compare 152 for i in range(len(input)): 153 self.assertAlmostEqual(answer[i], output[i], 0) 154 155 def test_slit_w(self): 156 """ 157 Test identity slit smearing w/ h=0.0 w = 0.001 158 """ 159 # Set params and dQl 160 data = self.data 161 data.dxw = 0.0001 * numpy.ones(len(self.data.x)) 162 data.dxl = 0.0 * numpy.ones(len(self.data.x)) 163 # Create smearer for our data 164 s = SlitSmearer(data, self.model) 165 # Get smear 166 input = self.model.evalDistribution(data.x) 167 output = s(input) 168 # Get pre-calculated values 169 answer = self.answer3.y 170 # Now compare 171 for i in range(len(input)): 172 if i <= 40: 173 self.assertAlmostEqual(answer[i], output[i], -3) 174 else: 175 self.assertAlmostEqual(answer[i], output[i], 0) 176 92 93 177 94 if __name__ == '__main__': 178 95 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.