Changeset 4130
- Timestamp:
- Jan 5, 2007, 2:14:16 PM (18 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r4129 r4130 17 17 from Numeric import array, zeros, Float, less, concatenate, NewAxis,\ 18 18 argmax, allclose, take, reshape 19 19 20 from anuga.utilities.numerical_tools import ensure_numeric, is_scalar 20 21 from anuga.geospatial_data.geospatial_data import Geospatial_data 22 from anuga.fit_interpolate.fit import fit_to_mesh 21 23 22 24 class Quantity: … … 655 657 656 658 657 from anuga.fit_interpolate.fit import fit_to_mesh658 659 from anuga.coordinate_transforms.geo_reference import Geo_reference 659 660 … … 727 728 """ 728 729 729 from load_mesh.loadASCII import import_points_file730 from anuga.geospatial_data.geospatial_data import\731 points_dictionary2geospatial_data732 733 730 from types import StringType 734 731 msg = 'Filename must be a text string' 735 732 assert type(filename) == StringType, msg 736 733 737 geospatial_data = Geospatial_data(filename) 734 735 if location != 'vertices': 736 msg = 'set_values_from_points is only defined for '+\ 737 'location=\'vertices\'' 738 raise ms 739 740 coordinates = self.domain.get_nodes(absolute=True) 741 triangles = self.domain.triangles #FIXME 742 738 743 739 self.set_values_from_geospatial_data(geospatial_data, 740 alpha, 741 location, indices, 742 verbose = verbose, 743 use_cache = use_cache) 744 # FIXME handle attribute name 745 vertex_attributes = fit_to_mesh(coordinates, triangles,filename, 746 alpha=alpha) #, max_read_lines=max_read_lines) 747 748 #Call underlying method using array values 749 self.set_values_from_array(vertex_attributes, 750 location, indices, verbose) 751 752 #geospatial_data = Geospatial_data(filename) 753 754 #self.set_values_from_geospatial_data(geospatial_data, 755 # alpha, 756 # location, indices, 757 # verbose = verbose, 758 # use_cache = use_cache) 744 759 745 760 -
anuga_core/source/anuga/abstract_2d_finite_volumes/test_quantity.py
r3956 r4130 3 3 import unittest 4 4 from math import sqrt, pi 5 5 import tempfile 6 6 7 7 from quantity import * … … 499 499 [ 3.0, 1.0]] 500 500 501 z = linear_function(data_points) 502 503 504 #Create pts file 505 from load_mesh.loadASCII import export_points_file 506 ptsfile = 'testptsfile.pts' 501 data_geo_spatial = Geospatial_data(data_points, 502 geo_reference = Geo_reference(56, 0, 0)) 503 data_points_absolute = data_geo_spatial.get_data_points(absolute=True) 504 attributes = linear_function(data_points_absolute) 507 505 att = 'spam_and_eggs' 508 points_dict = {'pointlist': data_points, 509 'attributelist': {att: z}} 510 511 export_points_file(ptsfile, points_dict) 506 507 #Create .txt file 508 ptsfile = tempfile.mktemp(".txt") 509 file = open(ptsfile,"w") 510 file.write(" x,y," + att + " \n") 511 for data_point, attribute in map(None, data_points_absolute 512 ,attributes): 513 row = str(data_point[0]) + ',' + str(data_point[1]) \ 514 + ',' + str(attribute) 515 file.write(row + "\n") 516 file.close() 517 512 518 513 519 #Check that values can be set from file … … 551 557 elements = [ [1,0,2], [1,2,4], [4,2,5], [3,1,4] ] 552 558 559 #absolute going in .. 553 560 mesh4 = Domain(points, elements, 554 561 geo_reference = Geo_reference(56, 0, 0)) … … 557 564 558 565 #Get (enough) datapoints (relative to georef) 559 data_points = [[ 0.66666667, 0.66666667],566 data_points_rel = [[ 0.66666667, 0.66666667], 560 567 [ 1.33333333, 1.33333333], 561 568 [ 2.66666667, 0.66666667], … … 571 578 [ 3.0, 1.0]] 572 579 573 z = linear_function(data_points) 574 575 576 #Create pts file 577 from load_mesh.loadASCII import export_points_file 578 579 ptsfile = 'testptsfile.pts' 580 data_geo_spatial = Geospatial_data(data_points_rel, 581 geo_reference = Geo_reference(56, x0, y0)) 582 data_points_absolute = data_geo_spatial.get_data_points(absolute=True) 583 attributes = linear_function(data_points_absolute) 580 584 att = 'spam_and_eggs' 581 582 points_dict = {'pointlist': data_points, 583 'attributelist': {att: z}, 584 'geo_reference': Geo_reference(zone = 56, 585 xllcorner = x0, 586 yllcorner = y0)} 587 588 export_points_file(ptsfile, points_dict) 589 585 586 #Create .txt file 587 ptsfile = tempfile.mktemp(".txt") 588 file = open(ptsfile,"w") 589 file.write(" x,y," + att + " \n") 590 for data_point, attribute in map(None, data_points_absolute 591 ,attributes): 592 row = str(data_point[0]) + ',' + str(data_point[1]) \ 593 + ',' + str(attribute) 594 file.write(row + "\n") 595 file.close() 596 597 #file = open(ptsfile, 'r') 598 #lines = file.readlines() 599 #file.close() 600 590 601 591 602 #Check that values can be set from file 592 603 quantity.set_values(filename = ptsfile, 593 604 attribute_name = att, alpha = 0) 594 answer = linear_function(quantity.domain.get_vertex_coordinates() - [x0, y0])605 answer = linear_function(quantity.domain.get_vertex_coordinates()) 595 606 596 607 assert allclose(quantity.vertex_values.flat, answer) … … 630 641 quantity = Quantity(mesh4) 631 642 632 #Get (enough) datapoints (relative to georef)643 #Get (enough) datapoints 633 644 data_points = [[ x0+0.66666667, y0+0.66666667], 634 645 [ x0+1.33333333, y0+1.33333333], … … 645 656 [ x0+3.0, y0+1.0]] 646 657 647 z = linear_function(data_points) 648 649 650 #Create pts file 651 from load_mesh.loadASCII import export_points_file 652 653 ptsfile = 'testptsfile.pts' 658 659 data_geo_spatial = Geospatial_data(data_points, 660 geo_reference = Geo_reference(56, 0, 0)) 661 data_points_absolute = data_geo_spatial.get_data_points(absolute=True) 662 attributes = linear_function(data_points_absolute) 654 663 att = 'spam_and_eggs' 655 656 points_dict = {'pointlist': data_points, 657 'attributelist': {att: z}, 658 'geo_reference': Geo_reference(zone = 56, 659 xllcorner = 0, 660 yllcorner = 0)} 661 662 export_points_file(ptsfile, points_dict) 664 665 #Create .txt file 666 ptsfile = tempfile.mktemp(".txt") 667 file = open(ptsfile,"w") 668 file.write(" x,y," + att + " \n") 669 for data_point, attribute in map(None, data_points_absolute 670 ,attributes): 671 row = str(data_point[0]) + ',' + str(data_point[1]) \ 672 + ',' + str(attribute) 673 file.write(row + "\n") 674 file.close() 663 675 664 676 … … 666 678 quantity.set_values(filename = ptsfile, 667 679 attribute_name = att, alpha = 0) 668 answer = linear_function(quantity.domain.get_vertex_coordinates() + [x0, y0]) 680 answer = linear_function(quantity.domain. \ 681 get_vertex_coordinates(absolute=True)) 669 682 670 683 … … 1690 1703 suite = unittest.makeSuite(Test_Quantity, 'test') 1691 1704 #print "restricted test" 1692 #suite = unittest.makeSuite(Test_Quantity,'test_set_values_f unc')1705 #suite = unittest.makeSuite(Test_Quantity,'test_set_values_from_file_with_georef2') 1693 1706 runner = unittest.TextTestRunner() 1694 1707 runner.run(suite) -
anuga_core/source/anuga/fit_interpolate/fit.py
r4129 r4130 415 415 def fit_to_mesh(vertex_coordinates, 416 416 triangles, 417 point_coordinates =None,417 point_coordinates, # this can also be a .csv/.txt file name 418 418 point_attributes=None, 419 alpha = DEFAULT_ALPHA, 420 verbose = False, 421 acceptable_overshoot = 1.01, 422 mesh_origin = None, 423 data_origin = None, 419 alpha=DEFAULT_ALPHA, 420 verbose=False, 421 acceptable_overshoot=1.01, 422 mesh_origin=None, 423 data_origin=None, 424 max_read_lines=None, 424 425 use_cache = False): 425 426 """ … … 477 478 vertex_attributes = interp.fit(point_coordinates, 478 479 point_attributes, 479 point_origin = data_origin, 480 verbose = verbose) 480 point_origin=data_origin, 481 max_read_lines=max_read_lines, 482 verbose=verbose) 481 483 482 484 -
anuga_core/source/anuga/fit_interpolate/test_fit.py
r4129 r4130 235 235 236 236 f = interp.fit(fileName, max_read_lines=2) 237 answer = linear_function(vertices) 238 #print "f\n",f 239 #print "answer\n",answer 240 assert allclose(f, answer) 241 242 def test_fit_2_mesh(self): 243 244 a = [-1.0, 0.0] 245 b = [3.0, 4.0] 246 c = [4.0,1.0] 247 d = [-3.0, 2.0] #3 248 e = [-1.0,-2.0] 249 f = [1.0, -2.0] #5 250 251 vertices = [a, b, c, d,e,f] 252 triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc 253 254 255 fileName = tempfile.mktemp(".ddd") 256 file = open(fileName,"w") 257 file.write(" x,y, elevation \n\ 258 -2.0, 2.0, 0.\n\ 259 -1.0, 1.0, 0.\n\ 260 0.0, 2.0 , 2.\n\ 261 1.0, 1.0 , 2.\n\ 262 2.0, 1.0 ,3. \n\ 263 0.0, 0.0 , 0.\n\ 264 1.0, 0.0 , 1.\n\ 265 0.0, -1.0, -1.\n\ 266 -0.2, -0.5, -0.7\n\ 267 -0.9, -1.5, -2.4\n\ 268 0.5, -1.9, -1.4\n\ 269 3.0, 1.0 , 4.\n") 270 file.close() 271 272 f = fit_to_mesh(vertices, triangles,fileName, 273 alpha=0.0, max_read_lines=2) 237 274 answer = linear_function(vertices) 238 275 #print "f\n",f
Note: See TracChangeset
for help on using the changeset viewer.