Changeset 4a47244 in sasview
- Timestamp:
- Jun 15, 2012 3:45:08 PM (13 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:
- 9053779
- Parents:
- d970df9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sansguiframe/test/utest_manipulations.py
r117a1d6 r4a47244 153 153 def setUp(self): 154 154 # Create two data sets to play with 155 x_0 = 2.0*numpy.ones([5,4]) 156 dx_0 = 0.5*numpy.ones([5,4]) 157 self.data = Data2D(x_0, dx_0) 158 159 y = numpy.ones([5,4]) 160 dy = numpy.ones([5,4]) 161 self.data2 = Data2D(y, dy) 155 x_0 = 2.0*numpy.ones(25) 156 dx_0 = 0.5*numpy.ones(25) 157 qx_0 = numpy.arange(25) 158 qy_0 = numpy.arange(25) 159 mask_0 = numpy.zeros(25) 160 dqx_0 = numpy.arange(25)/100 161 dqy_0 = numpy.arange(25)/100 162 q_0 = numpy.sqrt(qx_0 * qx_0 + qy_0 * qy_0) 163 self.data = Data2D(image=x_0, err_image=dx_0, qx_data=qx_0, 164 qy_data=qy_0, q_data=q_0, mask=mask_0, 165 dqx_data=dqx_0, dqy_data=dqy_0) 166 167 y = numpy.ones(25) 168 dy = numpy.ones(25) 169 qx = numpy.arange(25) 170 qy = numpy.arange(25) 171 mask = numpy.zeros(25) 172 q = numpy.sqrt(qx * qx + qy * qy) 173 self.data2 = Data2D(image=y, err_image=dy, qx_data=qx, qy_data=qy, 174 q_data=q, mask=mask) 162 175 163 176 … … 167 180 """ 168 181 # There should be 5 entries in the file 169 self.assertEqual(numpy.size(self.data.data, 0), 5) 170 self.assertEqual(numpy.size(self.data.data, 1), 4) 171 172 for i in range(5): 173 for j in range(4): 174 # All y-error values should be 0.5 175 self.assertEqual(self.data.err_data[i][j], 0.5) 176 177 # All y values should be 2.0 178 self.assertEqual(self.data.data[i][j], 2.0) 182 self.assertEqual(numpy.size(self.data.data), 25) 183 184 for i in range(25): 185 # All y-error values should be 0.5 186 self.assertEqual(self.data.err_data[i], 0.5) 187 188 # All y values should be 2.0 189 self.assertEqual(self.data.data[i], 2.0) 179 190 180 191 def test_add(self): 181 192 result = self.data2+self.data 182 for i in range(5): 183 for j in range(4): 184 self.assertEqual(result.data[i][j], 3.0) 185 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 193 for i in range(25): 194 self.assertEqual(result.data[i], 3.0) 195 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 186 196 187 197 def test_sub(self): 188 198 result = self.data2-self.data 189 for i in range(5): 190 for j in range(4): 191 self.assertEqual(result.data[i][j], -1.0) 192 self.assertEqual(result.err_data[i][j], math.sqrt(0.5**2+1.0)) 199 for i in range(25): 200 self.assertEqual(result.data[i], -1.0) 201 self.assertEqual(result.err_data[i], math.sqrt(0.5**2+1.0)) 193 202 194 203 def test_mul(self): 195 204 result = self.data2*self.data 196 for i in range(5): 197 for j in range(4): 198 self.assertEqual(result.data[i][j], 2.0) 199 self.assertEqual(result.err_data[i][j], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 205 for i in range(25): 206 self.assertEqual(result.data[i], 2.0) 207 self.assertEqual(result.err_data[i], math.sqrt((0.5*1.0)**2+(1.0*2.0)**2)) 200 208 201 209 def test_div(self): 202 210 result = self.data2/self.data 203 for i in range(5): 204 for j in range(4): 205 self.assertEqual(result.data[i][j], 0.5) 206 self.assertEqual(result.err_data[i][j], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 211 for i in range(25): 212 self.assertEqual(result.data[i], 0.5) 213 self.assertEqual(result.err_data[i], math.sqrt((1.0/2.0)**2+(0.5*1.0/4.0)**2)) 207 214 208 215 def test_radd(self): 209 216 result = self.data+3.0 210 for i in range(5): 211 for j in range(4): 212 self.assertEqual(result.data[i][j], 5.0) 213 self.assertEqual(result.err_data[i][j], 0.5) 214 217 for i in range(25): 218 self.assertEqual(result.data[i], 5.0) 219 self.assertEqual(result.err_data[i], 0.5) 220 215 221 result = 3.0+self.data 216 for i in range(5): 217 for j in range(4): 218 self.assertEqual(result.data[i][j], 5.0) 219 self.assertEqual(result.err_data[i][j], 0.5) 222 for i in range(25): 223 self.assertEqual(result.data[i], 5.0) 224 self.assertEqual(result.err_data[i], 0.5) 220 225 221 226 def test_rsub(self): 222 227 result = self.data-3.0 223 for i in range(5): 224 for j in range(4): 225 self.assertEqual(result.data[i][j], -1.0) 226 self.assertEqual(result.err_data[i][j], 0.5) 227 228 for i in range(25): 229 self.assertEqual(result.data[i], -1.0) 230 self.assertEqual(result.err_data[i], 0.5) 231 228 232 result = 3.0-self.data 229 for i in range(5): 230 for j in range(4): 231 self.assertEqual(result.data[i][j], 1.0) 232 self.assertEqual(result.err_data[i][j], 0.5) 233 for i in range(25): 234 self.assertEqual(result.data[i], 1.0) 235 self.assertEqual(result.err_data[i], 0.5) 233 236 234 237 def test_rmul(self): 235 238 result = self.data*3.0 236 for i in range(5): 237 for j in range(4): 238 self.assertEqual(result.data[i][j], 6.0) 239 self.assertEqual(result.err_data[i][j], 1.5) 240 239 for i in range(25): 240 self.assertEqual(result.data[i], 6.0) 241 self.assertEqual(result.err_data[i], 1.5) 242 241 243 result = 3.0*self.data 242 for i in range(5): 243 for j in range(4): 244 self.assertEqual(result.data[i][j], 6.0) 245 self.assertEqual(result.err_data[i][j], 1.5) 244 for i in range(25): 245 self.assertEqual(result.data[i], 6.0) 246 self.assertEqual(result.err_data[i], 1.5) 246 247 247 248 def test_rdiv(self): 248 249 result = self.data/4.0 249 for i in range(5): 250 for j in range(4): 251 self.assertEqual(result.data[i][j], 0.5) 252 self.assertEqual(result.err_data[i][j], 0.125) 253 250 for i in range(25): 251 self.assertEqual(result.data[i], 0.5) 252 self.assertEqual(result.err_data[i], 0.125) 253 254 254 result = 6.0/self.data 255 for i in range(5): 256 for j in range(4): 257 self.assertEqual(result.data[i][j], 3.0) 258 self.assertEqual(result.err_data[i][j], 6.0*0.5/4.0) 259 255 for i in range(25): 256 self.assertEqual(result.data[i], 3.0) 257 self.assertEqual(result.err_data[i], 6.0*0.5/4.0) 258 260 259 261 260 if __name__ == '__main__':
Note: See TracChangeset
for help on using the changeset viewer.