Changeset e2605a5 in sasview for sansdataloader/test/utest_manipulations.py
- Timestamp:
- May 23, 2012 3:41:29 PM (12 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:
- 0c24e98
- Parents:
- d56fc67
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansdataloader/test/utest_manipulations.py
rca3b9c5d re2605a5 133 133 def setUp(self): 134 134 # Create two data sets to play with 135 x_0 = 2.0*numpy.ones([5,4]) 136 dx_0 = 0.5*numpy.ones([5,4]) 137 self.data = Data2D(x_0, dx_0) 138 139 y = numpy.ones([5,4]) 140 dy = numpy.ones([5,4]) 141 self.data2 = Data2D(y, dy) 135 x_0 = 2.0*numpy.ones(100) 136 dx_0 = 0.5*numpy.ones(100) 137 qx_0 = numpy.arange(100) 138 qy_0 = numpy.arange(100) 139 mask_0 = numpy.zeros(100) 140 dqx_0 = numpy.arange(100)/100 141 dqy_0 = numpy.arange(100)/100 142 q_0 = numpy.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 143 self.data = Data2D(x_0, dx_0, qx_0, qy_0, q_0, mask_0, dqx_0, dqy_0) 144 145 y = numpy.ones(100) 146 dy = numpy.ones(100) 147 qx = numpy.arange(100) 148 qy = numpy.arange(100) 149 mask = numpy.zeros(100) 150 q = numpy.sqrt(qx * qx + qy * qy) 151 self.data2 = Data2D(y, dy, qx, qy, q, mask) 142 152 143 153 … … 147 157 """ 148 158 # There should be 5 entries in the file 149 self.assertEqual(numpy.size(self.data.data, 0), 5) 150 self.assertEqual(numpy.size(self.data.data, 1), 4) 151 152 for i in range(5): 153 for j in range(4): 154 # All y-error values should be 0.5 155 self.assertEqual(self.data.err_data[i][j], 0.5) 156 157 # All y values should be 2.0 158 self.assertEqual(self.data.data[i][j], 2.0) 159 self.assertEqual(numpy.size(self.data.data), 100) 160 161 for i in range(100): 162 # All y-error values should be 0.5 163 self.assertEqual(self.data.err_data[i], 0.5) 164 165 # All y values should be 2.0 166 self.assertEqual(self.data.data[i], 2.0) 159 167 160 168 def test_add(self): 161 169 result = self.data2+self.data 162 for i in range(5): 163 for j in range(4): 164 self.assertEqual(result.data[i][j], 3.0) 165 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 170 for i in range(100): 171 self.assertEqual(result.data[i], 3.0) 172 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 166 173 167 174 def test_sub(self): 168 175 result = self.data2-self.data 169 for i in range(5): 170 for j in range(4): 171 self.assertEqual(result.data[i][j], -1.0) 172 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 176 for i in range(100): 177 self.assertEqual(result.data[i], -1.0) 178 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 173 179 174 180 def test_mul(self): 175 181 result = self.data2*self.data 176 for i in range(5): 177 for j in range(4): 178 self.assertEqual(result.data[i][j], 2.0) 179 self.assertEqual(result.err_data[i][j], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 182 for i in range(100): 183 self.assertEqual(result.data[i], 2.0) 184 self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 180 185 181 186 def test_div(self): 182 187 result = self.data2/self.data 183 for i in range(5): 184 for j in range(4): 185 self.assertEqual(result.data[i][j], 0.5) 186 self.assertEqual(result.err_data[i][j], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 188 for i in range(100): 189 self.assertEqual(result.data[i], 0.5) 190 self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 187 191 188 192 def test_radd(self): 189 193 result = self.data+3.0 190 for i in range(5): 191 for j in range(4): 192 self.assertEqual(result.data[i][j], 5.0) 193 self.assertEqual(result.err_data[i][j], 0.5) 194 for i in range(100): 195 self.assertEqual(result.data[i], 5.0) 196 self.assertEqual(result.err_data[i], 0.5) 194 197 195 198 result = 3.0+self.data 196 for i in range(5): 197 for j in range(4): 198 self.assertEqual(result.data[i][j], 5.0) 199 self.assertEqual(result.err_data[i][j], 0.5) 199 for i in range(100): 200 self.assertEqual(result.data[i], 5.0) 201 self.assertEqual(result.err_data[i], 0.5) 200 202 201 203 def test_rsub(self): 202 204 result = self.data-3.0 203 for i in range(5): 204 for j in range(4): 205 self.assertEqual(result.data[i][j], -1.0) 206 self.assertEqual(result.err_data[i][j], 0.5) 205 for i in range(100): 206 self.assertEqual(result.data[i], -1.0) 207 self.assertEqual(result.err_data[i], 0.5) 207 208 208 209 result = 3.0-self.data 209 for i in range(5): 210 for j in range(4): 211 self.assertEqual(result.data[i][j], 1.0) 212 self.assertEqual(result.err_data[i][j], 0.5) 210 for i in range(100): 211 self.assertEqual(result.data[i], 1.0) 212 self.assertEqual(result.err_data[i], 0.5) 213 213 214 214 def test_rmul(self): 215 215 result = self.data*3.0 216 for i in range(5): 217 for j in range(4): 218 self.assertEqual(result.data[i][j], 6.0) 219 self.assertEqual(result.err_data[i][j], 1.5) 216 for i in range(100): 217 self.assertEqual(result.data[i], 6.0) 218 self.assertEqual(result.err_data[i], 1.5) 220 219 221 220 result = 3.0*self.data 222 for i in range(5): 223 for j in range(4): 224 self.assertEqual(result.data[i][j], 6.0) 225 self.assertEqual(result.err_data[i][j], 1.5) 221 for i in range(100): 222 self.assertEqual(result.data[i], 6.0) 223 self.assertEqual(result.err_data[i], 1.5) 226 224 227 225 def test_rdiv(self): 228 226 result = self.data/4.0 229 for i in range(5): 230 for j in range(4): 231 self.assertEqual(result.data[i][j], 0.5) 232 self.assertEqual(result.err_data[i][j], 0.125) 227 for i in range(100): 228 self.assertEqual(result.data[i], 0.5) 229 self.assertEqual(result.err_data[i], 0.125) 233 230 234 231 result = 6.0/self.data 235 for i in range(5): 236 for j in range(4): 237 self.assertEqual(result.data[i][j], 3.0) 238 self.assertEqual(result.err_data[i][j], 6.0*0.5/4.0) 232 for i in range(100): 233 self.assertEqual(result.data[i], 3.0) 234 self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 239 235 240 236
Note: See TracChangeset
for help on using the changeset viewer.