Changeset 9734 for trunk/anuga_core/anuga/file_conversion
- Timestamp:
- Sep 5, 2015, 4:03:54 PM (10 years ago)
- Location:
- trunk/anuga_core/anuga/file_conversion
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/anuga/file_conversion/dem2array.py
r9497 r9734 77 77 Z = Z.reshape(nrows,ncols) 78 78 Z = num.where(Z == NODATA_value , num.nan, Z) 79 79 #changed the orientation of Z array to make it consistent with grd2array result 80 Z = num.fliplr(Z.T) 80 81 81 82 #print ncols, nrows, xllcorner,yllcorner, cellsize, NODATA_value, zone -
trunk/anuga_core/anuga/file_conversion/dem2pts.py
r8832 r9734 42 42 43 43 if use_cache is True: 44 from caching import cache44 from anuga.caching import cache 45 45 result = cache(_dem2pts, name_in, kwargs, 46 46 dependencies = [name_in], … … 153 153 outfile.nrows = nrows 154 154 155 dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols))155 #dem_elevation_r = num.reshape(dem_elevation, (nrows, ncols)) 156 156 totalnopoints = nrows*ncols 157 157 -
trunk/anuga_core/anuga/file_conversion/sww2dem.py
r9550 r9734 180 180 log.critical(' Time: %f' % times) 181 181 else: 182 log.critical(' Start time: %f' % fid.starttime [0])182 log.critical(' Start time: %f' % fid.starttime) 183 183 log.critical(' Extent:') 184 184 log.critical(' x [m] in [%f, %f], len(x) == %d' -
trunk/anuga_core/anuga/file_conversion/tests/test_dem2array.py
r9510 r9734 66 66 67 67 Z_ex = num.array(ref_elevation,num.float).reshape(12,11) 68 69 #Write prj file with metadata 68 Z_ex = num.fliplr(Z_ex.T) 69 70 #Write prj file with metadata 70 71 metafilename = root+'.prj' 71 72 fid = open(metafilename, 'w') … … 91 92 x,y, Z = dem2array(root+'.dem') 92 93 93 # print Z94 # print Z_ex95 94 # print x 96 95 # print xvec 97 96 # print y 98 97 # print yvec 99 100 98 assert num.allclose(Z,Z_ex) 101 99 assert num.allclose(x,xvec) -
trunk/anuga_core/anuga/file_conversion/tests/test_dem2pts.py
r9551 r9734 126 126 ref_points.append ([xnew,ynew]) #Relative point values 127 127 128 assert num.allclose(points , ref_points)129 130 assert num.allclose(elevation , ref_elevation)128 assert num.allclose(points[:], ref_points) 129 130 assert num.allclose(elevation[:], ref_elevation) 131 131 132 132 #Cleanup … … 390 390 #print new_ref_points, len(new_ref_points) 391 391 392 assert num.allclose(elevation , ref_elevation)393 assert num.allclose(points , new_ref_points)392 assert num.allclose(elevation[:], ref_elevation) 393 assert num.allclose(points[:], new_ref_points) 394 394 395 395 -
trunk/anuga_core/anuga/file_conversion/tests/test_file_conversion.py
r9562 r9734 19 19 from anuga.file.mux import WAVEHEIGHT_MUX_LABEL, EAST_VELOCITY_LABEL, \ 20 20 NORTH_VELOCITY_LABEL 21 22 21 import sys 23 22 import unittest … … 26 25 import os 27 26 27 def axes2points(x, y): 28 """Generate all combinations of grid point coordinates from x and y axes 29 30 Args: 31 * x: x coordinates (array) 32 * y: y coordinates (array) 33 34 Returns: 35 * P: Nx2 array consisting of coordinates for all 36 grid points defined by x and y axes. The x coordinate 37 will vary the fastest to match the way 2D numpy 38 arrays are laid out by default ('C' order). That way, 39 the x and y coordinates will match a corresponding 40 2D array A when flattened (A.flat[:] or A.reshape(-1)) 41 42 Note: 43 Example 44 45 x = [1, 2, 3] 46 y = [10, 20] 47 48 P = [[1, 10], 49 [2, 10], 50 [3, 10], 51 [1, 20], 52 [2, 20], 53 [3, 20]] 54 """ 55 import numpy 56 57 # Reverse y coordinates to have them start at bottom of array 58 y = numpy.flipud(y) 59 60 # Repeat x coordinates for each y (fastest varying) 61 X = numpy.kron(numpy.ones(len(y)), x) 62 63 # Repeat y coordinates for each x (slowest varying) 64 Y = numpy.kron(y, numpy.ones(len(x))) 65 66 # Check 67 N = len(X) 68 assert len(Y) == N 69 70 # Create Nx2 array of x and y coordinates 71 X = numpy.reshape(X, (N, 1)) 72 Y = numpy.reshape(Y, (N, 1)) 73 P = numpy.concatenate((X, Y), axis=1) 74 75 # Return 76 return P 77 78 def linear_function(point): 79 point = num.array(point) 80 return point[:,0]+3*point[:,1] 28 81 29 82 class Test_File_Conversion(unittest.TestCase): … … 945 998 os.remove(root+'.txt') 946 999 1000 1001 def test_grd2array_dem2array(self): 1002 '''test the conversion result of grd to array and dem to array. The pts files should be the same''' 1003 #ANUGA models 1004 from anuga.file_conversion.grd2array import grd2array 1005 from anuga.file_conversion.dem2array import dem2array 1006 from anuga.file_conversion.asc2dem import asc2dem 1007 1008 #Create .asc file. Uses the example from test_grd2array.py 1009 """ Format of asc file 1010 ncols 11 1011 nrows 12 1012 xllcorner 240000 1013 yllcorner 7620000 1014 cellsize 6000 1015 NODATA_value -9999 1016 """ 1017 1018 x0 = 0.0 1019 y0 = 0.0 1020 1021 ncols = 11 # Nx 1022 nrows = 12 # Ny 1023 xllcorner = x0 1024 yllcorner = y0 1025 cellsize = 1.0 1026 NODATA_value = -9999 1027 1028 #Create .asc file 1029 root = 'test_asc' 1030 txt_file = root+'.asc' 1031 datafile = open(txt_file,"w") 1032 datafile.write('ncols '+str(ncols)+"\n") 1033 datafile.write('nrows '+str(nrows)+"\n") 1034 datafile.write('xllcorner '+str(xllcorner)+"\n") 1035 datafile.write('yllcorner '+str(yllcorner)+"\n") 1036 datafile.write('cellsize '+str(cellsize)+"\n") 1037 datafile.write('NODATA_value '+str(NODATA_value)+"\n") 1038 1039 x_ex = num.linspace(xllcorner, xllcorner+(ncols-1)*cellsize, ncols) 1040 y_ex = num.linspace(yllcorner, yllcorner+(nrows-1)*cellsize, nrows) 1041 Z_ex = [[ 0., 3., 6., 9., 12., 15., 18., 21., 24., 27., 30., 33.], 1042 [ 1., 4., 7., 10., 13., 16., 19., 22., 25., 28., 31., 34.], 1043 [ 2., 5., 8., 11., 14., 17., 20., 23., 26., 29., 32., 35.], 1044 [ 3., 6., 9., 12., 15., 18., 21., 24., 27., 30., 33., 36.], 1045 [ 4., 7., 10., 13., 16., 19., 22., 25., 28., 31., 34., 37.], 1046 [ 5., 8., 11., 14., 17., 20., 23., 26., 29., 32., 35., 38.], 1047 [ 6., 9., 12., 15., 18., 21., 24., 27., 30., 33., 36., 39.], 1048 [ 7., 10., 13., 16., 19., 22., 25., 28., 31., 34., 37., 40.], 1049 [ 8., 11., 14., 17., 20., 23., 26., 29., 32., 35., 38., 41.], 1050 [ 9., 12., 15., 18., 21., 24., 27., 30., 33., 36., 39., 42.], 1051 [ 10., 13., 16., 19., 22., 25., 28., 31., 34., 37., 40., 43.]] 1052 1053 points = axes2points(x_ex, y_ex) 1054 1055 datavalues = linear_function(points) 1056 datavalues = datavalues.reshape(nrows,ncols) 1057 1058 for row in datavalues: 1059 #print row 1060 datafile.write(" ".join(str(elem) for elem in row) + "\n") 1061 datafile.close() 1062 1063 1064 #create dem file from asc file 1065 txt_file_prj = root+'.prj' 1066 fid = open(txt_file_prj, 'w') 1067 fid.write("""Projection UTM 1068 Zone 56 1069 Datum WGS84 1070 Zunits NO 1071 Units METERS 1072 Spheroid WGS84 1073 Xshift 0.0000000000 1074 Yshift 10000000.0000000000 1075 Parameters 1076 """) 1077 fid.close() 1078 1079 txt_file_dem = root+'.dem' 1080 asc2dem(name_in=txt_file, name_out=root, 1081 use_cache=False, verbose=False) 1082 1083 #convert grd to array 1084 x_grd, y_grd, Z_grd = grd2array(txt_file) 1085 #convert dem to array 1086 x_dem, y_dem, Z_dem = dem2array(txt_file_dem) 1087 1088 #check grd2array and dem2array results are equal 1089 assert num.allclose(x_grd, x_dem) 1090 assert num.allclose(y_grd, y_dem) 1091 assert num.allclose(Z_grd, Z_dem) 1092 1093 #check grd2array (dem2array) results are correct 1094 assert num.allclose(x_grd, x_ex) 1095 assert num.allclose(y_grd, y_ex) 1096 assert num.allclose(Z_grd, Z_ex) 1097 1098 try: 1099 os.remove(root + '.dem') 1100 os.remove(root + '.asc') 1101 os.remove(root + '.prj') 1102 except: 1103 # Expect error on windows 1104 pass 947 1105 #------------------------------------------------------------- 948 1106 -
trunk/anuga_core/anuga/file_conversion/tests/test_sww2dem.py
r9733 r9734 1 import unittest, os 1 import unittest, os, sys 2 2 import numpy as num 3 3 … … 25 25 from pprint import pprint 26 26 27 from cStringIO import StringIO 28 import sys 29 30 class Capturing(list): 31 def __enter__(self): 32 self._stdout = sys.stdout 33 sys.stdout = self._stringio = StringIO() 34 return self 35 def __exit__(self, *args): 36 self.extend(self._stringio.getvalue().splitlines()) 37 sys.stdout = self._stdout 38 27 39 class Test_Sww2Dem(unittest.TestCase): 28 40 def setUp(self): … … 38 50 39 51 # Set some field values 40 domain.set_quantity('elevation', lambda x, y:-x)52 domain.set_quantity('elevation', lambda x, y:-x) 41 53 domain.set_quantity('friction', 0.03) 42 54 … … 45 57 # Boundary conditions 46 58 B = Transmissive_boundary(domain) 47 domain.set_boundary( 59 domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B}) 48 60 49 61 50 62 ###################### 51 # Initial condition - with jumps63 # Initial condition - with jumps 52 64 bed = domain.quantities['elevation'].vertex_values 53 65 stage = num.zeros(bed.shape, num.float) … … 56 68 for i in range(stage.shape[0]): 57 69 if i % 2 == 0: 58 stage[i, :] = bed[i,:] + h70 stage[i, :] = bed[i, :] + h 59 71 else: 60 stage[i, :] = bed[i,:]72 stage[i, :] = bed[i, :] 61 73 62 74 domain.set_quantity('stage', stage) … … 67 79 68 80 C = domain.get_vertex_coordinates() 69 self.X = C[:, 0:6:2].copy()70 self.Y = C[:, 1:6:2].copy()81 self.X = C[:, 0:6:2].copy() 82 self.Y = C[:, 1:6:2].copy() 71 83 72 84 self.F = bed 85 # self.verbose = False 73 86 self.verbose = False 74 75 87 76 88 def tearDown(self): … … 100 112 self.domain.format = 'sww' 101 113 self.domain.smooth = True 102 self.domain.set_quantity('elevation', lambda x, y: -x-y)114 self.domain.set_quantity('elevation', lambda x, y:-x - y) 103 115 self.domain.set_quantity('stage', 1.0) 104 116 … … 110 122 111 123 112 self.domain.evolve_to_end(finaltime =0.01)124 self.domain.evolve_to_end(finaltime=0.01) 113 125 sww.store_timestep() 114 126 115 127 cellsize = 0.25 116 # Check contents117 # Get NetCDF128 # Check contents 129 # Get NetCDF 118 130 119 131 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 134 146 fid.close() 135 147 136 # Export to ascii/prj files137 sww2dem(self.domain.get_name() +'.sww',138 self.domain.get_name() +'_elevation.asc',139 quantity ='elevation',140 cellsize =cellsize,141 number_of_decimal_places =9,142 verbose =self.verbose)143 144 # Check prj (meta data)148 # Export to ascii/prj files 149 sww2dem(self.domain.get_name() + '.sww', 150 self.domain.get_name() + '_elevation.asc', 151 quantity='elevation', 152 cellsize=cellsize, 153 number_of_decimal_places=9, 154 verbose=self.verbose) 155 156 # Check prj (meta data) 145 157 prjid = open(prjfile) 146 158 lines = prjid.readlines() … … 183 195 184 196 185 # Check asc file197 # Check asc file 186 198 ascid = open(ascfile) 187 199 lines = ascid.readlines() … … 212 224 assert L[1].strip().lower() == '-9999' 213 225 214 # Check grid values226 # Check grid values 215 227 for j in range(5): 216 L = lines[6 +j].strip().split()217 y = (4 -j) * cellsize228 L = lines[6 + j].strip().split() 229 y = (4 - j) * cellsize 218 230 for i in range(5): 219 assert num.allclose(float(L[i]), -i *cellsize - y)231 assert num.allclose(float(L[i]), -i * cellsize - y) 220 232 221 # Cleanup233 # Cleanup 222 234 os.remove(prjfile) 223 235 os.remove(ascfile) … … 226 238 prjfile = self.domain.get_name() + '_depth.prj' 227 239 228 # Export to ascii/prj files229 sww2dem(self.domain.get_name() +'.sww',240 # Export to ascii/prj files 241 sww2dem(self.domain.get_name() + '.sww', 230 242 ascfile, 231 quantity ='depth',232 cellsize =cellsize,233 number_of_decimal_places =9,234 verbose =self.verbose)235 236 # Check asc file243 quantity='depth', 244 cellsize=cellsize, 245 number_of_decimal_places=9, 246 verbose=self.verbose) 247 248 # Check asc file 237 249 ascid = open(ascfile) 238 250 lines = ascid.readlines() … … 263 275 assert L[1].strip().lower() == '-9999' 264 276 265 # Check grid values277 # Check grid values 266 278 for j in range(5): 267 L = lines[6 +j].strip().split()268 y = (4 -j) * cellsize279 L = lines[6 + j].strip().split() 280 y = (4 - j) * cellsize 269 281 for i in range(5): 270 assert num.allclose(float(L[i]), 1 - (-i *cellsize - y))271 272 273 # Cleanup282 assert num.allclose(float(L[i]), 1 - (-i * cellsize - y)) 283 284 285 # Cleanup 274 286 os.remove(prjfile) 275 287 os.remove(ascfile) … … 303 315 import time, os 304 316 305 # Create basic mesh (100m x 100m)317 # Create basic mesh (100m x 100m) 306 318 points, vertices, boundary = rectangular(2, 2, 100, 100) 307 319 308 # Create shallow water domain320 # Create shallow water domain 309 321 domain = Domain(points, vertices, boundary) 310 322 domain.default_order = 2 … … 323 335 324 336 # FIXME: de0 algorithm doesn't recreate a linear function! 325 domain.set_quantity('elevation', lambda x, y: -x-y)337 domain.set_quantity('elevation', lambda x, y:-x - y) 326 338 domain.set_quantity('stage', 0) 327 339 328 340 B = Transmissive_boundary(domain) 329 domain.set_boundary( 341 domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B}) 330 342 331 343 # … … 335 347 336 348 domain.tight_slope_limiters = 1 337 domain.evolve_to_end(finaltime =0.01)338 sww.store_timestep() 339 340 cellsize = 10.0 # 10m grid341 342 343 # Export to ascii/prj files349 domain.evolve_to_end(finaltime=0.01) 350 sww.store_timestep() 351 352 cellsize = 10.0 # 10m grid 353 354 355 # Export to ascii/prj files 344 356 sww2dem(domain.get_name() + '.sww', 345 357 domain.get_name() + '_elevation.asc', 346 quantity ='elevation',347 cellsize =cellsize,348 number_of_decimal_places =3,349 verbose =self.verbose,358 quantity='elevation', 359 cellsize=cellsize, 360 number_of_decimal_places=3, 361 verbose=self.verbose, 350 362 block_size=2) 351 363 352 364 353 # Check prj (meta data)365 # Check prj (meta data) 354 366 prjid = open(prjfile) 355 367 lines = prjid.readlines() … … 392 404 393 405 394 # Check asc file406 # Check asc file 395 407 ascid = open(ascfile) 396 408 lines = ascid.readlines() … … 421 433 assert L[1].strip().lower() == '-9999' 422 434 423 # Check grid values (FIXME: Use same strategy for other sww2dem tests)435 # Check grid values (FIXME: Use same strategy for other sww2dem tests) 424 436 425 437 V = [-1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.333e+02, -1.367e+02, -1.400e+02, -1.433e+02, -1.467e+02, -1.500e+02, 426 - 9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.300e+02, -1.333e+02, -1.367e+02, -1.400e+02, -1.467e+02,427 - 8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.233e+02, -1.267e+02, -1.300e+02, -1.367e+02, -1.433e+02,428 - 8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.167e+02, -1.200e+02, -1.267e+02, -1.333e+02, -1.400e+02,429 - 7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.100e+02, -1.167e+02, -1.233e+02, -1.300e+02, -1.367e+02,430 - 6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.333e+02,431 - 6.333e+01, -7.000e+01, -7.667e+01, -8.333e+01, -9.000e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02,432 - 6.000e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.333e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02,433 - 5.667e+01, -6.333e+01, -7.000e+01, -7.333e+01, -7.667e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02,434 - 5.333e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.000e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02,435 - 5.000e+01, -5.333e+01, -5.667e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02 ]438 - 9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.300e+02, -1.333e+02, -1.367e+02, -1.400e+02, -1.467e+02, 439 - 8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.233e+02, -1.267e+02, -1.300e+02, -1.367e+02, -1.433e+02, 440 - 8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.167e+02, -1.200e+02, -1.267e+02, -1.333e+02, -1.400e+02, 441 - 7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.100e+02, -1.167e+02, -1.233e+02, -1.300e+02, -1.367e+02, 442 - 6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, -1.333e+02, 443 - 6.333e+01, -7.000e+01, -7.667e+01, -8.333e+01, -9.000e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, -1.267e+02, 444 - 6.000e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.333e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, -1.200e+02, 445 - 5.667e+01, -6.333e+01, -7.000e+01, -7.333e+01, -7.667e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, -1.133e+02, 446 - 5.333e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.000e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02, -1.067e+02, 447 - 5.000e+01, -5.333e+01, -5.667e+01, -6.000e+01, -6.333e+01, -6.667e+01, -7.333e+01, -8.000e+01, -8.667e+01, -9.333e+01, -1.000e+02 ] 436 448 437 449 for i, line in enumerate(lines[6:]): 438 for j, value in enumerate( line.split()):439 assert num.allclose(float(value), V[i *11+j],450 for j, value in enumerate(line.split()): 451 assert num.allclose(float(value), V[i * 11 + j], 440 452 atol=1.0e-12, rtol=1.0e-12) 441 453 442 454 # Note: Equality can be obtained in this case, 443 455 # but it is better to use allclose. 444 # assert float(value) == -(10-i+j)*cellsize445 446 447 # fid.close()448 449 # Cleanup450 #os.remove(prjfile)451 #os.remove(ascfile)452 #os.remove(swwfile)456 # assert float(value) == -(10-i+j)*cellsize 457 458 459 # fid.close() 460 461 # Cleanup 462 os.remove(prjfile) 463 os.remove(ascfile) 464 os.remove(swwfile) 453 465 454 466 … … 479 491 import time, os 480 492 481 # Create basic mesh (100m x 100m)493 # Create basic mesh (100m x 100m) 482 494 points, vertices, boundary = rectangular(2, 2, 100, 100) 483 495 484 # Create shallow water domain496 # Create shallow water domain 485 497 domain = Domain(points, vertices, boundary) 486 498 domain.set_flow_algorithm('1_5') … … 499 511 500 512 # 501 domain.set_quantity('elevation', lambda x, y: -x-y)513 domain.set_quantity('elevation', lambda x, y:-x - y) 502 514 domain.set_quantity('stage', 0) 503 515 504 516 B = Transmissive_boundary(domain) 505 domain.set_boundary( 517 domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B}) 506 518 507 519 … … 512 524 513 525 domain.tight_slope_limiters = 1 514 domain.evolve_to_end(finaltime =0.01)515 sww.store_timestep() 516 517 cellsize = 10 # 10m grid518 519 520 521 # Export to ascii/prj files526 domain.evolve_to_end(finaltime=0.01) 527 sww.store_timestep() 528 529 cellsize = 10 # 10m grid 530 531 532 533 # Export to ascii/prj files 522 534 sww2dem(domain.get_name() + '.sww', 523 535 domain.get_name() + '_elevation.asc', 524 quantity ='elevation',525 cellsize =cellsize,526 number_of_decimal_places =9,527 verbose =self.verbose,536 quantity='elevation', 537 cellsize=cellsize, 538 number_of_decimal_places=9, 539 verbose=self.verbose, 528 540 block_size=2) 529 541 530 542 531 # Check prj (meta data)543 # Check prj (meta data) 532 544 prjid = open(prjfile) 533 545 lines = prjid.readlines() … … 570 582 571 583 572 # Check asc file584 # Check asc file 573 585 ascid = open(ascfile) 574 586 lines = ascid.readlines() … … 599 611 assert L[1].strip().lower() == '-9999' 600 612 601 # Check grid values (FIXME: Use same strategy for other sww2dem tests)613 # Check grid values (FIXME: Use same strategy for other sww2dem tests) 602 614 for i, line in enumerate(lines[6:]): 603 for j, value in enumerate( line.split()):604 assert num.allclose(float(value), -(10 -i+j)*cellsize,615 for j, value in enumerate(line.split()): 616 assert num.allclose(float(value), -(10 - i + j) * cellsize, 605 617 atol=1.0e-12, rtol=1.0e-12) 606 618 607 619 # Note: Equality can be obtained in this case, 608 620 # but it is better to use allclose. 609 # assert float(value) == -(10-i+j)*cellsize610 611 612 # Cleanup613 #os.remove(prjfile)614 #os.remove(ascfile)615 #os.remove(swwfile)621 # assert float(value) == -(10-i+j)*cellsize 622 623 624 # Cleanup 625 os.remove(prjfile) 626 os.remove(ascfile) 627 os.remove(swwfile) 616 628 617 629 … … 631 643 import time, os 632 644 633 # Setup645 # Setup 634 646 635 647 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular_cross 636 648 637 # Create basic mesh (100m x 100m)649 # Create basic mesh (100m x 100m) 638 650 points, vertices, boundary = rectangular_cross(20, 1, 20.0, 1.0) 639 651 640 # Create shallow water domain652 # Create shallow water domain 641 653 domain = Domain(points, vertices, boundary) 642 654 domain.default_order = 1 … … 658 670 659 671 B = Transmissive_boundary(domain) 660 domain.set_boundary( 672 domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B}) 661 673 662 674 … … 667 679 668 680 domain.tight_slope_limiters = 1 669 domain.evolve_to_end(finaltime =0.01)670 sww.store_timestep() 671 672 cellsize = 1.0 # 0.1 grid673 674 675 # Check contents676 # Get NetCDF681 domain.evolve_to_end(finaltime=0.01) 682 sww.store_timestep() 683 684 cellsize = 1.0 # 0.1 grid 685 686 687 # Check contents 688 # Get NetCDF 677 689 678 690 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 686 698 687 699 688 # Export to ascii/prj files689 sww2dem(domain.get_name() +'.sww',700 # Export to ascii/prj files 701 sww2dem(domain.get_name() + '.sww', 690 702 domain.get_name() + '_elevation.asc', 691 quantity ='elevation',692 cellsize =cellsize,693 number_of_decimal_places =9,694 verbose =self.verbose,703 quantity='elevation', 704 cellsize=cellsize, 705 number_of_decimal_places=9, 706 verbose=self.verbose, 695 707 block_size=2) 696 708 697 709 698 # Check prj (meta data)710 # Check prj (meta data) 699 711 prjid = open(prjfile) 700 712 lines = prjid.readlines() … … 738 750 739 751 740 # Check asc file752 # Check asc file 741 753 ascid = open(ascfile) 742 754 lines = ascid.readlines() … … 769 781 assert L[1].strip().lower() == '-9999' 770 782 771 # Check grid values (FIXME: Use same strategy for other sww2dem tests)783 # Check grid values (FIXME: Use same strategy for other sww2dem tests) 772 784 for i, line in enumerate(lines[6:]): 773 for j, value in enumerate( line.split()):774 # print value785 for j, value in enumerate(line.split()): 786 # print value 775 787 assert num.allclose(float(value), 0.0, 776 788 atol=1.0e-12, rtol=1.0e-12) … … 778 790 # Note: Equality can be obtained in this case, 779 791 # but it is better to use allclose. 780 # assert float(value) == -(10-i+j)*cellsize792 # assert float(value) == -(10-i+j)*cellsize 781 793 782 794 … … 784 796 785 797 786 # Cleanup798 # Cleanup 787 799 os.remove(prjfile) 788 800 os.remove(ascfile) … … 824 836 import time, os 825 837 826 # Setup838 # Setup 827 839 828 840 from anuga.abstract_2d_finite_volumes.mesh_factory import rectangular 829 841 830 # Create basic mesh (100m x 100m)842 # Create basic mesh (100m x 100m) 831 843 points, vertices, boundary = rectangular(2, 2, 100, 100) 832 844 833 # Create shallow water domain845 # Create shallow water domain 834 846 domain = Domain(points, vertices, boundary) 835 847 domain.set_flow_algorithm('1_5') … … 847 859 848 860 # 849 domain.set_quantity('elevation', lambda x, y: -x-y)861 domain.set_quantity('elevation', lambda x, y:-x - y) 850 862 domain.set_quantity('stage', 0) 851 863 852 864 B = Transmissive_boundary(domain) 853 domain.set_boundary( 865 domain.set_boundary({'left': B, 'right': B, 'top': B, 'bottom': B}) 854 866 855 867 … … 859 871 sww.store_timestep() 860 872 861 # domain.tight_slope_limiters = 1862 domain.evolve_to_end(finaltime =0.01)863 sww.store_timestep() 864 865 cellsize = 10 # 10m grid866 867 868 # Check contents869 # Get NetCDF873 # domain.tight_slope_limiters = 1 874 domain.evolve_to_end(finaltime=0.01) 875 sww.store_timestep() 876 877 cellsize = 10 # 10m grid 878 879 880 # Check contents 881 # Get NetCDF 870 882 871 883 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 882 894 sww2dem(domain.get_name() + '.sww', 883 895 domain.get_name() + '_elevation.asc', 884 quantity ='elevation',885 cellsize =cellsize,886 number_of_decimal_places =9,887 easting_min =308530,888 easting_max =308570,889 northing_min =6189050,890 northing_max =6189100,891 verbose =self.verbose)896 quantity='elevation', 897 cellsize=cellsize, 898 number_of_decimal_places=9, 899 easting_min=308530, 900 easting_max=308570, 901 northing_min=6189050, 902 northing_max=6189100, 903 verbose=self.verbose) 892 904 893 905 fid.close() … … 935 947 936 948 937 # Check asc file949 # Check asc file 938 950 ascid = open(ascfile) 939 951 lines = ascid.readlines() … … 964 976 assert L[1].strip().lower() == '-9999' 965 977 966 # Check grid values978 # Check grid values 967 979 for i, line in enumerate(lines[6:]): 968 for j, value in enumerate( line.split()):969 # assert float(value) == -(10-i+j)*cellsize970 assert float(value) == -(10 -i+j+3)*cellsize971 972 973 974 # Cleanup980 for j, value in enumerate(line.split()): 981 # assert float(value) == -(10-i+j)*cellsize 982 assert float(value) == -(10 - i + j + 3) * cellsize 983 984 985 986 # Cleanup 975 987 os.remove(prjfile) 976 988 os.remove(ascfile) … … 988 1000 import time, os 989 1001 990 # Setup1002 # Setup 991 1003 self.domain.set_name('datatest') 992 1004 … … 998 1010 self.domain.format = 'sww' 999 1011 self.domain.smooth = True 1000 self.domain.set_quantity('elevation', lambda x, y: -x-y)1001 1002 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1012 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1013 1014 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1003 1015 1004 1016 … … 1007 1019 sww.store_timestep() 1008 1020 1009 # self.domain.tight_slope_limiters = 11010 self.domain.evolve_to_end(finaltime =0.01)1021 # self.domain.tight_slope_limiters = 1 1022 self.domain.evolve_to_end(finaltime=0.01) 1011 1023 sww.store_timestep() 1012 1024 1013 1025 cellsize = 0.25 1014 # Check contents1015 # Get NetCDF1026 # Check contents 1027 # Get NetCDF 1016 1028 1017 1029 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1025 1037 1026 1038 1027 # Export to ascii/prj files1039 # Export to ascii/prj files 1028 1040 sww2dem(self.domain.get_name() + '.sww', 1029 1041 self.domain.get_name() + '_stage.asc', 1030 quantity ='stage',1031 cellsize =cellsize,1032 number_of_decimal_places =9,1033 reduction =min)1034 1035 1036 # Check asc file1042 quantity='stage', 1043 cellsize=cellsize, 1044 number_of_decimal_places=9, 1045 reduction=min) 1046 1047 1048 # Check asc file 1037 1049 ascid = open(ascfile) 1038 1050 lines = ascid.readlines() … … 1064 1076 1065 1077 1066 # Check grid values (where applicable)1078 # Check grid values (where applicable) 1067 1079 for j in range(5): 1068 if j %2 == 0:1069 L = lines[6 +j].strip().split()1070 jj = 4 -j1080 if j % 2 == 0: 1081 L = lines[6 + j].strip().split() 1082 jj = 4 - j 1071 1083 for i in range(5): 1072 if i %2 == 0:1073 index = jj /2 + i/2*31074 val0 = stage[0, index]1075 val1 = stage[1, index]1076 1077 # print i, j, index, ':', L[i], val0, val11084 if i % 2 == 0: 1085 index = jj / 2 + i / 2 * 3 1086 val0 = stage[0, index] 1087 val1 = stage[1, index] 1088 1089 # print i, j, index, ':', L[i], val0, val1 1078 1090 assert num.allclose(float(L[i]), min(val0, val1)) 1079 1091 … … 1081 1093 fid.close() 1082 1094 1083 # Cleanup1095 # Cleanup 1084 1096 os.remove(prjfile) 1085 1097 os.remove(ascfile) … … 1095 1107 import time, os 1096 1108 1097 # Setup1109 # Setup 1098 1110 self.domain.set_name('datatest') 1099 1111 … … 1105 1117 self.domain.format = 'sww' 1106 1118 self.domain.smooth = True 1107 self.domain.set_quantity('elevation', lambda x, y: -x-y)1108 1109 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1119 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1120 1121 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1110 1122 1111 1123 sww = SWW_file(self.domain) … … 1113 1125 sww.store_timestep() 1114 1126 1115 # self.domain.tight_slope_limiters = 11116 self.domain.evolve_to_end(finaltime =0.01)1127 # self.domain.tight_slope_limiters = 1 1128 self.domain.evolve_to_end(finaltime=0.01) 1117 1129 sww.store_timestep() 1118 1130 1119 1131 cellsize = 0.25 1120 # Check contents1121 # Get NetCDF1132 # Check contents 1133 # Get NetCDF 1122 1134 1123 1135 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1130 1142 stage = fid.variables['stage'][:] 1131 1143 1132 # Export to ascii/prj files1144 # Export to ascii/prj files 1133 1145 sww2dem(self.domain.get_name() + '.sww', 1134 1146 self.domain.get_name() + '_stage.asc', 1135 quantity ='stage',1136 cellsize =cellsize,1137 number_of_decimal_places =9,1138 reduction =1,1147 quantity='stage', 1148 cellsize=cellsize, 1149 number_of_decimal_places=9, 1150 reduction=1, 1139 1151 verbose=self.verbose) 1140 1152 1141 1153 1142 # Check asc file1154 # Check asc file 1143 1155 ascid = open(ascfile) 1144 1156 lines = ascid.readlines() … … 1169 1181 assert L[1].strip().lower() == '-9999' 1170 1182 1171 # Check grid values (where applicable)1183 # Check grid values (where applicable) 1172 1184 for j in range(5): 1173 if j %2 == 0:1174 L = lines[6 +j].strip().split()1175 jj = 4 -j1185 if j % 2 == 0: 1186 L = lines[6 + j].strip().split() 1187 jj = 4 - j 1176 1188 for i in range(5): 1177 if i %2 == 0:1178 index = jj /2 + i/2*31189 if i % 2 == 0: 1190 index = jj / 2 + i / 2 * 3 1179 1191 1180 val = stage[1, index]1192 val = stage[1, index] 1181 1193 1182 1194 assert num.allclose(float(L[i]), val) … … 1184 1196 fid.close() 1185 1197 1186 # Cleanup1198 # Cleanup 1187 1199 os.remove(prjfile) 1188 1200 os.remove(ascfile) … … 1199 1211 import time, os 1200 1212 1201 # Setup1213 # Setup 1202 1214 self.domain.set_name('datatest') 1203 1215 … … 1209 1221 self.domain.format = 'sww' 1210 1222 self.domain.smooth = True 1211 self.domain.set_quantity('elevation', lambda x, y: -x-y)1223 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1212 1224 self.domain.set_quantity('stage', 0.0) 1213 1225 1214 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1226 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1215 1227 1216 1228 … … 1219 1231 sww.store_timestep() 1220 1232 1221 # self.domain.tight_slope_limiters = 11222 self.domain.evolve_to_end(finaltime =0.01)1233 # self.domain.tight_slope_limiters = 1 1234 self.domain.evolve_to_end(finaltime=0.01) 1223 1235 sww.store_timestep() 1224 1236 1225 1237 cellsize = 0.25 1226 # Check contents1227 # Get NetCDF1238 # Check contents 1239 # Get NetCDF 1228 1240 1229 1241 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1237 1249 1238 1250 1239 # Export to ascii/prj files1240 sww2dem(self.domain.get_name() +'.sww',1241 name_out ='datatest_depth.asc',1242 quantity ='stage - elevation',1243 cellsize =cellsize,1244 number_of_decimal_places =9,1245 reduction =min,1246 verbose =self.verbose)1247 1248 1249 # Check asc file1251 # Export to ascii/prj files 1252 sww2dem(self.domain.get_name() + '.sww', 1253 name_out='datatest_depth.asc', 1254 quantity='stage - elevation', 1255 cellsize=cellsize, 1256 number_of_decimal_places=9, 1257 reduction=min, 1258 verbose=self.verbose) 1259 1260 1261 # Check asc file 1250 1262 ascid = open(ascfile) 1251 1263 lines = ascid.readlines() … … 1277 1289 1278 1290 1279 # Check grid values (where applicable)1291 # Check grid values (where applicable) 1280 1292 for j in range(5): 1281 if j %2 == 0:1282 L = lines[6 +j].strip().split()1283 jj = 4 -j1293 if j % 2 == 0: 1294 L = lines[6 + j].strip().split() 1295 jj = 4 - j 1284 1296 for i in range(5): 1285 if i %2 == 0:1286 index = jj /2 + i/2*31287 val0 = stage[0, index] - z[index]1288 val1 = stage[1, index] - z[index]1289 1290 # print i, j, index, ':', L[i], val0, val11297 if i % 2 == 0: 1298 index = jj / 2 + i / 2 * 3 1299 val0 = stage[0, index] - z[index] 1300 val1 = stage[1, index] - z[index] 1301 1302 # print i, j, index, ':', L[i], val0, val1 1291 1303 assert num.allclose(float(L[i]), min(val0, val1)) 1292 1304 … … 1294 1306 fid.close() 1295 1307 1296 # Cleanup1308 # Cleanup 1297 1309 os.remove(prjfile) 1298 1310 os.remove(ascfile) … … 1312 1324 import time, os 1313 1325 1314 # Setup mesh not coinciding with rectangle.1315 # This will cause missing values to occur in gridded data1326 # Setup mesh not coinciding with rectangle. 1327 # This will cause missing values to occur in gridded data 1316 1328 1317 1329 … … 1320 1332 [0.0, 0.0], [0.5, 0.0], [1.0, 0.0]] 1321 1333 1322 vertices = [ [4, 1,3], [5,2,4], [1,4,2], [2,0,1]]1323 1324 # Create shallow water domain1334 vertices = [ [4, 1, 3], [5, 2, 4], [1, 4, 2], [2, 0, 1]] 1335 1336 # Create shallow water domain 1325 1337 domain = Domain(points, vertices) 1326 1338 domain.set_flow_algorithm('1_5') 1327 domain.default_order =21328 1329 1330 # Set some field values1331 domain.set_quantity('elevation', lambda x, y: -x-y)1339 domain.default_order = 2 1340 1341 1342 # Set some field values 1343 domain.set_quantity('elevation', lambda x, y:-x - y) 1332 1344 domain.set_quantity('friction', 0.03) 1333 1345 … … 1336 1348 # Boundary conditions 1337 1349 B = Transmissive_boundary(domain) 1338 domain.set_boundary( {'exterior': B})1350 domain.set_boundary({'exterior': B}) 1339 1351 1340 1352 1341 1353 ###################### 1342 # Initial condition - with jumps1354 # Initial condition - with jumps 1343 1355 1344 1356 bed = domain.quantities['elevation'].vertex_values … … 1348 1360 for i in range(stage.shape[0]): 1349 1361 if i % 2 == 0: 1350 stage[i, :] = bed[i,:] + h1362 stage[i, :] = bed[i, :] + h 1351 1363 else: 1352 stage[i, :] = bed[i,:]1364 stage[i, :] = bed[i, :] 1353 1365 1354 1366 domain.set_quantity('stage', stage) … … 1365 1377 domain.smooth = True 1366 1378 1367 domain.geo_reference = Geo_reference(56, 308500,6189000)1379 domain.geo_reference = Geo_reference(56, 308500, 6189000) 1368 1380 1369 1381 sww = SWW_file(domain) … … 1372 1384 1373 1385 cellsize = 0.25 1374 # Check contents1375 # Get NetCDF1386 # Check contents 1387 # Get NetCDF 1376 1388 1377 1389 fid = NetCDFFile(swwfile, netcdf_mode_r) … … 1386 1398 geo_reference = Geo_reference(NetCDFObject=fid) 1387 1399 except AttributeError, e: 1388 geo_reference = Geo_reference(DEFAULT_ZONE, 0,0)1389 1390 # Export to ascii/prj files1391 sww2dem(domain.get_name() +'.sww',1392 domain.get_name() +'_elevation.asc',1393 quantity ='elevation',1394 cellsize =cellsize,1395 number_of_decimal_places =9,1396 verbose =self.verbose)1397 1398 1399 # Check asc file1400 geo_reference = Geo_reference(DEFAULT_ZONE, 0, 0) 1401 1402 # Export to ascii/prj files 1403 sww2dem(domain.get_name() + '.sww', 1404 domain.get_name() + '_elevation.asc', 1405 quantity='elevation', 1406 cellsize=cellsize, 1407 number_of_decimal_places=9, 1408 verbose=self.verbose) 1409 1410 1411 # Check asc file 1400 1412 ascid = open(ascfile) 1401 1413 lines = ascid.readlines() … … 1426 1438 assert L[1].strip().lower() == '-9999' 1427 1439 1428 # Check grid values1440 # Check grid values 1429 1441 for j in range(5): 1430 L = lines[6 +j].strip().split()1442 L = lines[6 + j].strip().split() 1431 1443 assert len(L) == 5 1432 y = (4 -j) * cellsize1444 y = (4 - j) * cellsize 1433 1445 1434 1446 for i in range(5): 1435 # print i1436 if i +j >= 4:1437 assert num.allclose(float(L[i]), -i *cellsize - y)1447 # print i 1448 if i + j >= 4: 1449 assert num.allclose(float(L[i]), -i * cellsize - y) 1438 1450 else: 1439 # Missing values1451 # Missing values 1440 1452 assert num.allclose(float(L[i]), -9999) 1441 1453 … … 1444 1456 fid.close() 1445 1457 1446 # Cleanup1458 # Cleanup 1447 1459 os.remove(prjfile) 1448 1460 os.remove(ascfile) … … 1461 1473 NODATA_value = 1758323 1462 1474 1463 # Setup1475 # Setup 1464 1476 self.domain.set_name('datatest') 1465 1477 self.domain.set_flow_algorithm('1_5') … … 1471 1483 self.domain.format = 'sww' 1472 1484 self.domain.smooth = True 1473 self.domain.set_quantity('elevation', lambda x, y: -x-y)1474 1475 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1485 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1486 1487 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1476 1488 1477 1489 sww = SWW_file(self.domain) … … 1479 1491 sww.store_timestep() 1480 1492 1481 # self.domain.tight_slope_limiters = 11482 self.domain.evolve_to_end(finaltime =0.01)1493 # self.domain.tight_slope_limiters = 1 1494 self.domain.evolve_to_end(finaltime=0.01) 1483 1495 sww.store_timestep() 1484 1496 1485 1497 cellsize = 0.25 1486 # Check contents1487 # Get NetCDF1498 # Check contents 1499 # Get NetCDF 1488 1500 1489 1501 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1497 1509 1498 1510 1499 # Export to ers files1511 # Export to ers files 1500 1512 outname = self.domain.get_name() + '_elevation.ers' 1501 1513 sww2dem(self.domain.get_name() + '.sww', 1502 1514 outname, 1503 quantity ='elevation',1504 cellsize =cellsize,1505 number_of_decimal_places =9,1506 NODATA_value =NODATA_value,1507 verbose =self.verbose)1508 1509 # Check header data1515 quantity='elevation', 1516 cellsize=cellsize, 1517 number_of_decimal_places=9, 1518 NODATA_value=NODATA_value, 1519 verbose=self.verbose) 1520 1521 # Check header data 1510 1522 from anuga.abstract_2d_finite_volumes.ermapper_grids import read_ermapper_header, read_ermapper_data 1511 1523 … … 1518 1530 assert header['xdimension'] == '0.25' 1519 1531 assert header['ydimension'] == '0.25' 1520 assert float(header['eastings']) == 308500.0 #xllcorner1521 assert float(header['northings']) == 6189000.0 #yllcorner1532 assert float(header['eastings']) == 308500.0 # xllcorner 1533 assert float(header['northings']) == 6189000.0 # yllcorner 1522 1534 assert int(header['nroflines']) == 5 1523 1535 assert int(header['nrofcellsperline']) == 5 1524 1536 assert int(header['nullcellvalue']) == NODATA_value 1525 # FIXME - there is more in the header1526 1527 1528 # Check grid data1537 # FIXME - there is more in the header 1538 1539 1540 # Check grid data 1529 1541 grid = read_ermapper_data(self.domain.get_name() + '_elevation') 1530 1542 1531 1543 1532 1544 1533 ref_grid = [-1, -1.25, -1.5,-1.75, -2.0,1534 - 0.75, -1.0, -1.25, -1.5,-1.75,1535 - 0.5, -0.75, -1.0,-1.25, -1.5,1536 - 0.25, -0.5, -0.75, -1.0,-1.25,1537 - 0.0, -0.25, -0.5,-0.75, -1.0]1538 1539 1540 1541 # pprint(grid)1545 ref_grid = [-1, -1.25, -1.5, -1.75, -2.0, 1546 - 0.75, -1.0, -1.25, -1.5, -1.75, 1547 - 0.5, -0.75, -1.0, -1.25, -1.5, 1548 - 0.25, -0.5, -0.75, -1.0, -1.25, 1549 - 0.0, -0.25, -0.5, -0.75, -1.0] 1550 1551 1552 1553 # pprint(grid) 1542 1554 assert num.allclose(grid, ref_grid) 1543 1555 1544 1556 fid.close() 1545 1557 1546 # Cleanup1547 # FIXME the file clean-up doesn't work (eg Permission Denied Error)1548 # Done (Ole) - it was because sww2ers didn't close it's sww file1558 # Cleanup 1559 # FIXME the file clean-up doesn't work (eg Permission Denied Error) 1560 # Done (Ole) - it was because sww2ers didn't close it's sww file 1549 1561 os.remove(sww.filename) 1550 1562 os.remove(self.domain.get_name() + '_elevation') … … 1562 1574 NODATA_value = 1758323 1563 1575 1564 # Setup1576 # Setup 1565 1577 self.domain.set_name('datatest') 1566 1578 … … 1571 1583 self.domain.format = 'sww' 1572 1584 self.domain.smooth = True 1573 self.domain.set_quantity('elevation', lambda x, y: -x-y)1574 1575 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1585 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1586 1587 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1576 1588 1577 1589 sww = SWW_file(self.domain) … … 1579 1591 sww.store_timestep() 1580 1592 1581 # self.domain.tight_slope_limiters = 11582 self.domain.evolve_to_end(finaltime =0.01)1593 # self.domain.tight_slope_limiters = 1 1594 self.domain.evolve_to_end(finaltime=0.01) 1583 1595 sww.store_timestep() 1584 1596 1585 1597 cellsize = 0.25 1586 # Check contents1587 # Get NetCDF1598 # Check contents 1599 # Get NetCDF 1588 1600 1589 1601 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1597 1609 1598 1610 1599 # Export to ers files1611 # Export to ers files 1600 1612 outname = self.domain.get_name() + '_elevation.ers' 1601 1613 sww2dem(self.domain.get_name() + '.sww', 1602 1614 outname, 1603 quantity ='elevation',1604 cellsize =cellsize,1605 number_of_decimal_places =9,1606 NODATA_value =NODATA_value,1607 verbose =self.verbose)1608 1609 # Check header data1615 quantity='elevation', 1616 cellsize=cellsize, 1617 number_of_decimal_places=9, 1618 NODATA_value=NODATA_value, 1619 verbose=self.verbose) 1620 1621 # Check header data 1610 1622 from anuga.abstract_2d_finite_volumes.ermapper_grids import read_ermapper_header, read_ermapper_data 1611 1623 … … 1618 1630 assert header['xdimension'] == '0.25' 1619 1631 assert header['ydimension'] == '0.25' 1620 assert float(header['eastings']) == 308500.0 #xllcorner1621 assert float(header['northings']) == 6189000.0 #yllcorner1632 assert float(header['eastings']) == 308500.0 # xllcorner 1633 assert float(header['northings']) == 6189000.0 # yllcorner 1622 1634 assert int(header['nroflines']) == 5 1623 1635 assert int(header['nrofcellsperline']) == 5 1624 1636 assert int(header['nullcellvalue']) == NODATA_value 1625 # FIXME - there is more in the header1626 1627 1628 # Check grid data1637 # FIXME - there is more in the header 1638 1639 1640 # Check grid data 1629 1641 grid = read_ermapper_data(self.domain.get_name() + '_elevation') 1630 1642 1631 1643 1632 1644 ref_grid = [-1. , -1.08333325, -1.16666663, -1.33333325, -1.5 , 1633 - 0.91666663, -1. , -1.08333325, -1.25 , -1.33333325,1634 - 0.83333331, -0.91666663, -1. , -1.08333325, -1.16666663,1635 - 0.66666663, -0.75 , -0.91666663, -1. , -1.08333325,1636 - 0.5 , -0.66666663, -0.83333331, -0.91666663, -1. ],1637 1638 1639 # pprint(grid)1645 - 0.91666663, -1. , -1.08333325, -1.25 , -1.33333325, 1646 - 0.83333331, -0.91666663, -1. , -1.08333325, -1.16666663, 1647 - 0.66666663, -0.75 , -0.91666663, -1. , -1.08333325, 1648 - 0.5 , -0.66666663, -0.83333331, -0.91666663, -1. ], 1649 1650 1651 # pprint(grid) 1640 1652 1641 1653 assert num.allclose(grid, ref_grid) … … 1643 1655 fid.close() 1644 1656 1645 # Cleanup1646 # FIXME the file clean-up doesn't work (eg Permission Denied Error)1647 # Done (Ole) - it was because sww2ers didn't close it's sww file1657 # Cleanup 1658 # FIXME the file clean-up doesn't work (eg Permission Denied Error) 1659 # Done (Ole) - it was because sww2ers didn't close it's sww file 1648 1660 os.remove(sww.filename) 1649 1661 os.remove(self.domain.get_name() + '_elevation') … … 1658 1670 1659 1671 base_name = 'tegp' 1660 # Setup1661 self.domain.set_name(base_name +'_P0_8')1672 # Setup 1673 self.domain.set_name(base_name + '_P0_8') 1662 1674 swwfile = self.domain.get_name() + '.sww' 1663 1675 … … 1666 1678 self.domain.format = 'sww' 1667 1679 self.domain.smooth = True 1668 self.domain.set_quantity('elevation', lambda x, y: -x-y)1680 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1669 1681 self.domain.set_quantity('stage', 1.0) 1670 1682 1671 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1683 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1672 1684 1673 1685 sww = SWW_file(self.domain) 1674 1686 sww.store_connectivity() 1675 1687 sww.store_timestep() 1676 self.domain.evolve_to_end(finaltime =0.0001)1677 # Setup1678 self.domain.set_name(base_name +'_P1_8')1688 self.domain.evolve_to_end(finaltime=0.0001) 1689 # Setup 1690 self.domain.set_name(base_name + '_P1_8') 1679 1691 swwfile2 = self.domain.get_name() + '.sww' 1680 1692 sww = SWW_file(self.domain) 1681 1693 sww.store_connectivity() 1682 1694 sww.store_timestep() 1683 self.domain.evolve_to_end(finaltime =0.0002)1695 self.domain.evolve_to_end(finaltime=0.0002) 1684 1696 sww.store_timestep() 1685 1697 1686 1698 cellsize = 0.25 1687 # Check contents1688 # Get NetCDF1699 # Check contents 1700 # Get NetCDF 1689 1701 1690 1702 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1699 1711 fid.close() 1700 1712 1701 # Export to ascii/prj files1713 # Export to ascii/prj files 1702 1714 extra_name_out = 'yeah' 1703 1715 sww2dem_batch(base_name, 1704 quantities =['elevation', 'depth'],1705 extra_name_out =extra_name_out,1706 cellsize =cellsize,1707 verbose =self.verbose,1708 format ='asc')1716 quantities=['elevation', 'depth'], 1717 extra_name_out=extra_name_out, 1718 cellsize=cellsize, 1719 verbose=self.verbose, 1720 format='asc') 1709 1721 1710 1722 prjfile = base_name + '_P0_8_elevation_yeah.prj' 1711 1723 ascfile = base_name + '_P0_8_elevation_yeah.asc' 1712 # Check asc file1724 # Check asc file 1713 1725 ascid = open(ascfile) 1714 1726 lines = ascid.readlines() 1715 1727 ascid.close() 1716 # Check grid values1728 # Check grid values 1717 1729 for j in range(5): 1718 L = lines[6 +j].strip().split()1719 y = (4 -j) * cellsize1730 L = lines[6 + j].strip().split() 1731 y = (4 - j) * cellsize 1720 1732 for i in range(5): 1721 # print " -i*cellsize - y", -i*cellsize - y1722 # print "float(L[i])", float(L[i])1723 assert num.allclose(float(L[i]), -i *cellsize - y)1724 # Cleanup1733 # print " -i*cellsize - y", -i*cellsize - y 1734 # print "float(L[i])", float(L[i]) 1735 assert num.allclose(float(L[i]), -i * cellsize - y) 1736 # Cleanup 1725 1737 os.remove(prjfile) 1726 1738 os.remove(ascfile) … … 1728 1740 prjfile = base_name + '_P1_8_elevation_yeah.prj' 1729 1741 ascfile = base_name + '_P1_8_elevation_yeah.asc' 1730 # Check asc file1742 # Check asc file 1731 1743 ascid = open(ascfile) 1732 1744 lines = ascid.readlines() 1733 1745 ascid.close() 1734 # Check grid values1746 # Check grid values 1735 1747 for j in range(5): 1736 L = lines[6 +j].strip().split()1737 y = (4 -j) * cellsize1748 L = lines[6 + j].strip().split() 1749 y = (4 - j) * cellsize 1738 1750 for i in range(5): 1739 # print " -i*cellsize - y", -i*cellsize - y1740 # print "float(L[i])", float(L[i])1741 assert num.allclose(float(L[i]), -i *cellsize - y)1742 # Cleanup1751 # print " -i*cellsize - y", -i*cellsize - y 1752 # print "float(L[i])", float(L[i]) 1753 assert num.allclose(float(L[i]), -i * cellsize - y) 1754 # Cleanup 1743 1755 os.remove(prjfile) 1744 1756 os.remove(ascfile) 1745 1757 os.remove(swwfile) 1746 1758 1747 # Check asc file1759 # Check asc file 1748 1760 ascfile = base_name + '_P0_8_depth_yeah.asc' 1749 1761 prjfile = base_name + '_P0_8_depth_yeah.prj' … … 1751 1763 lines = ascid.readlines() 1752 1764 ascid.close() 1753 # Check grid values1765 # Check grid values 1754 1766 for j in range(5): 1755 L = lines[6 +j].strip().split()1756 y = (4 -j) * cellsize1767 L = lines[6 + j].strip().split() 1768 y = (4 - j) * cellsize 1757 1769 for i in range(5): 1758 assert num.allclose(float(L[i]), 1 - (-i *cellsize - y))1759 # Cleanup1770 assert num.allclose(float(L[i]), 1 - (-i * cellsize - y)) 1771 # Cleanup 1760 1772 os.remove(prjfile) 1761 1773 os.remove(ascfile) 1762 1774 1763 # Check asc file1775 # Check asc file 1764 1776 ascfile = base_name + '_P1_8_depth_yeah.asc' 1765 1777 prjfile = base_name + '_P1_8_depth_yeah.prj' … … 1767 1779 lines = ascid.readlines() 1768 1780 ascid.close() 1769 # Check grid values1781 # Check grid values 1770 1782 for j in range(5): 1771 L = lines[6 +j].strip().split()1772 y = (4 -j) * cellsize1783 L = lines[6 + j].strip().split() 1784 y = (4 - j) * cellsize 1773 1785 for i in range(5): 1774 assert num.allclose(float(L[i]), 1 - (-i *cellsize - y))1775 # Cleanup1786 assert num.allclose(float(L[i]), 1 - (-i * cellsize - y)) 1787 # Cleanup 1776 1788 os.remove(prjfile) 1777 1789 os.remove(ascfile) … … 1793 1805 pass 1794 1806 1795 # Setup1807 # Setup 1796 1808 self.domain.set_name('teg') 1797 1809 … … 1803 1815 self.domain.set_flow_algorithm('1_5') 1804 1816 self.domain.smooth = True 1805 self.domain.set_quantity('elevation', lambda x, y: -x-y)1817 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1806 1818 self.domain.set_quantity('stage', 1.0) 1807 1819 1808 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1820 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1809 1821 1810 1822 sww = SWW_file(self.domain) 1811 1823 sww.store_connectivity() 1812 1824 sww.store_timestep() 1813 self.domain.evolve_to_end(finaltime =0.01)1825 self.domain.evolve_to_end(finaltime=0.01) 1814 1826 sww.store_timestep() 1815 1827 1816 1828 cellsize = 0.25 1817 # Check contents1818 # Get NetCDF1829 # Check contents 1830 # Get NetCDF 1819 1831 1820 1832 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1829 1841 fid.close() 1830 1842 1831 # Export to ascii/prj files1843 # Export to ascii/prj files 1832 1844 sww2dem_batch(self.domain.get_name(), 1833 quantities ='elevation',1834 cellsize =cellsize,1835 verbose =self.verbose,1836 format ='asc')1837 1838 # Check asc file1845 quantities='elevation', 1846 cellsize=cellsize, 1847 verbose=self.verbose, 1848 format='asc') 1849 1850 # Check asc file 1839 1851 ascid = open(ascfile) 1840 1852 lines = ascid.readlines() … … 1849 1861 assert num.allclose(float(L[1].strip().lower()), 6189000) 1850 1862 1851 # Check grid values1852 # print '==='1863 # Check grid values 1864 # print '===' 1853 1865 for j in range(5): 1854 L = lines[6 +j].strip().split()1855 y = (4 -j) * cellsize1866 L = lines[6 + j].strip().split() 1867 y = (4 - j) * cellsize 1856 1868 for i in range(5): 1857 # print float(L[i])1858 assert num.allclose(float(L[i]), -i *cellsize - y)1869 # print float(L[i]) 1870 assert num.allclose(float(L[i]), -i * cellsize - y) 1859 1871 1860 # Cleanup1872 # Cleanup 1861 1873 os.remove(prjfile) 1862 1874 os.remove(ascfile) … … 1877 1889 pass 1878 1890 1879 # Setup1891 # Setup 1880 1892 self.domain.set_name('tegII') 1881 1893 … … 1885 1897 self.domain.set_flow_algorithm('1_5') 1886 1898 self.domain.smooth = True 1887 self.domain.set_quantity('elevation', lambda x, y: -x-y)1899 self.domain.set_quantity('elevation', lambda x, y:-x - y) 1888 1900 self.domain.set_quantity('stage', 1.0) 1889 1901 1890 self.domain.geo_reference = Geo_reference(56, 308500,6189000)1902 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 1891 1903 1892 1904 sww = SWW_file(self.domain) 1893 1905 sww.store_connectivity() 1894 1906 sww.store_timestep() 1895 self.domain.evolve_to_end(finaltime =0.01)1907 self.domain.evolve_to_end(finaltime=0.01) 1896 1908 sww.store_timestep() 1897 1909 1898 1910 cellsize = 0.25 1899 # Check contents1900 # Get NetCDF1911 # Check contents 1912 # Get NetCDF 1901 1913 1902 1914 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 1911 1923 ymomentum = fid.variables['ymomentum'][:] 1912 1924 1913 # print 'stage', stage1914 # print 'xmom', xmomentum1915 # print 'ymom', ymomentum1925 # print 'stage', stage 1926 # print 'xmom', xmomentum 1927 # print 'ymom', ymomentum 1916 1928 1917 1929 fid.close() 1918 1930 1919 # Export to ascii/prj files1931 # Export to ascii/prj files 1920 1932 if True: 1921 1933 sww2dem_batch(self.domain.get_name(), 1922 quantities =['elevation', 'depth'],1923 cellsize =cellsize,1924 verbose =self.verbose,1925 format ='asc')1934 quantities=['elevation', 'depth'], 1935 cellsize=cellsize, 1936 verbose=self.verbose, 1937 format='asc') 1926 1938 1927 1939 else: 1928 1940 sww2dem_batch(self.domain.get_name(), 1929 quantities =['depth'],1930 cellsize =cellsize,1931 verbose =self.verbose,1932 format ='asc')1941 quantities=['depth'], 1942 cellsize=cellsize, 1943 verbose=self.verbose, 1944 format='asc') 1933 1945 1934 1946 1935 1947 export_grid(self.domain.get_name(), 1936 quantities =['elevation'],1937 cellsize =cellsize,1938 verbose =self.verbose,1939 format ='asc')1948 quantities=['elevation'], 1949 cellsize=cellsize, 1950 verbose=self.verbose, 1951 format='asc') 1940 1952 1941 1953 prjfile = self.domain.get_name() + '_elevation.prj' 1942 1954 ascfile = self.domain.get_name() + '_elevation.asc' 1943 1955 1944 # Check asc file1956 # Check asc file 1945 1957 ascid = open(ascfile) 1946 1958 lines = ascid.readlines() … … 1955 1967 assert num.allclose(float(L[1].strip().lower()), 6189000) 1956 1968 1957 # print "ascfile", ascfile1958 # Check grid values1969 # print "ascfile", ascfile 1970 # Check grid values 1959 1971 for j in range(5): 1960 L = lines[6 +j].strip().split()1961 y = (4 -j) * cellsize1972 L = lines[6 + j].strip().split() 1973 y = (4 - j) * cellsize 1962 1974 for i in range(5): 1963 # print " -i*cellsize - y", -i*cellsize - y1964 # print "float(L[i])", float(L[i])1965 assert num.allclose(float(L[i]), -i *cellsize - y)1966 1967 # Cleanup1975 # print " -i*cellsize - y", -i*cellsize - y 1976 # print "float(L[i])", float(L[i]) 1977 assert num.allclose(float(L[i]), -i * cellsize - y) 1978 1979 # Cleanup 1968 1980 os.remove(prjfile) 1969 1981 os.remove(ascfile) 1970 1982 1971 # Check asc file1983 # Check asc file 1972 1984 ascfile = self.domain.get_name() + '_depth.asc' 1973 1985 prjfile = self.domain.get_name() + '_depth.prj' … … 1984 1996 assert num.allclose(float(L[1].strip().lower()), 6189000) 1985 1997 1986 # Check grid values1998 # Check grid values 1987 1999 for j in range(5): 1988 L = lines[6 +j].strip().split()1989 y = (4 -j) * cellsize2000 L = lines[6 + j].strip().split() 2001 y = (4 - j) * cellsize 1990 2002 for i in range(5): 1991 # print " -i*cellsize - y", -i*cellsize - y1992 # print "float(L[i])", float(L[i])1993 assert num.allclose(float(L[i]), 1 - (-i *cellsize - y))1994 1995 # Cleanup2003 # print " -i*cellsize - y", -i*cellsize - y 2004 # print "float(L[i])", float(L[i]) 2005 assert num.allclose(float(L[i]), 1 - (-i * cellsize - y)) 2006 2007 # Cleanup 1996 2008 os.remove(prjfile) 1997 2009 os.remove(ascfile) … … 2013 2025 pass 2014 2026 2015 # Setup2027 # Setup 2016 2028 2017 2029 self.domain.set_name('tegIII') … … 2023 2035 self.domain.format = 'sww' 2024 2036 self.domain.smooth = True 2025 self.domain.set_quantity('elevation', lambda x, y: -x-y)2037 self.domain.set_quantity('elevation', lambda x, y:-x - y) 2026 2038 self.domain.set_quantity('stage', 1.0) 2027 2039 2028 self.domain.geo_reference = Geo_reference(56, 308500,6189000)2040 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 2029 2041 2030 2042 sww = SWW_file(self.domain) 2031 2043 sww.store_connectivity() 2032 sww.store_timestep() #'stage')2033 self.domain.evolve_to_end(finaltime =0.01)2034 sww.store_timestep() #'stage')2044 sww.store_timestep() # 'stage') 2045 self.domain.evolve_to_end(finaltime=0.01) 2046 sww.store_timestep() # 'stage') 2035 2047 2036 2048 cellsize = 0.25 2037 # Check contents2038 # Get NetCDF2049 # Check contents 2050 # Get NetCDF 2039 2051 2040 2052 fid = NetCDFFile(sww.filename, netcdf_mode_r) … … 2049 2061 fid.close() 2050 2062 2051 # Export to ascii/prj files2063 # Export to ascii/prj files 2052 2064 extra_name_out = 'yeah' 2053 2065 if True: 2054 2066 sww2dem_batch(self.domain.get_name(), 2055 quantities =['elevation', 'depth'],2056 extra_name_out =extra_name_out,2057 cellsize =cellsize,2058 verbose =self.verbose,2059 format ='asc')2067 quantities=['elevation', 'depth'], 2068 extra_name_out=extra_name_out, 2069 cellsize=cellsize, 2070 verbose=self.verbose, 2071 format='asc') 2060 2072 2061 2073 else: 2062 2074 sww2dem_batch(self.domain.get_name(), 2063 quantities =['depth'],2064 cellsize =cellsize,2065 verbose =self.verbose,2066 format ='asc')2075 quantities=['depth'], 2076 cellsize=cellsize, 2077 verbose=self.verbose, 2078 format='asc') 2067 2079 2068 2080 2069 2081 sww2dem_batch(self.domain.get_name(), 2070 quantities =['elevation'],2071 cellsize =cellsize,2072 verbose =self.verbose,2073 format ='asc')2082 quantities=['elevation'], 2083 cellsize=cellsize, 2084 verbose=self.verbose, 2085 format='asc') 2074 2086 2075 2087 prjfile = self.domain.get_name() + '_elevation_yeah.prj' 2076 2088 ascfile = self.domain.get_name() + '_elevation_yeah.asc' 2077 2089 2078 # Check asc file2090 # Check asc file 2079 2091 ascid = open(ascfile) 2080 2092 lines = ascid.readlines() … … 2089 2101 assert num.allclose(float(L[1].strip().lower()), 6189000) 2090 2102 2091 # print "ascfile", ascfile2092 # Check grid values2103 # print "ascfile", ascfile 2104 # Check grid values 2093 2105 for j in range(5): 2094 L = lines[6 +j].strip().split()2095 y = (4 -j) * cellsize2106 L = lines[6 + j].strip().split() 2107 y = (4 - j) * cellsize 2096 2108 for i in range(5): 2097 # print " -i*cellsize - y", -i*cellsize - y2098 # print "float(L[i])", float(L[i])2099 assert num.allclose(float(L[i]), -i *cellsize - y)2109 # print " -i*cellsize - y", -i*cellsize - y 2110 # print "float(L[i])", float(L[i]) 2111 assert num.allclose(float(L[i]), -i * cellsize - y) 2100 2112 2101 # Cleanup2113 # Cleanup 2102 2114 os.remove(prjfile) 2103 2115 os.remove(ascfile) 2104 2116 2105 # Check asc file2117 # Check asc file 2106 2118 ascfile = self.domain.get_name() + '_depth_yeah.asc' 2107 2119 prjfile = self.domain.get_name() + '_depth_yeah.prj' … … 2118 2130 assert num.allclose(float(L[1].strip().lower()), 6189000) 2119 2131 2120 # Check grid values2132 # Check grid values 2121 2133 for j in range(5): 2122 L = lines[6 +j].strip().split()2123 y = (4 -j) * cellsize2134 L = lines[6 + j].strip().split() 2135 y = (4 - j) * cellsize 2124 2136 for i in range(5): 2125 assert num.allclose(float(L[i]), 1 - (-i *cellsize - y))2126 2127 # Cleanup2137 assert num.allclose(float(L[i]), 1 - (-i * cellsize - y)) 2138 2139 # Cleanup 2128 2140 os.remove(prjfile) 2129 2141 os.remove(ascfile) … … 2136 2148 try: 2137 2149 sww2dem_batch('a_small_round-egg', 2138 quantities =['elevation', 'depth'],2139 cellsize =99,2140 verbose =self.verbose,2141 format ='asc')2150 quantities=['elevation', 'depth'], 2151 cellsize=99, 2152 verbose=self.verbose, 2153 format='asc') 2142 2154 except IOError: 2143 2155 pass 2144 2156 else: 2145 self.assertTrue(0 ==1, 'Bad input did not throw exception error!') 2157 self.assertTrue(0 == 1, 'Bad input did not throw exception error!') 2158 2159 def test_sww2dem_verbose_True(self): 2160 '''test sww2dem when verbose is True 2161 uses the example from function test_sww2dem_asc_elevation_depth''' 2162 import anuga.utilities.log as log 2163 cwd = os.getcwd() 2164 LOG_FILENAME = cwd + '/log_critical_message.log' 2165 filehandler = log.logging.FileHandler(LOG_FILENAME) 2166 filehandler.setLevel(log.logging.CRITICAL) 2167 log.logging.getLogger('').addHandler(filehandler) 2168 # Setup 2169 self.domain.set_name('datatest') 2170 2171 prjfile = self.domain.get_name() + '_elevation.prj' 2172 ascfile = self.domain.get_name() + '_elevation.asc' 2173 swwfile = self.domain.get_name() + '.sww' 2174 2175 self.domain.set_datadir('.') 2176 self.domain.set_flow_algorithm('1_5') 2177 self.domain.format = 'sww' 2178 self.domain.smooth = True 2179 self.domain.set_quantity('elevation', lambda x, y:-x - y) 2180 self.domain.set_quantity('stage', 1.0) 2181 2182 self.domain.geo_reference = Geo_reference(56, 308500, 6189000) 2183 2184 sww = SWW_file(self.domain) 2185 sww.store_connectivity() 2186 sww.store_timestep() 2187 2188 self.domain.evolve_to_end(finaltime=0.01) 2189 sww.store_timestep() 2190 2191 cellsize = 0.25 2192 2193 with Capturing() as myout: 2194 sww2dem(swwfile, ascfile, 2195 quantity='elevation', 2196 cellsize=cellsize, 2197 number_of_decimal_places=9, 2198 verbose=True) 2199 2200 log_critical_msg = open(LOG_FILENAME) 2201 output = log_critical_msg.read() 2202 log_critical_msg.close() 2203 output = output.split('\n') 2204 #print output, 'log message output' 2205 2206 output_verbose_True = '''Reading from datatest.sww 2207 Output directory is datatest_elevation.asc 2208 ------------------------------------------------ 2209 Statistics of SWW file: 2210 Name: datatest.sww 2211 Reference: 2212 Lower left corner: [308500.000000, 6189000.000000] 2213 Start time: 0.000000 2214 Extent: 2215 x [m] in [0.000000, 1.000000], len(x) == 9 2216 y [m] in [0.000000, 1.000000], len(y) == 9 2217 t [s] in [0.000000, 0.010000], len(t) == 2 2218 Quantities [SI units]: 2219 stage in [1.000000, 1.000000] 2220 xmomentum in [-0.000000, 0.000000] 2221 ymomentum in [-0.000000, 0.000000] 2222 elevation in [-2.000000, 0.000000] 2223 Slicing sww file, num points: 9, block size: 10000 2224 Processed values for elevation are in [-2.000000, 0.000000] 2225 Creating grid 2226 Interpolated values are in [-2.000000, 0.000000] 2227 Writing datatest_elevation.prj 2228 Writing datatest_elevation.asc 2229 Doing row 0 of 5 2230 Doing row 1 of 5 2231 Doing row 2 of 5 2232 Doing row 3 of 5 2233 Doing row 4 of 5''' 2234 2235 output_verbose_True = output_verbose_True.split('\n') 2236 2237 # check the output line by line 2238 for output_verbose_True_line, line in zip(output_verbose_True, output): 2239 assert line.lstrip() == output_verbose_True_line.lstrip() 2240 # cleanup 2241 try: 2242 os.remove(prjfile) 2243 except: 2244 pass 2245 try: 2246 os.remove(ascfile) 2247 except: 2248 pass 2249 try: 2250 os.remove(swwfile) 2251 except: 2252 pass 2253 # os.remove(LOG_FILENAME) 2254 log.logging.disable(log.logging.CRITICAL) 2255 2256 os.remove(LOG_FILENAME) 2257 2146 2258 2147 2259 … … 2149 2261 2150 2262 if __name__ == "__main__": 2151 #suite = unittest.makeSuite(Test_Shallow_Water, 'test_rainfall_forcing_with_evolve') 2263 # suite = unittest.makeSuite(Test_Shallow_Water, 'test_rainfall_forcing_with_evolve') 2264 2265 2152 2266 suite = unittest.makeSuite(Test_Sww2Dem, 'test_') 2153 2267 runner = unittest.TextTestRunner(verbosity=1)
Note: See TracChangeset
for help on using the changeset viewer.