Changeset 4779
- Timestamp:
- Nov 2, 2007, 5:18:29 PM (17 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r4599 r4779 259 259 260 260 return V 261 261 262 def get_node(self, i, 263 absolute=False): 264 """Return node coordinates. 265 266 The nodes are ordered in an Nx2 array where N is the number of nodes. 267 This is the same format they were provided in the constructor 268 i.e. without any duplication. 269 270 Boolean keyword argument absolute determines whether coordinates 271 are to be made absolute by taking georeference into account 272 Default is False as many parts of ANUGA expects relative coordinates. 273 (To see which, switch to default absolute=True and run tests). 274 """ 275 276 277 V = self.nodes[i,:] 278 if absolute is True: 279 if not self.geo_reference.is_absolute(): 280 V[0] += self.geo_reference.xllcorner 281 V[1] += self.geo_reference.yllcorner 282 283 return V 284 262 285 263 286 -
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r4769 r4779 726 726 727 727 # Call fit_interpolate.fit function 728 args = (coordinates, triangles, points, values) 729 kwargs = {'data_origin': data_georef.get_origin(), 728 #args = (coordinates, triangles, points, values) 729 args = (points, ) 730 kwargs = {'vertex_coordinates': coordinates, 731 'triangles': triangles, 732 'mesh': None, 733 'point_attributes': values, 734 'data_origin': data_georef.get_origin(), 730 735 'mesh_origin': mesh_georef.get_origin(), 731 736 'alpha': alpha, … … 776 781 raise msg 777 782 778 coordinates = self.domain.get_nodes(absolute=True) 779 triangles = self.domain.triangles #FIXME 780 781 vertex_attributes = fit_to_mesh(coordinates, triangles, filename, 783 #coordinates = self.domain.get_nodes(absolute=True) 784 #triangles = self.domain.triangles #FIXME 785 #vertex_attributes = fit_to_mesh(coordinates, triangles, filename, 786 vertex_attributes = fit_to_mesh(filename, 787 mesh = self.domain, 782 788 alpha=alpha, 783 789 attribute_name=attribute_name, -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_general_mesh.py
r4599 r4779 9 9 from Numeric import allclose, array, ones, Float 10 10 from general_mesh import General_mesh 11 from anuga.coordinate_transforms.geo_reference import Geo_reference 11 12 12 13 … … 216 217 assert unique_vertices == [0,2,4,5,6,7] 217 218 218 219 219 def test_get_node(self): 220 """test_get_triangles_and_vertices_per_node - 221 222 Test that tuples of triangle, vertex can be extracted 223 from inverted triangles structure 224 225 """ 226 227 x0 = 314036.58727982 228 y0 = 6224951.2960092 229 geo = Geo_reference(56, x0, y0) 230 231 a = [0.0, 0.0] 232 b = [0.0, 2.0] 233 c = [2.0, 0.0] 234 d = [0.0, 4.0] 235 e = [2.0, 2.0] 236 f = [4.0, 0.0] 237 238 nodes = array([a, b, c, d, e, f]) 239 240 nodes_absolute = geo.get_absolute(nodes) 241 242 #bac, bce, ecf, dbe, daf, dae 243 triangles = array([[1,0,2], [1,2,4], [4,2,5], [3,1,4]]) 244 245 domain = General_mesh(nodes, triangles, 246 geo_reference = geo) 247 node = domain.get_node(2) 248 self.assertEqual(c, node) 249 250 node = domain.get_node(2, absolute=True) 251 self.assertEqual(nodes_absolute[2], node) 252 253 220 254 221 255 #------------------------------------------------------------- 222 256 if __name__ == "__main__": 223 suite = unittest.makeSuite(Test_General_Mesh,'test') 257 suite = unittest.makeSuite(Test_General_Mesh,'test') 258 #suite = unittest.makeSuite(Test_General_Mesh,'test_get_node') 224 259 runner = unittest.TextTestRunner() 225 260 runner.run(suite) -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r4712 r4779 541 541 542 542 #Now try by setting the same values directly 543 vertex_attributes = fit_to_mesh(quantity.domain.get_nodes(), 543 vertex_attributes = fit_to_mesh(data_points, 544 quantity.domain.get_nodes(), 544 545 quantity.domain.triangles, #FIXME 545 data_points, 546 z, 546 point_attributes=z, 547 547 alpha = 0, 548 548 verbose=False) … … 584 584 585 585 #Reference 586 ref = fit_to_mesh(vertex_coordinates, triangles, data_points, z, 586 ref = fit_to_mesh(data_points, vertex_coordinates, triangles, 587 point_attributes=z, 587 588 data_origin = data_georef.get_origin(), 588 589 mesh_origin = mesh_georef.get_origin(), … … 1048 1049 x0 = 314036.58727982 1049 1050 y0 = 6224951.2960092 1051 #x0 = 0.0 1052 #y0 = 0.0 1050 1053 1051 1054 a = [0.0, 0.0] -
anuga_core/source/anuga/fit_interpolate/fit.py
r4663 r4779 27 27 import types 28 28 29 from Numeric import zeros, Float, ArrayType,take 30 29 from Numeric import zeros, Float, ArrayType,take, Int 30 31 from anuga.abstract_2d_finite_volumes.neighbour_mesh import Mesh 31 32 from anuga.caching import cache 32 33 from anuga.geospatial_data.geospatial_data import Geospatial_data, \ … … 49 50 50 51 def __init__(self, 51 vertex_coordinates, 52 triangles, 52 vertex_coordinates=None, 53 triangles=None, 54 mesh=None, 53 55 mesh_origin=None, 54 56 alpha = None, … … 98 100 vertex_coordinates, 99 101 triangles, 102 mesh, 100 103 mesh_origin, 101 104 verbose, … … 434 437 ############################################################################ 435 438 436 def fit_to_mesh(vertex_coordinates, 437 triangles, 438 point_coordinates, # this can also be a points file name 439 def fit_to_mesh(point_coordinates, # this can also be a points file name 440 vertex_coordinates=None, 441 triangles=None, 442 mesh=None, 439 443 point_attributes=None, 440 444 alpha=DEFAULT_ALPHA, … … 450 454 """ 451 455 452 args = (vertex_coordinates, triangles, point_coordinates, ) 453 kwargs = {'point_attributes': point_attributes, 456 args = (point_coordinates, ) 457 kwargs = {'vertex_coordinates': vertex_coordinates, 458 'triangles': triangles, 459 'mesh': mesh, 460 'point_attributes': point_attributes, 454 461 'alpha': alpha, 455 462 'verbose': verbose, … … 480 487 args, kwargs) 481 488 482 def _fit_to_mesh(vertex_coordinates, 483 triangles, 484 point_coordinates, # this can also be a points file name 489 def _fit_to_mesh(point_coordinates, # this can also be a points file name 490 vertex_coordinates=None, 491 triangles=None, 492 mesh=None, 485 493 point_attributes=None, 486 494 alpha=DEFAULT_ALPHA, … … 513 521 alpha: Smoothing parameter. 514 522 515 acceptable overshoot: controls the allowed factor by which fitted values 523 acceptable overshoot: NOT IMPLEMENTED 524 controls the allowed factor by which 525 fitted values 516 526 may exceed the value of input data. The lower limit is defined 517 527 as min(z) - acceptable_overshoot*delta z and upper limit 518 528 as max(z) + acceptable_overshoot*delta z 529 519 530 520 531 mesh_origin: A geo_reference object or 3-tuples consisting of … … 531 542 # Duncan and Ole think that this isn't worth caching. 532 543 # Caching happens at the higher level anyway. 533 interp = Fit(vertex_coordinates, 534 triangles, 544 545 if mesh is None: 546 # Fixme (DSG) Throw errors if triangles or vertex_coordinates 547 # are None 548 549 #Convert input to Numeric arrays 550 triangles = ensure_numeric(triangles, Int) 551 vertex_coordinates = ensure_absolute(vertex_coordinates, 552 geo_reference = mesh_origin) 553 554 if verbose: print 'FitInterpolate: Building mesh' 555 mesh = Mesh(vertex_coordinates, triangles) 556 mesh.check_integrity() 557 558 interp = Fit(mesh=mesh, 535 559 verbose=verbose, 536 mesh_origin=mesh_origin,537 560 alpha=alpha) 538 561 … … 624 647 if verbose: print "points file loaded" 625 648 if verbose: print "fitting to mesh" 626 f = fit_to_mesh(vertex_coordinates, 649 f = fit_to_mesh(point_coordinates, 650 vertex_coordinates, 627 651 triangles, 628 point_coordinates,652 None, 629 653 point_attributes, 630 654 alpha = alpha, -
anuga_core/source/anuga/fit_interpolate/general_fit_interpolate.py
r4739 r4779 44 44 45 45 def __init__(self, 46 vertex_coordinates, 47 triangles, 46 vertex_coordinates=None, 47 triangles=None, 48 mesh=None, 48 49 mesh_origin=None, 49 50 verbose=False, … … 54 55 function values at vertices to function values at data points 55 56 57 Pass in a mesh instance or vertex_coordinates and triangles 58 and optionally mesh_origin 59 56 60 Inputs: 57 61 … … 64 68 triangles: List of 3-tuples (or a Numeric array) of 65 69 integers representing indices of all vertices in the mesh. 70 71 mesh: A mesh instance describing the mesh. 66 72 67 73 mesh_origin: A geo_reference object or 3-tuples consisting of … … 79 85 if max_vertices_per_cell == None: 80 86 max_vertices_per_cell = MAX_VERTICES_PER_CELL 81 82 #Convert input to Numeric arrays83 triangles = ensure_numeric(triangles, Int)84 vertex_coordinates = ensure_absolute(vertex_coordinates,85 geo_reference = mesh_origin)86 87 87 #Don't pass geo_reference to mesh. It doesn't work. (Still??) 88 89 if verbose: print 'FitInterpolate: Building mesh' 90 self.mesh = Mesh(vertex_coordinates, triangles) 91 self.mesh.check_integrity() 88 if mesh is None: 89 # Fixme (DSG) Throw errors if triangles or vertex_coordinates 90 # are None 91 92 #Convert input to Numeric arrays 93 triangles = ensure_numeric(triangles, Int) 94 vertex_coordinates = ensure_absolute(vertex_coordinates, 95 geo_reference = mesh_origin) 96 97 if verbose: print 'FitInterpolate: Building mesh' 98 self.mesh = Mesh(vertex_coordinates, triangles) 99 self.mesh.check_integrity() 100 else: 101 self.mesh = mesh 92 102 93 103 if verbose: print 'FitInterpolate: Building quad tree' -
anuga_core/source/anuga/fit_interpolate/interpolate.py
r4663 r4779 84 84 85 85 FitInterpolate.__init__(self, 86 vertex_coordinates ,87 triangles ,88 mesh_origin ,89 verbose ,90 max_vertices_per_cell )86 vertex_coordinates=vertex_coordinates, 87 triangles=triangles, 88 mesh_origin=mesh_origin, 89 verbose=verbose, 90 max_vertices_per_cell=max_vertices_per_cell) 91 91 92 92 # FIXME: What is a good start_blocking_len value? -
anuga_core/source/anuga/fit_interpolate/test_fit.py
r4659 r4779 270 270 points = [a, b, c] 271 271 elements = [[0,2,1]] 272 f = fit_to_mesh( points, elements, txt_file,272 f = fit_to_mesh(txt_file, points, elements, 273 273 alpha=0.0, max_read_lines=2) 274 274 answer = linear_function(points) … … 312 312 points = geo.get_data_points(absolute=True) 313 313 atts = geo.get_attributes() 314 f = fit_to_mesh( vertices, triangles,points,atts,314 f = fit_to_mesh(points,atts, vertices, triangles, 315 315 alpha=0.0, max_read_lines=2, 316 316 use_cache=True, verbose=True) … … 352 352 fileName_pts = tempfile.mktemp(".pts") 353 353 geo.export_points_file(fileName_pts) 354 f = fit_to_mesh(vertices, triangles,fileName_pts, 354 f = fit_to_mesh(fileName_pts, vertices, triangles, 355 alpha=0.0, max_read_lines=2) 356 answer = linear_function(vertices) 357 #print "f\n",f 358 #print "answer\n",answer 359 assert allclose(f, answer) 360 os.remove(fileName) 361 os.remove(fileName_pts) 362 363 def test_fit_to_mesh_pts_passing_mesh_in(self): 364 a = [-1.0, 0.0] 365 b = [3.0, 4.0] 366 c = [4.0,1.0] 367 d = [-3.0, 2.0] #3 368 e = [-1.0,-2.0] 369 f = [1.0, -2.0] #5 370 371 vertices = [a, b, c, d,e,f] 372 triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc 373 374 375 fileName = tempfile.mktemp(".txt") 376 file = open(fileName,"w") 377 file.write(" x, y, elevation \n\ 378 -2.0, 2.0, 0.\n\ 379 -1.0, 1.0, 0.\n\ 380 0.0, 2.0 , 2.\n\ 381 1.0, 1.0 , 2.\n\ 382 2.0, 1.0 ,3. \n\ 383 0.0, 0.0 , 0.\n\ 384 1.0, 0.0 , 1.\n\ 385 0.0, -1.0, -1.\n\ 386 -0.2, -0.5, -0.7\n\ 387 -0.9, -1.5, -2.4\n\ 388 0.5, -1.9, -1.4\n\ 389 3.0, 1.0 , 4.\n") 390 file.close() 391 geo = Geospatial_data(fileName) 392 fileName_pts = tempfile.mktemp(".pts") 393 geo.export_points_file(fileName_pts) 394 f = fit_to_mesh(fileName_pts, vertices, triangles, 355 395 alpha=0.0, max_read_lines=2) 356 396 answer = linear_function(vertices) … … 391 431 file.close() 392 432 393 f = fit_to_mesh( vertices, triangles,fileName,433 f = fit_to_mesh(fileName, vertices, triangles, 394 434 alpha=0.0, max_read_lines=2) 395 435 #use_cache=True, verbose=True) … … 432 472 file.close() 433 473 434 f = fit_to_mesh( vertices, triangles,fileName,474 f = fit_to_mesh(fileName, vertices, triangles, 435 475 alpha=0.0, 436 476 attribute_name='elevation', max_read_lines=2) … … 686 726 z = [z1, z2, z3] 687 727 688 f = fit_to_mesh(points, triangles, data_coords, z, alpha=0.0) 728 f = fit_to_mesh(data_coords, vertex_coordinates=points, 729 triangles=triangles, 730 point_attributes=z, alpha=0.0) 689 731 answer = [[0, 0], [5., 10.], [5., 10.]] 690 732 … … 720 762 721 763 #Fit 722 zz = fit_to_mesh(vertex_coordinates, triangles, data_points, z, 764 zz = fit_to_mesh(data_points, vertex_coordinates=vertex_coordinates, 765 triangles=triangles, 766 point_attributes=z, 723 767 data_origin = data_geo.get_origin(), 724 768 mesh_origin = mesh_geo.get_origin(), … … 1052 1096 if __name__ == "__main__": 1053 1097 suite = unittest.makeSuite(Test_Fit,'test') 1054 #suite = unittest.makeSuite(Test_Fit,' cache_test_fit_to_mesh_pts')1098 #suite = unittest.makeSuite(Test_Fit,'test_fit_to_mesh_pts_passing_mesh_in') 1055 1099 #suite = unittest.makeSuite(Test_Fit,'') 1056 1100 runner = unittest.TextTestRunner(verbosity=1) -
anuga_core/source/anuga/fit_interpolate/test_interpolate.py
r4739 r4779 14 14 15 15 from Scientific.IO.NetCDF import NetCDFFile 16 from Numeric import allclose, array, transpose, zeros, Float, sometrue, alltrue, take, where 16 from Numeric import allclose, array, transpose, zeros, Float, sometrue, \ 17 alltrue, take, where 17 18 18 19 -
anuga_core/source/anuga/utilities/quad.py
r4739 r4779 142 142 if len(args) == 2: 143 143 point_id = int(args[1]) 144 x, y = self.mesh.get_node s()[point_id]144 x, y = self.mesh.get_node(point_id, absolute=True) 145 145 146 146 #print point_id, x, y … … 183 183 self.store(point) 184 184 else: 185 x = self.mesh.coordinates[point][0] 186 y = self.mesh.coordinates[point][1] 187 print "(" + str(x) + "," + str(y) + ")" 185 # Have to take into account of georef. 186 #x = self.mesh.coordinates[point][0] 187 #y = self.mesh.coordinates[point][1] 188 node = self.mesh.get_node(point, absolute=True) 189 print "node", node 190 print "(" + str(node[0]) + "," + str(node[1]) + ")" 188 191 raise 'point not in region: %s' %str(point) 189 192 … … 229 232 if not triangles.has_key(k): 230 233 # print 'k',k 231 tri = self.mesh.get_vertex_coordinates(k) 234 tri = self.mesh.get_vertex_coordinates(k, 235 absolute=True) 232 236 n0 = self.mesh.get_normal(k, 0) 233 237 n1 = self.mesh.get_normal(k, 1) … … 441 445 #print mesh.coordinates 442 446 443 nodes = mesh.get_nodes() 447 448 nodes = mesh.get_nodes(absolute=True) 444 449 xmin = min(nodes[:,0]) 445 450 xmax = max(nodes[:,0]) … … 447 452 ymax = max(nodes[:,1]) 448 453 454 # Don't know why this didn't work 455 #xmin, xmax, ymin, ymax = mesh.get_extent(absolute=True) 449 456 450 457 # Ensure boundary points are fully contained in region
Note: See TracChangeset
for help on using the changeset viewer.