Changeset 281 for inundation/ga/storm_surge/pyvolution/test_data_manager.py
- Timestamp:
- Sep 7, 2004, 10:29:42 PM (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r276 r281 128 128 129 129 130 # def test_sww_constant(self): 131 # """Test that constant sww information can be written correctly 132 # (non smooth) 133 # """ 134 135 # import time, os 136 # from Numeric import array, zeros, allclose, Float, concatenate 137 # from Scientific.IO.NetCDF import NetCDFFile 138 139 # self.domain.filename = 'datatest' + str(time.time()) 140 # self.domain.format = 'sww' 141 # self.domain.smooth = False 142 143 # sww = get_dataobject(self.domain) 144 # sww.store_all() 145 146 # #Check contents 147 # #Get NetCDF 148 # fid = NetCDFFile(sww.filename, 'r') #Open existing file for append 149 150 # # Get the variables 151 # x = fid.variables['x'] 152 # y = fid.variables['y'] 153 # z = fid.variables['z'] 154 155 # volumes = fid.variables['volumes'] 156 157 # assert allclose (x[:], concatenate( (self.X0, self.X1, self.X2) )) 158 # assert allclose (y[:], concatenate( (self.Y0, self.Y1, self.Y2) )) 159 # assert allclose (z[:], concatenate( (self.F0[:,0], 160 # self.F1[:,0], 161 # self.F2[:,0]) )) 162 163 # V = volumes 164 165 # P = len(self.domain) 166 # for k in range(P): 167 # assert V[k,0] == V[k,1] - P 168 # assert V[k,1] == V[k,2] - P 169 170 171 172 173 # fid.close() 174 175 # #Cleanup 176 # os.remove(sww.filename) 177 178 179 # def test_sww_constant_smooth(self): 180 # """Test that constant sww information can be written correctly 181 # (non smooth) 182 # """ 183 184 185 # import time, os 186 # from Numeric import array, zeros, allclose, Float, concatenate 187 # from Scientific.IO.NetCDF import NetCDFFile 188 189 # self.domain.filename = 'datatest' + str(time.time()) 190 # self.domain.format = 'sww' 191 # self.domain.smooth = True 192 193 # sww = get_dataobject(self.domain) 194 # sww.store_all() 195 196 # #Check contents 197 # #Get NetCDF 198 # fid = NetCDFFile(sww.filename, 'r') #Open existing file for append 199 200 # # Get the variables 201 # x = fid.variables['x'] 202 # y = fid.variables['y'] 203 # z = fid.variables['z'] 204 205 # volumes = fid.variables['volumes'] 206 207 # X = x[:] 208 # Y = y[:] 209 210 # assert allclose([X[0], Y[0]], array([0.0, 0.0])) 211 # assert allclose([X[1], Y[1]], array([0.0, 0.5])) 212 # assert allclose([X[2], Y[2]], array([0.0, 1.0])) 213 214 # assert allclose([X[4], Y[4]], array([0.5, 0.5])) 215 216 # assert allclose([X[7], Y[7]], array([1.0, 0.5])) 217 218 # Z = z[:] 219 # assert Z[4] == -0.5 220 221 222 223 # V = volumes 224 # assert V[2,0] == 4 225 # assert V[2,1] == 5 226 # assert V[2,2] == 1 227 228 # assert V[4,0] == 6 229 # assert V[4,1] == 7 230 # assert V[4,2] == 3 231 232 233 234 235 236 # fid.close() 237 238 # #Cleanup 239 # os.remove(sww.filename) 240 241 242 243 # def test_sww_variable(self): 244 # """Test that sww information can be written correctly 245 # """ 246 247 # import time, os 248 # from Numeric import array, zeros, allclose, Float, concatenate 249 # from Scientific.IO.NetCDF import NetCDFFile 250 251 # self.domain.filename = 'datatest' + str(time.time()) 252 # self.domain.format = 'sww' 253 # self.domain.smooth = True 254 # self.domain.reduction = mean 255 256 # sww = get_dataobject(self.domain) 257 # sww.store_all() 258 # sww.store_timestep() 259 260 # #Check contents 261 # #Get NetCDF 262 # fid = NetCDFFile(sww.filename, 'r') #Open existing file for append 263 264 265 # # Get the variables 266 # x = fid.variables['x'] 267 # y = fid.variables['y'] 268 # z = fid.variables['z'] 269 # time = fid.variables['time'] 270 # stage = fid.variables['stage'] 271 272 273 # Q0 = self.domain.volume_class.conserved_quantities_vertex0 274 # Q1 = self.domain.volume_class.conserved_quantities_vertex1 275 # Q2 = self.domain.volume_class.conserved_quantities_vertex2 276 277 # A = stage[0,:] 278 # #print A[0], (Q2[0,0] + Q1[1,0])/2 279 # assert allclose(A[0], (Q2[0,0] + Q1[1,0])/2) 280 # assert allclose(A[1], (Q0[1,0] + Q1[3,0] + Q2[2,0])/3) 281 # assert allclose(A[2], Q0[3,0]) 282 # assert allclose(A[3], (Q0[0,0] + Q1[5,0] + Q2[4,0])/3) 283 284 # #Center point 285 # assert allclose(A[4], (Q1[0,0] + Q2[1,0] + Q0[2,0] +\ 286 # Q0[5,0] + Q2[6,0] + Q1[7,0])/6) 287 288 289 290 # fid.close() 291 292 # #Cleanup 293 # os.remove(sww.filename) 130 def test_sww_constant(self): 131 """Test that constant sww information can be written correctly 132 (non smooth) 133 """ 134 135 import time, os 136 from Numeric import array, zeros, allclose, Float, concatenate 137 from Scientific.IO.NetCDF import NetCDFFile 138 139 self.domain.filename = 'datatest' + str(time.time()) 140 self.domain.format = 'sww' 141 self.domain.smooth = False 142 143 sww = get_dataobject(self.domain) 144 sww.store_connectivity() 145 146 #Check contents 147 #Get NetCDF 148 fid = NetCDFFile(sww.filename, 'r') #Open existing file for append 149 150 # Get the variables 151 x = fid.variables['x'] 152 y = fid.variables['y'] 153 z = fid.variables['z'] 154 155 volumes = fid.variables['volumes'] 156 157 #print z[:] 158 #print self.F.flat 159 #print concatenate( (self.X0, self.X1, self.X2)) 160 161 assert allclose (x[:], concatenate( (self.X0, self.X1, self.X2) )) 162 assert allclose (y[:], concatenate( (self.Y0, self.Y1, self.Y2) )) 163 assert allclose (z[:], self.F.flat) 164 165 V = volumes 166 167 P = len(self.domain) 168 for k in range(P): 169 assert V[k,0] == V[k,1] - P 170 assert V[k,1] == V[k,2] - P 171 172 173 174 175 fid.close() 176 177 #Cleanup 178 os.remove(sww.filename) 179 180 181 def test_sww_constant_smooth(self): 182 """Test that constant sww information can be written correctly 183 (non smooth) 184 """ 185 186 187 import time, os 188 from Numeric import array, zeros, allclose, Float, concatenate 189 from Scientific.IO.NetCDF import NetCDFFile 190 191 self.domain.filename = 'datatest' + str(time.time()) 192 self.domain.format = 'sww' 193 self.domain.smooth = True 194 195 sww = get_dataobject(self.domain) 196 sww.store_connectivity() 197 198 #Check contents 199 #Get NetCDF 200 fid = NetCDFFile(sww.filename, 'r') #Open existing file for append 201 202 # Get the variables 203 x = fid.variables['x'] 204 y = fid.variables['y'] 205 z = fid.variables['z'] 206 207 volumes = fid.variables['volumes'] 208 209 X = x[:] 210 Y = y[:] 211 212 assert allclose([X[0], Y[0]], array([0.0, 0.0])) 213 assert allclose([X[1], Y[1]], array([0.0, 0.5])) 214 assert allclose([X[2], Y[2]], array([0.0, 1.0])) 215 216 assert allclose([X[4], Y[4]], array([0.5, 0.5])) 217 218 assert allclose([X[7], Y[7]], array([1.0, 0.5])) 219 220 Z = z[:] 221 assert Z[4] == -0.5 222 223 V = volumes 224 assert V[2,0] == 4 225 assert V[2,1] == 5 226 assert V[2,2] == 1 227 228 assert V[4,0] == 6 229 assert V[4,1] == 7 230 assert V[4,2] == 3 231 232 233 234 235 236 fid.close() 237 238 #Cleanup 239 os.remove(sww.filename) 240 241 242 243 def test_sww_variable(self): 244 """Test that sww information can be written correctly 245 """ 246 247 import time, os 248 from Numeric import array, zeros, allclose, Float, concatenate 249 from Scientific.IO.NetCDF import NetCDFFile 250 251 self.domain.filename = 'datatest' + str(time.time()) 252 self.domain.format = 'sww' 253 self.domain.smooth = True 254 self.domain.reduction = mean 255 256 sww = get_dataobject(self.domain) 257 sww.store_connectivity() 258 sww.store_timestep('level') 259 260 #Check contents 261 #Get NetCDF 262 fid = NetCDFFile(sww.filename, 'r') #Open existing file for append 263 264 265 # Get the variables 266 x = fid.variables['x'] 267 y = fid.variables['y'] 268 z = fid.variables['z'] 269 time = fid.variables['time'] 270 stage = fid.variables['stage'] 271 272 273 Q = self.domain.quantities['level'] 274 Q0 = Q.vertex_values[:,0] 275 Q1 = Q.vertex_values[:,1] 276 Q2 = Q.vertex_values[:,2] 277 278 A = stage[0,:] 279 #print A[0], (Q2[0,0] + Q1[1,0])/2 280 assert allclose(A[0], (Q2[0] + Q1[1])/2) 281 assert allclose(A[1], (Q0[1] + Q1[3] + Q2[2])/3) 282 assert allclose(A[2], Q0[3]) 283 assert allclose(A[3], (Q0[0] + Q1[5] + Q2[4])/3) 284 285 #Center point 286 assert allclose(A[4], (Q1[0] + Q2[1] + Q0[2] +\ 287 Q0[5] + Q2[6] + Q1[7])/6) 288 289 290 291 fid.close() 292 293 #Cleanup 294 os.remove(sww.filename) 294 295 295 296 … … 421 422 #------------------------------------------------------------- 422 423 if __name__ == "__main__": 423 #suite = unittest.makeSuite(dataTestCase,'test_sww_constant') 424 suite = unittest.makeSuite(dataTestCase,'test_dummy') 424 suite = unittest.makeSuite(dataTestCase,'test') 425 425 runner = unittest.TextTestRunner() 426 426 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.