Changeset 7685
- Timestamp:
- Apr 14, 2010, 6:53:12 PM (13 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/gauge.py
r7679 r7685 92 92 import string 93 93 from anuga.shallow_water.data_manager import get_all_swwfiles 94 from anuga.abstract_2d_finite_volumes.util import file_function 94 from anuga.abstract_2d_finite_volumes.util import file_function 95 95 96 96 assert type(gauge_file) == type(''), 'Gauge filename must be a string' … … 246 246 if quantity == 'ycentroid': 247 247 points_list.append(callable_sww.centroids[point_i][1]) 248 248 249 249 points_writer[point_i].writerow(points_list) 250 250 … … 281 281 use_cache=False, 282 282 verbose=False, 283 283 output_centroids=False): 284 284 """ Read sww file and plot the time series for the 285 285 prescribed quantities at defined gauge locations and … … 399 399 use_cache, 400 400 verbose, 401 401 output_centroids = output_centroids) 402 402 return k 403 403 … … 435 435 use_cache = False, 436 436 verbose = False, 437 437 output_centroids = False): 438 438 439 439 # FIXME(Ole): Shouldn't print statements here be governed by verbose? … … 499 499 verbose = verbose, 500 500 use_cache = use_cache, 501 501 output_centroids = output_centroids) 502 502 503 503 # determine which gauges are contained in sww file -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_gauge.py
r7679 r7685 389 389 os.remove(point1_filename) 390 390 os.remove(point2_filename) 391 391 392 392 393 393 def test_sww2csv_centroid(self): … … 399 399 400 400 Test the ability to get a timeseries at the centroid of a triangle, rather 401 401 than the given gauge point. 402 402 """ 403 403 … … 453 453 points_file = tempfile.mktemp(".csv") 454 454 file_id = open(points_file,"w") 455 # These values are where the centroids should be 455 # These values are where the centroids should be 456 456 # file_id.write("name, easting, northing, elevation \n\ 457 457 #point1, 2.0, 2.0, 3.0\n\ … … 501 501 point1_handle.close() 502 502 point2_handle.close() 503 os.remove(mesh_file) 503 os.remove(mesh_file) 504 504 os.remove(sww.filename) 505 505 os.remove(points_file) … … 516 516 517 517 Test the ability to get a timeseries at the centroid of a triangle, rather 518 518 than the given gauge point, then output the results. 519 519 """ 520 520 … … 596 596 # clean up 597 597 point1_handle.close() 598 os.remove(mesh_file) 598 os.remove(mesh_file) 599 599 os.remove(sww.filename) 600 600 os.remove(points_file) 601 601 os.remove(point1_filename) 602 603 602 603 604 604 605 605 #------------------------------------------------------------- -
anuga_core/source/anuga/abstract_2d_finite_volumes/util.py
r7679 r7685 158 158 """Temporary Interface to new location""" 159 159 160 import anuga.utilities.numerical_tools as NT 160 import anuga.utilities.numerical_tools as NT 161 161 162 162 msg = 'angle has moved from util.py. ' … … 187 187 warn(msg, DeprecationWarning) 188 188 189 return utilities.polygon.point_on_line(*args, **kwargs) 189 return utilities.polygon.point_on_line(*args, **kwargs) 190 190 191 191 … … 211 211 return utilities.polygon.outside_polygon(*args, **kwargs) 212 212 213 214 # @note TEMP 215 def separate_points_by_polygon(*args, **kwargs): 216 """Temporary Interface to new location""" 217 218 log.critical('separate_points_by_polygon has moved from util.py.') 219 log.critical('Please use "from anuga.utilities.polygon import ' 220 'separate_points_by_polygon"') 221 222 return utilities.polygon.separate_points_by_polygon(*args, **kwargs) 223 224 213 225 214 # @note TEMP 226 215 def read_polygon(*args, **kwargs): … … 947 936 # verts=num.take(verts,X,axis=0) to Remove the loners from verts 948 937 # but I think it would use more memory 949 new_i = lone_start 938 new_i = lone_start # point at first loner - 'shuffle down' target 950 939 for i in range(lone_start, N): 951 if loners[i] >= N: 940 if loners[i] >= N: # [i] is a loner, leave alone 952 941 pass 953 else: 942 else: # a non-loner, move down 954 943 loners[i] = new_i 955 944 verts[new_i] = verts[i] … … 1575 1564 """ 1576 1565 from gauge import sww2csv_gauges as sww2csv 1577 1566 1578 1567 return sww2csv(sww_file, gauge_file, out_name, quantities, verbose, use_cache) 1579 1568 1580 1569 def sww2timeseries(swwfiles, 1581 1570 gauge_filename, … … 1610 1599 use_cache, 1611 1600 verbose, 1612 output_centroids) 1613 1601 output_centroids) 1602 1614 1603 ## 1615 1604 # @brief Get a wave height at a certain depth given wave height at another depth. -
anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py
r7317 r7685 27 27 from anuga.utilities.cg_solve import conjugate_gradient, VectorShapeError 28 28 from anuga.utilities.numerical_tools import ensure_numeric 29 from anuga.utilities.polygon import in_and_outside_polygon30 29 from anuga.utilities.quad import build_quadtree 31 30 -
anuga_core/source/anuga/fit_interpolate/interpolate.py
r7682 r7685 155 155 use_cache=use_cache, 156 156 verbose=verbose, 157 157 output_centroids=output_centroids) 158 158 159 159 return result … … 230 230 start_blocking_len=500000, 231 231 verbose=False, 232 232 output_centroids=False): 233 233 """Interpolate mesh data f to determine values, z, at points. 234 234 … … 324 324 # @param use_cache True if caching should be used to accelerate the calculations 325 325 # @param verbose True if this function is verbose. 326 # @return ??326 # @return interpolated f 327 327 def interpolate_block(self, f, point_coordinates, 328 328 use_cache=False, verbose=False, output_centroids=False): … … 407 407 ## 408 408 # @brief Get interpolated data at given points. 409 410 411 409 # Applies a transform to all points to calculate the 410 # interpolated values. Points outside the mesh are returned as NaN. 411 # @note self._A matrix must be valid 412 412 # @param f Array of arbitrary data 413 413 # @param verbose True if this function is to be verbose. … … 431 431 # @brief Build NxM interpolation matrix. 432 432 # @param point_coordinates Points to sample at 433 434 435 433 # @param output_centroids set to True to always sample from the centre 434 # of the intersected triangle, instead of the intersection 435 # point. 436 436 # @param verbose True if this function is to be verbose. 437 437 # @return Interpolation matrix A, plus lists of the points inside and outside the mesh 438 438 # and the list of centroids, if requested. 439 439 def _build_interpolation_matrix_A(self, 440 440 point_coordinates, … … 464 464 if verbose: log.critical('Getting indices inside mesh boundary') 465 465 466 inside_poly_indices, outside_poly_indices = \ 466 # Quick test against boundary, but will not deal with holes in the mesh 467 inside_boundary_indices, outside_poly_indices = \ 467 468 in_and_outside_polygon(point_coordinates, 468 469 self.mesh.get_boundary_polygon(), … … 474 475 475 476 # Since you can block, throw a warning, not an error. 476 if verbose and 0 == len(inside_ poly_indices):477 if verbose and 0 == len(inside_boundary_indices): 477 478 log.critical('WARNING: No points within the mesh!') 478 479 … … 485 486 A = Sparse(n,m) 486 487 487 n = len(inside_ poly_indices)488 n = len(inside_boundary_indices) 488 489 489 490 centroids = [] 490 491 492 inside_poly_indices = [] 493 491 494 # Compute matrix elements for points inside the mesh 492 495 if verbose: log.critical('Building interpolation matrix from %d points' 493 496 % n) 494 497 495 for d, i in enumerate(inside_ poly_indices):498 for d, i in enumerate(inside_boundary_indices): 496 499 # For each data_coordinate point 497 500 if verbose and d%((n+10)/10)==0: log.critical('Doing %d of %d' … … 501 504 element_found, sigma0, sigma1, sigma2, k = \ 502 505 search_tree_of_vertices(self.root, x) 506 507 # Update interpolation matrix A if necessary 508 if element_found is True: 509 510 if verbose: 511 print 'Point is within mesh:', d, i 503 512 504 # Update interpolation matrix A if necessary 505 if element_found is True:513 inside_poly_indices.append(i) 514 506 515 # Assign values to matrix A 507 516 j0 = self.mesh.triangles[k,0] # Global vertex id for sigma0 … … 509 518 j2 = self.mesh.triangles[k,2] # Global vertex id for sigma2 510 519 js = [j0, j1, j2] 511 520 512 521 if output_centroids is False: 513 522 # Weight each vertex according to its distance from x … … 516 525 A[i, j] = sigmas[j] 517 526 else: 518 527 # If centroids are needed, weight all 3 vertices equally 519 528 for j in js: 520 529 A[i, j] = 1.0/3.0 521 centroids.append(self.mesh.centroid_coordinates[k]) 530 centroids.append(self.mesh.centroid_coordinates[k]) 522 531 else: 523 # Mesh has a hole - move this point to the outside list524 # num.delete(inside_poly_indices,[i], axis=0)525 num.append(outside_poly_indices, [i], axis=0) 526 # msg = 'Could not find triangle for point', x 527 # raise Exception(msg)532 if verbose: 533 log.critical('Mesh has a hole - moving this point to outside list') 534 535 # This is a numpy arrays, so we need to do a slow transfer 536 outside_poly_indices = num.append(outside_poly_indices, [i], axis=0) 528 537 529 538 return A, inside_poly_indices, outside_poly_indices, centroids … … 775 784 verbose=False, 776 785 gauge_neighbour_id=None, 777 786 output_centroids=False): 778 787 """Initialise object and build spatial interpolation if required 779 788 … … 1003 1012 verbose=False, 1004 1013 output_centroids=output_centroids) 1005 self.centroids = interpol.centroids 1014 self.centroids = interpol.centroids 1006 1015 elif triangles is None and vertex_coordinates is not None: 1007 1016 result = interpolate_polyline(Q, … … 1012 1021 1013 1022 #assert len(result), len(interpolation_points) 1014 self.precomputed_values[name][i, :] = result 1015 1023 self.precomputed_values[name][i, :] = result 1024 1016 1025 # Report 1017 1026 if verbose: 1018 log.critical(self.statistics()) 1027 log.critical(self.statistics()) 1019 1028 else: 1020 1029 # Store quantitites as is -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r7675 r7685 107 107 assert num.allclose(A.todense(), [[1./3, 1./3, 1./3]]) 108 108 109 109 def test_datapoint_in_hole(self): 110 # create 3 right-angled triangles arranged in a bigger triangle 111 a = [0.0, 0.0] #0 112 b = [0.0, 2.0] #1 113 c = [2.0,0.0] #2 114 d = [0.0,4.0] #3 115 e = [2.0,2.0] #4 116 f = [4.0,0.0] #5 117 points = [a, b, c, d, e, f] 118 vertices = [ [1,0,2], [3,1,4], [4,2,5] ] #bac dbe ecf 119 120 point_in_hole = [1.5, 1.5] # a point in the hole 121 data = [ [20, 20], [0.3, 0.3], point_in_hole, [2.5, 0.3], [30, 30] ] #some points inside and outside the hole 122 123 # any function for the vertices, we don't care about the result 124 f = num.array([linear_function(points), 2*linear_function(points)]) 125 f = num.transpose(f) 126 127 interp = Interpolate(points, vertices) 128 interp.interpolate(f, data) 129 130 assert not set(interp.inside_poly_indices).intersection(set(interp.outside_poly_indices)), \ 131 'Some points are in both lists!' 132 assert len(interp.inside_poly_indices) == 2 133 assert len(interp.outside_poly_indices) == 3 134 135 interp.outside_poly_indices.sort() 136 assert interp.outside_poly_indices[1] == 2, \ 137 'third outside point should be inside the hole!' 110 138 111 139 def test_simple_interpolation_example(self): … … 391 419 assert num.allclose(num.sum(results, axis=1), 1.0) 392 420 393 421 394 422 def test_arbitrary_datapoints_return_centroids(self): 395 423 #Try arbitrary datapoints, making sure they return … … 409 437 third = [1.0/3.0, 1.0/3.0, 1.0/3.0] 410 438 answer = [third, third, third] 411 439 412 440 A,_,_,_ = interp._build_interpolation_matrix_A(data, output_centroids=True) 413 441 results = A.todense() 414 assert num.allclose(results, answer) 415 416 442 assert num.allclose(results, answer) 443 444 417 445 def test_arbitrary_datapoints_some_outside(self): 418 446 #Try arbitrary datapoints one outside the triangle. -
anuga_core/source/anuga/shallow_water/data_manager.py
r7641 r7685 2258 2258 import types 2259 2259 2260 from anuga.utilities.polygon import inside_polygon, outside_polygon, \ 2261 separate_points_by_polygon 2260 from anuga.utilities.polygon import inside_polygon, outside_polygon 2262 2261 from anuga.abstract_2d_finite_volumes.util import \ 2263 2262 apply_expression_to_dictionary … … 2690 2689 2691 2690 import sys 2692 from anuga.utilities.polygon import inside_polygon, outside_polygon, \ 2693 separate_points_by_polygon 2691 from anuga.utilities.polygon import inside_polygon, outside_polygon 2694 2692 from anuga.abstract_2d_finite_volumes.util import \ 2695 2693 apply_expression_to_dictionary -
anuga_core/source/anuga/shallow_water/data_manager_joaquims_patch.py
r7340 r7685 1847 1847 from Numeric import array2string 1848 1848 1849 from anuga.utilities.polygon import inside_polygon, outside_polygon, \ 1850 separate_points_by_polygon 1849 from anuga.utilities.polygon import inside_polygon, outside_polygon 1851 1850 from anuga.abstract_2d_finite_volumes.util import \ 1852 1851 apply_expression_to_dictionary … … 2232 2231 from Numeric import array2string 2233 2232 2234 from anuga.utilities.polygon import inside_polygon, outside_polygon , separate_points_by_polygon2233 from anuga.utilities.polygon import inside_polygon, outside_polygon 2235 2234 from anuga.abstract_2d_finite_volumes.util import apply_expression_to_dictionary 2236 2235
Note: See TracChangeset
for help on using the changeset viewer.