Changeset 7149
 Timestamp:
 Jun 3, 2009, 8:06:13 AM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/numpy_anuga_validation/automated_validation_tests/patong_beach_validation/cmpsww.py
r7141 r7149 228 228 ##### 229 229 230 error_msg = '' 231 glob_vars_bad = {} 232 data_vars_bad = {} 233 230 234 # check values of global attributes 231 235 for glob_name in globals: 232 236 if getattr(fid1, glob_name) != getattr(fid2, glob_name): 233 error_msg += ("\nFiles differ in global '%s':\n" 234 "%s: '%s',\n" 235 "%s: '%s'\n" 236 % (glob_name, filename1, str(g1), filename2, str(g2))) 237 print("\nFiles differ in global '%s':\n" 238 "%s: '%s',\n" 239 "%s: '%s'" 240 % (glob_name, filename1, str(g1), filename2, str(g2))) 241 glob_vars_bad[glob_name] = glob_vars_bad.get(glob_name, 0) + 1 237 242 error = True 238 243 239 244 # check data variables, be clever with time series data 240 max_ difference = 1245 max_rel_difference = 1 241 246 diff_count = 0 242 247 for var_name in variables: … … 254 259 rtol=rel_tolerance, 255 260 atol=abs_tolerance): 261 abs_difference = num.abs(var1[i]var2[i]) 262 max_a_b = num.max(num.abs(var1[i]), 263 num.abs(var2[i])) 264 rel_difference = num.abs(abs_difference/max_a_b) 265 256 266 if not quiet: 257 error_msg += ('\nFiles differ in variable ' 258 '%s[%d,%d]:\n' 259 '%s: %f\n' 260 '%s: %f\n' 261 'difference=%e\n' 262 % (var_name, t, i, 263 filename1, var1[i], 264 filename2, var2[i], 265 num.abs(var1[i]var2[i]))) 266 max_difference = max(max_difference, 267 num.abs(var1[i]var2[i])) 267 print('\nFiles differ in variable ' 268 '%s[%d,%d]:\n' 269 '%s: %f\n' 270 '%s: %f\n' 271 'abs. difference=%e, rel. difference=%e\n' 272 % (var_name, t, i, 273 filename1, var1[i], 274 filename2, var2[i], 275 abs_difference, 276 rel_difference)) 277 278 if rel_difference > max_rel_difference: 279 max_rel_difference = rel_difference 280 max_rel_difference_abs = abs_difference 281 max_rel_difference_a = var1[i] 282 max_rel_difference_b = var2[i] 283 284 data_vars_bad[var_name] = data_vars_bad.get(var_name, 0) + 1 268 285 diff_count += 1 269 286 else: … … 276 293 if not num.allclose(var1[j], var2[j], 277 294 rtol=rel_tolerance, atol=abs_tolerance): 295 abs_difference = num.abs(var1[j]var2[j]) 296 max_a_b = num.max(num.abs(var1[j]), 297 num.abs(var2[j])) 298 rel_difference = num.abs(abs_difference/max_a_b) 299 278 300 if not quiet: 279 error_msg += ('\nFiles differ in variable ' 280 '%s[%d]:\n' 281 '%s: %f\n' 282 '%s: %f\n' 283 'difference=%e\n' 284 % (var_name, j, 285 filename1, var1[j], 286 filename2, var2[j], 287 num.abs(var1[j]var2[j]))) 288 max_difference = max(max_difference, 289 num.abs(var1[i]var2[i])) 301 print('\nFiles differ in variable ' 302 '%s[%d]:\n' 303 '%s: %f\n' 304 '%s: %f\n' 305 'abs. difference=%e, rel. difference=%e\n' 306 % (var_name, j, 307 filename1, var1[j], 308 filename2, var2[j], 309 abs_difference, 310 rel_difference)) 311 312 if rel_difference > max_rel_difference: 313 max_rel_difference = rel_difference 314 max_rel_difference_abs = abs_difference 315 max_rel_difference_a = var1[j] 316 max_rel_difference_b = var2[j] 317 318 data_vars_bad[var_name] = data_vars_bad.get(var_name, 0) + 1 290 319 diff_count += 1 291 320 error = True … … 300 329 if error: 301 330 error_msg += ('\nNumber of data differences=%d\n' 302 'Maximum data difference=%e\n' 303 % (diff_count, max_difference)) 331 'Maximum relative data difference=%e\n' 332 'associated absolute difference=%e\n' 333 "associated 'a' value=%e\n" 334 "associated 'b' value=%e\n" 335 % (diff_count, max_rel_difference, max_rel_difference_abs, 336 max_rel_difference_a, max_rel_difference_b)) 337 error_msg += ('\nglob_vars bad=%s\n' % str(glob_vars_bad)) 338 error_msg += ('\ndata_vars bad=%s\n' % str(data_vars_bad)) 304 339 raise RuntimeError, error_msg 305 340
Note: See TracChangeset
for help on using the changeset viewer.