Changeset 7673
- Timestamp:
- Mar 31, 2010, 10:57:09 PM (15 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/gauge.py
r7672 r7673 180 180 verbose=verbose, 181 181 use_cache=use_cache, 182 182 output_centroids = output_centroids) 183 183 184 184 if quake_offset_time is None: … … 190 190 quake_time = time + quake_offset_time 191 191 points_list = [quake_time, quake_time/3600.]# fudge around SWW time bug 192 point_quantities = callable_sww(time,point_i) 193 192 point_quantities = callable_sww(time,point_i) # __call__ is overridden 193 194 194 for quantity in quantities: 195 195 if quantity == NAN: … … 271 271 title_on=None, 272 272 use_cache=False, 273 verbose=False): 273 verbose=False, 274 output_centroids=False): 274 275 """ Read sww file and plot the time series for the 275 276 prescribed quantities at defined gauge locations and … … 388 389 title_on, 389 390 use_cache, 390 verbose) 391 verbose, 392 output_centroids = output_centroids) 391 393 return k 392 394 … … 423 425 title_on = None, 424 426 use_cache = False, 425 verbose = False): 427 verbose = False, 428 output_centroids = False): 426 429 427 430 # FIXME(Ole): Shouldn't print statements here be governed by verbose? … … 486 489 time_thinning = time_thinning, 487 490 verbose = verbose, 488 use_cache = use_cache) 491 use_cache = use_cache, 492 output_centroids = output_centroids) 489 493 490 494 # determine which gauges are contained in sww file -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_gauge.py
r7672 r7673 451 451 452 452 # create a csv file containing our gauge points 453 points = [[2.0,1.0],[ 5.0,5.0]]453 points = [[2.0,1.0],[4.5,4.0]] 454 454 455 455 points_file = tempfile.mktemp(".csv") 456 456 file_id = open(points_file,"w") 457 # These values are where the centroids should be 457 # These values are where the centroids should be 458 458 # file_id.write("name, easting, northing, elevation \n\ 459 #point1, 1.5, 1.5, 3.0\n\460 #point2, 4. 5, 4.5, 9.0\n")459 #point1, 2.0, 2.0, 3.0\n\ 460 #point2, 4.0, 4.0, 9.0\n") 461 461 462 # These values are slightly off the centroids - will it find them?462 # These values are slightly off the centroids - will it find the centroids? 463 463 file_id.write("name, easting, northing, elevation \n\ 464 464 point1, 2.0, 1.0, 3.0\n\ 465 point2, 5.5, 4.0, 9.0\n")465 point2, 4.5, 4.0, 9.0\n") 466 466 467 467 … … 474 474 output_centroids=True) 475 475 476 point1_answers_array = [[0.0,0.0,1.0, 2.5,-1.5,3.0,4.0], [2.0,2.0/3600.,10.0,11.5,-1.5,3.0,4.0]]476 point1_answers_array = [[0.0,0.0,1.0,3.0,-2.0,3.0,4.0], [2.0,2.0/3600.,10.0,12.0,-2.0,3.0,4.0]] 477 477 point1_filename = 'gauge_point1.csv' 478 478 point1_handle = file(point1_filename) … … 482 482 line=[] 483 483 for i,row in enumerate(point1_reader): 484 # print 'i',i,'row',row485 484 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]), 486 485 float(row[4]),float(row[5]),float(row[6])]) … … 488 487 assert num.allclose(line[i], point1_answers_array[i]) 489 488 490 point2_answers_array = [[0.0,0.0,1.0,5. 5,-4.5,3.0,4.0], [2.0,2.0/3600.,10.0,14.5,-4.5,3.0,4.0]]489 point2_answers_array = [[0.0,0.0,1.0,5.0,-4.0,3.0,4.0], [2.0,2.0/3600.,10.0,14.0,-4.0,3.0,4.0]] 491 490 point2_filename = 'gauge_point2.csv' 492 491 point2_handle = file(point2_filename) … … 496 495 line=[] 497 496 for i,row in enumerate(point2_reader): 498 # print 'i',i,'row',row499 497 line.append([float(row[0]),float(row[1]),float(row[2]),float(row[3]), 500 498 float(row[4]),float(row[5]),float(row[6])]) 501 # print 'assert line',line[i],'point1',point1_answers_array[i]499 # print i, 'assert line',line[i],'point2',point2_answers_array[i] 502 500 assert num.allclose(line[i], point2_answers_array[i]) 503 501 -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r7672 r7673 54 54 use_cache=False, 55 55 boundary_polygon=None, 56 56 output_centroids=False): 57 57 """Read time history of spatial data from NetCDF file and return 58 58 a callable object. … … 140 140 'verbose': verbose, 141 141 'boundary_polygon': boundary_polygon, 142 142 'output_centroids': output_centroids} 143 143 144 144 # Call underlying engine with or without caching … … 232 232 verbose=verbose, 233 233 boundary_polygon=boundary_polygon, 234 234 output_centroids=output_centroids) 235 235 else: 236 236 # FIXME (Ole): Could add csv file here to address Ted Rigby's … … 260 260 verbose=False, 261 261 boundary_polygon=None, 262 262 output_centroids=False): 263 263 """Read time history of spatial data from NetCDF sww file and 264 264 return a callable object f(t,x,y) … … 501 501 time_thinning=time_thinning, 502 502 verbose=verbose, 503 gauge_neighbour_id=gauge_neighbour_id), 503 gauge_neighbour_id=gauge_neighbour_id, 504 output_centroids=output_centroids), 504 505 starttime) 505 506 -
anuga_core/source/anuga/fit_interpolate/interpolate.py
r7326 r7673 69 69 start_blocking_len=500000, 70 70 use_cache=False, 71 verbose=False): 71 verbose=False, 72 output_centroids=False): 72 73 """Interpolate vertex_values to interpolation points. 73 74 … … 153 154 result = I.interpolate_block(vertex_values, interpolation_points, 154 155 use_cache=use_cache, 155 verbose=verbose) 156 verbose=verbose, 157 output_centroids=output_centroids) 156 158 157 159 return result … … 228 230 point_coordinates=None, 229 231 start_blocking_len=500000, 230 verbose=False): 232 verbose=False, 233 output_centroids=False): 231 234 """Interpolate mesh data f to determine values, z, at points. 232 235 … … 288 291 self._A_can_be_reused = True 289 292 z = self.interpolate_block(f, point_coordinates, 290 verbose=verbose )293 verbose=verbose, output_centroids=output_centroids) 291 294 else: 292 295 # Handle blocking … … 305 308 start_blocking_len): 306 309 t = self.interpolate_block(f, point_coordinates[start:end], 307 verbose=verbose )310 verbose=verbose, output_centroids=output_centroids) 308 311 z = num.concatenate((z, t), axis=0) #??default# 309 312 start = end … … 311 314 end = len(point_coordinates) 312 315 t = self.interpolate_block(f, point_coordinates[start:end], 313 verbose=verbose )316 verbose=verbose, output_centroids=output_centroids) 314 317 z = num.concatenate((z, t), axis=0) #??default# 315 318 return z … … 317 320 318 321 ## 319 # @brief Control whether blocking occurs or not.320 # @param f ??321 # @param point_coordinates ??322 # @param use_cache ??322 # @brief Interpolate a block of vertices 323 # @param f Array of arbitrary data to be interpolated 324 # @param point_coordinates List of vertices to intersect with the mesh 325 # @param use_cache True if caching should be used to accelerate the calculations 323 326 # @param verbose True if this function is verbose. 324 327 # @return ?? 325 328 def interpolate_block(self, f, point_coordinates, 326 use_cache=False, verbose=False ):329 use_cache=False, verbose=False, output_centroids=False): 327 330 """ 328 331 Call this if you want to control the blocking or make sure blocking … … 354 357 355 358 X = cache(self._build_interpolation_matrix_A, 356 args=(point_coordinates, ),359 args=(point_coordinates, output_centroids), 357 360 kwargs={'verbose': verbose}, 358 361 verbose=verbose) … … 372 375 if reuse_A is False: 373 376 X = self._build_interpolation_matrix_A(point_coordinates, 377 output_centroids, 374 378 verbose=verbose) 375 379 self.interpolation_matrices[key] = (X, point_coordinates) 376 380 else: 377 X = self._build_interpolation_matrix_A(point_coordinates, 381 X = self._build_interpolation_matrix_A(point_coordinates, output_centroids, 378 382 verbose=verbose) 379 383 … … 403 407 404 408 ## 405 # @brief ?? 406 # @param f ?? 409 # @brief Get interpolated data at given points. 410 # Applies a transform to all points to calculate the 411 # interpolated values. Points outside the mesh are returned as NaN. 412 # @note self._A matrix must be valid 413 # @param f Array of arbitrary data 407 414 # @param verbose True if this function is to be verbose. 408 # @return ??415 # @return f transformed by interpolation matrix (f') 409 416 def _get_point_data_z(self, f, verbose=False): 410 417 """ … … 424 431 ## 425 432 # @brief Build NxM interpolation matrix. 426 # @param point_coordinates ?? 433 # @param point_coordinates Points to sample at 434 # @param output_centroids set to True to always sample from the centre 435 # of the intersected triangle, instead of the intersection 436 # point. 427 437 # @param verbose True if this function is to be verbose. 428 # @return ??438 # @return Interpolation matrix A, plus lists of the points inside and outside the mesh. 429 439 def _build_interpolation_matrix_A(self, 430 440 point_coordinates, 441 output_centroids=False, 431 442 verbose=False): 432 443 """Build n x m interpolation matrix, where … … 495 506 j1 = self.mesh.triangles[k,1] # Global vertex id for sigma1 496 507 j2 = self.mesh.triangles[k,2] # Global vertex id for sigma2 497 498 sigmas = {j0:sigma0, j1:sigma1, j2:sigma2} 499 js = [j0, j1, j2] 500 501 for j in js: 502 A[i, j] = sigmas[j] 508 js = [j0, j1, j2] 509 510 if output_centroids is False: 511 # Weight each vertex according to its distance from x 512 sigmas = {j0:sigma0, j1:sigma1, j2:sigma2} 513 for j in js: 514 A[i, j] = sigmas[j] 515 else: 516 # If centroids are needed, weight all 3 vertices equally 517 for j in js: 518 A[i, j] = 1.0/3.0 503 519 else: 504 520 msg = 'Could not find triangle for point', x … … 751 767 time_thinning=1, 752 768 verbose=False, 753 gauge_neighbour_id=None): 769 gauge_neighbour_id=None, 770 output_centroids=False): 754 771 """Initialise object and build spatial interpolation if required 755 772 … … 976 993 point_coordinates=\ 977 994 self.interpolation_points, 978 verbose=False) # No clutter 995 verbose=False, 996 output_centroids=output_centroids) 979 997 elif triangles is None and vertex_coordinates is not None: 980 998 result = interpolate_polyline(Q, … … 1002 1020 1003 1021 ## 1004 # @brief Override object() method.1022 # @brief Evaluate interpolation function 1005 1023 # @param t Model time - must lie within existing timesteps. 1006 1024 # @param point_id Index of one of the preprocessed points. -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r7342 r7673 391 391 assert num.allclose(num.sum(results, axis=1), 1.0) 392 392 393 394 def test_arbitrary_datapoints_return_centroids(self): 395 #Try arbitrary datapoints, making sure they return 396 #an interpolation matrix for the intersected triangle's 397 #centroid. 398 399 a = [1.0, 0.0] 400 b = [0.0, 3.0] 401 c = [4.0,0.0] 402 points = [a, b, c] 403 vertices = [ [1,0,2] ] 404 405 data = [ [1.2, 1.5], [1.123, 1.768], [2.43, 0.44] ] 406 407 interp = Interpolate(points, vertices) 408 409 third = [1.0/3.0, 1.0/3.0, 1.0/3.0] 410 answer = [third, third, third] 411 412 A,_,_ = interp._build_interpolation_matrix_A(data, output_centroids=True) 413 results = A.todense() 414 assert num.allclose(results, answer) 415 416 393 417 def test_arbitrary_datapoints_some_outside(self): 394 418 #Try arbitrary datapoints one outside the triangle.
Note: See TracChangeset
for help on using the changeset viewer.