Changeset 6918 for anuga_validation
- Timestamp:
- Apr 28, 2009, 3:09:17 PM (16 years ago)
- Location:
- anuga_validation/automated_validation_tests/patong_beach_validation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_validation/automated_validation_tests/patong_beach_validation/cmpsww.py
r6844 r6918 21 21 ##### 22 22 23 # allowable 'slop' when testing two float values 24 epsilon = 1.0e-9 25 23 26 # Global attributes that should exist and be same in both files 24 27 # Don't have to have all of these, and we don't care about others. 25 28 expect_global_attributes = ['smoothing', 'vertices_are_stored_uniquely', 26 'order', ' revision_number', 'starttime',29 'order', 'starttime', 27 30 'xllcorner', 'yllcorner', 28 31 'zone', 'false_easting', 'false_northing', … … 45 48 'volumes': ('number_of_volumes', 'number of vertices'), 46 49 'time': ('number_of_timesteps',), 47 'stage': ('number s_in_range',),50 'stage': ('number_of_timesteps', 'numbers_of_points',), 48 51 'stage_range': ('numbers_in_range',), 49 52 'xmomentum': ('number_of_timesteps', 'number_of_points'), … … 69 72 # split out the filenames and check they exist 70 73 (file1, file2) = files 74 filename1 = os.path.basename(file1) 75 filename2 = os.path.basename(file2) 76 width = max(len(filename1), len(filename2)) 77 filename1 = filename1.rjust(width) 78 filename2 = filename2.rjust(width) 71 79 72 80 error = False … … 76 84 fid1 = NetCDFFile(file1, netcdf_mode_r) 77 85 except: 78 error_msg += " File '%s' can't be opened?\n" % file186 error_msg += "\nFile '%s' can't be opened?\n" % file1 79 87 error = True 80 88 … … 82 90 fid2 = NetCDFFile(file2, netcdf_mode_r) 83 91 except: 84 error_msg += " File '%s' can't be opened?\n" % file292 error_msg += "\nFile '%s' can't be opened?\n" % file2 85 93 error = True 86 94 fid1.close() … … 88 96 if error: 89 97 raise RuntimeError, error_msg 98 99 if globals is None: 100 globals = expect_global_attributes 90 101 91 102 ##### … … 96 107 for key in expected_dimensions: 97 108 if key not in fid1.dimensions.keys(): 98 error_msg += (" File %s doesn't contain dimension '%s'\n"99 % (file 1, key))109 error_msg += ("\nFile %s doesn't contain dimension '%s'\n" 110 % (filename1, key)) 100 111 error = True 101 112 if key not in fid2.dimensions.keys(): 102 error_msg += (" File %s doesn't contain dimension '%s'\n"103 % (file 2, key))113 error_msg += ("\nFile %s doesn't contain dimension '%s'\n" 114 % (filename2, key)) 104 115 error = True 105 116 … … 109 120 dim1_shape = fid1.dimensions.get(dim, None) 110 121 dim2_shape = fid2.dimensions.get(dim, None) 111 if dim1_shape and dim2_shape and dim1_shape!= dim2_shape:112 error_msg += ( 'File %s has %s dimension of size %s, '113 'file %s has that dimension of size %s\n'114 % (file 1, dim, str(dim1_shape),115 file 2, str(dim2_shape)))122 if dim1_shape != dim2_shape: 123 error_msg += ("\nFile %s has '%s' dimension of size %s,\n" 124 "file %s has that dimension of size %s\n" 125 % (filename1, dim, str(dim1_shape), 126 filename2, str(dim2_shape))) 116 127 error = True 117 128 … … 120 131 for glob in globals: 121 132 if glob not in dir(fid1): 122 error_msg += (" Global attribute '%s' isn't in file %s\n"123 % (glob, file 1))133 error_msg += ("\nGlobal attribute '%s' isn't in file %s\n" 134 % (glob, filename1)) 124 135 error = True 125 136 if glob not in dir(fid2): 126 error_msg += (" Global attribute '%s' isn't in file %s\n"127 % (glob, file 2))137 error_msg += ("\nGlobal attribute '%s' isn't in file %s\n" 138 % (glob, filename2)) 128 139 error = True 129 140 else: … … 139 150 # now check attribute lists are same 140 151 if glob_vars1 != glob_vars2: 141 error_msg = (' Files differ in global attributes:\n'152 error_msg = ('\nFiles differ in global attributes:\n' 142 153 '%s: %s,\n' 143 '%s: %s\n' % (file1, str(glob_vars1), 144 file2, str(glob_vars2))) 145 error = True 146 globals = glob_vars1 154 '%s: %s\n' % (filename1, str(glob_vars1), 155 filename2, str(glob_vars2))) 156 error = True 147 157 148 158 # get variables to test … … 150 160 for var in variables: 151 161 if var not in fid1.variables.keys(): 152 error_msg += (" Variable '%s' isn't in file %s\n"153 % (var, file 1))162 error_msg += ("\nVariable '%s' isn't in file %s\n" 163 % (var, filename1)) 154 164 error = True 155 165 if var not in fid2.variables.keys(): 156 error_msg += (" Variable '%s' isn't in file %s\n"157 % (var, file 2))166 error_msg += ("\nVariable '%s' isn't in file %s\n" 167 % (var, filename2)) 158 168 error = True 159 169 else: … … 168 178 169 179 if var_names1 != var_names2: 170 error_msg += (' Variables are not the same between files:'171 '%s variables= %s, 180 error_msg += ('\nVariables are not the same between files:\n' 181 '%s variables= %s,\n' 172 182 '%s variables = %s\n' 173 % (file 1, str(var_names1), file2, str(var_names2)))183 % (filename1, str(var_names1), filename2, str(var_names2))) 174 184 error = True 175 185 variables = var_names1 176 177 if error:178 fid1.close()179 fid2.close()180 raise RuntimeError, error_msg181 186 182 187 # get size of time dimension … … 184 189 num_timesteps2 = fid2.variables['time'].shape 185 190 if num_timesteps1 != num_timesteps2: 186 error_msg += ('Files have different number of timesteps: %s=%d, %s=%d\n' 187 % (file1, num_timesteps1, file2, num_timesteps2)) 191 error_msg += ('Files have different number of timesteps:\n' 192 '%s=%d,\n' 193 '%s=%d\n' 194 % (filename1, num_timesteps1, filename2, num_timesteps2)) 188 195 error = True 189 190 if error:191 fid1.close()192 fid2.close()193 raise RuntimeError, error_msg194 196 195 197 num_timesteps = num_timesteps1[0] … … 205 207 '%s: %s,\n' 206 208 '%s: %s\n' 207 % (var_name, file1, str(var1_shape), 208 file2, str(var2_shape))) 209 error = True 210 continue 209 % (var_name, filename1, str(var1_shape), 210 filename2, str(var2_shape))) 211 error = True 211 212 212 213 if error: … … 221 222 # check values of global attributes 222 223 for glob_name in globals: 223 g1 = getattr(fid1, glob_name) 224 g2 = getattr(fid2, glob_name) 225 if g1 != g2: 226 error_msg += ("Files differ in global '%s': " 227 "%s: '%s', " 224 if getattr(fid1, glob_name) != getattr(fid2, glob_name): 225 error_msg += ("\nFiles differ in global '%s':\n" 226 "%s: '%s',\n" 228 227 "%s: '%s'\n" 229 % (glob_name, file 1, str(g1), file2, str(g2)))228 % (glob_name, filename1, str(g1), filename2, str(g2))) 230 229 error = True 231 230 … … 235 234 if (len(var_dims) > 1) and (var_dims[0] == 'number_of_timesteps'): 236 235 # time series, check by timestep block 237 for i in xrange(num_timesteps): 238 var1 = num.array(fid1.variables[var_name][i,:]) 239 var2 = num.array(fid2.variables[var_name][i,:]) 240 if not num.allclose(var1, var2): 241 error_msg += ('Files differ in variable %s data:\n' 242 '%s: %s\n' 243 '%s: %s\n' 244 % (glob_name, file1, str(var1), 245 file2, str(var1))) 236 for t in xrange(num_timesteps): 237 var1 = num.array(fid1.variables[var_name][t,:]) 238 var2 = num.array(fid2.variables[var_name][t,:]) 239 if var1 != var2: 240 for i in xrange(len(var1)): 241 if var1[i] != var2[i]: 242 error_msg += ('\nFiles differ in variable ' 243 '%s[%d,%d]:\n' 244 '%s: %.14f\n' 245 '%s: %.14f\n' 246 % (var_name, t, i, 247 filename1, var1[i], 248 filename2, var2[i])) 249 break 246 250 error = True 247 251 else: … … 250 254 var2 = num.array(fid2.variables[var_name][:]) 251 255 if not num.allclose(var1, var2): 252 error_msg += ('Files differ in variable %s:\n'253 '%s: %s,\n'254 '%s: %s\n'255 % (var_name, file1, str(var1),256 file2, str(var2)))257 error = True258 259 if error:260 fid1.close()261 fid2.close()262 raise RuntimeError, error_msg263 264 ##### 265 # All OK, close files and signal EQUAL256 for j in xrange(len(var1)): 257 if abs(var1[j] - var2[j]) > epsilon: 258 error_msg += ('\nFiles differ in variable ' 259 '%s[%d]:\n' 260 '%s: %.14f\n' 261 '%s: %.14f\n' 262 % (var_name, j, 263 filename1, var1[j], 264 filename2, var2[j])) 265 break 266 error = True 267 268 ##### 269 # close files and signal OK or ERROR 266 270 ##### 267 271 268 272 fid1.close() 269 273 fid2.close() 274 275 if error: 276 raise RuntimeError, error_msg 270 277 271 278 return -
anuga_validation/automated_validation_tests/patong_beach_validation/validate.py
r6906 r6918 164 164 (res, auth) = get_remote_from_mirrors(obj_digest, remote_digest, auth, mirrors) 165 165 if res: 166 if not files_same(local_d ata_digest, remote_data_digest):166 if not files_same(local_digest, remote_digest): 167 167 # digests differ, refresh object 168 168 shutil.move(remote_digest, local_digest) … … 270 270 271 271 # modify project.py template 272 log.debug("Creating '%s' version of project.py" % vtype) 272 273 fd = open('project.py.template', 'r') 273 274 project = fd.readlines() … … 286 287 287 288 # run the simulation, produce SWW file 289 log.debug('Running run_model.py') 288 290 cmd = 'python run_model.py > %s' % RUNMODEL_STDOUT 289 291 log.debug("run_simulation: doing '%s'" % cmd) … … 337 339 res = os.system(cmd) 338 340 log.debug("check_that_output_is_as_expected: res=%d" % res) 341 log.critical() 339 342 if res == 0: 340 343 log.info('Simulation results are as expected.') … … 344 347 cmp_error = fd.readlines() 345 348 fd.close() 346 log.critical(' \n' + ''.join(cmp_error))349 log.critical(''.join(cmp_error)) 347 350 348 351 … … 352 355 log.debug('teardown: called') 353 356 354 ## # clear all data objects from local data directory355 ## for data_object in Local_Data_Objects:356 ## obj_path = os.path.join(Local_Data_Directory, data_object)357 ## if os.path.isfile(obj_path):358 ## os.remove(obj_path)359 ## else:360 ## shutil.rmtree(obj_path, ignore_errors=True)361 362 357 # remove remote directory and stdout capture file 363 358 shutil.rmtree(Remote_Data_Directory, ignore_errors=True) … … 375 370 log.console_logging_level = log.INFO 376 371 log.log_logging_level = log.DEBUG 372 log_filename = log.log_filename 373 377 374 setup() 378 375 … … 380 377 381 378 msg = ''' 382 This validation requires a working internet connection to refresh it 's files.379 This validation requires a working internet connection to refresh its files. 383 380 You may still run this validation without an internet connection if you have the 384 381 required files. … … 422 419 # now run what simulations we can and check output is as expected 423 420 for odo in Optional_Data_Objects: 421 start_time = time.time() 424 422 (_, vtype, _) = odo.rsplit('.', 2) 425 423 vtype = vtype.lower() 424 log.critical('#' * 72) 426 425 log.critical("Running Patong '%s' validation ..." % vtype) 427 426 if run_simulation(vtype, odo): … … 430 429 (expected_sww, _) = valid_sww.rsplit('.', 1) 431 430 check_that_output_is_as_expected(expected_sww, valid_sww) 431 shutil.move(log_filename, '%s.%s' % (log_filename, vtype)) 432 stop_time = time.time() 433 log.critical("'%s' validation took %.1fs" % (vtype, stop_time - start_time)) 432 434 433 435 # clean up
Note: See TracChangeset
for help on using the changeset viewer.