Changeset 4129 for anuga_core/source
- Timestamp:
- Jan 5, 2007, 11:05:11 AM (18 years ago)
- Location:
- anuga_core/source/anuga
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/quantity.py
r4127 r4129 692 692 #print kwargs 693 693 694 #FIXME(dsg):Why is this catched? fit_to_mesh handles caching. 694 695 if use_cache is True: 695 696 try: … … 734 735 assert type(filename) == StringType, msg 735 736 736 737 # Read from (NetCDF) file738 # FIXME (Ole): This function should really return a739 # Geospatial_data object.740 737 geospatial_data = Geospatial_data(filename) 741 738 742 #points_dict = import_points_file(filename)743 #points_dict['pointlist'] = None744 #points_dict['attributelist'] = None745 #points = points_dict['pointlist']746 #attributes = points_dict['attributelist']747 748 749 #Take care of georeferencing750 # this doesn't do anything....751 #if points_dict.has_key('geo_reference') and \752 # points_dict['geo_reference'] is not None:753 # data_georef = points_dict['geo_reference']754 #else:755 # data_georef = None756 757 # if there is no attribute name, use the 1st key?758 # This isn't so good..., if there is more than 1 key759 # since it will not always be the 1 column760 # or anything predictable...761 762 #if attribute_name is None:763 # names = attributes.keys()764 # attribute_name = names[0]765 766 #msg = 'Attribute_name must be a text string'767 #assert type(attribute_name) == StringType, msg768 769 770 #if verbose:771 # print 'Using attribute %s from file %s' %(attribute_name, filename)772 # print 'Available attributes: %s' %(names)773 774 #try:775 # z = attributes[attribute_name]776 #except:777 # msg = 'Could not extract attribute %s from file %s'\778 # %(attribute_name, filename)779 # raise msg780 781 #Call underlying method for geospatial data782 #geospatial_data = points_dictionary2geospatial_data(points_dict)783 # geospatial_data.set_default_attribute_name(attribute_name)784 785 739 self.set_values_from_geospatial_data(geospatial_data, 786 740 alpha, -
anuga_core/source/anuga/fit_interpolate/benchmark_least_squares.py
r4108 r4129 49 49 50 50 class BenchmarkLeastSquares: 51 51 """ 52 """ 53 54 """ 55 56 Note(DSG-DSG): If you are interested in benchmarking fitting, before 57 and after blocking O:\1\dgray\before_blocking_subsandpit is before blocking 58 59 """ 52 60 53 61 def __init__(self): -
anuga_core/source/anuga/fit_interpolate/fit.py
r4108 r4129 23 23 * (DSG-) Change the interface of fit, so a domain object can 24 24 be passed in. (I don't know if this is feasible). If could 25 save time .25 save time/memory. 26 26 """ 27 import types 27 28 28 29 from Numeric import zeros, Float, ArrayType,take … … 300 301 301 302 302 def fit(self, point_coordinates=None, z=None, 303 verbose = False, 304 point_origin = None): 303 def fit(self, point_coordinates_or_filename=None, z=None, 304 verbose=False, 305 point_origin=None, 306 max_read_lines=500): 305 307 """Fit a smooth surface to given 1d array of data points z. 306 308 … … 315 317 316 318 """ 319 320 # use blocking to load in the point info 321 if type(point_coordinates_or_filename) == types.StringType: 322 filename = point_coordinates_or_filename 323 for geo_block in Geospatial_data(filename, 324 max_read_lines=max_read_lines, 325 load_file_now=False): 326 # build the array 327 points = geo_block.get_data_points(absolute=True) 328 z = geo_block.get_attributes() 329 self.build_fit_subset(points, z) 330 point_coordinates = None 331 else: 332 point_coordinates = point_coordinates_or_filename 333 317 334 if point_coordinates is None: 318 335 assert self.AtA <> None … … 320 337 #FIXME (DSG) - do a message 321 338 else: 322 # This is where build fit subset can be looped over,323 # if a file name is passed in.324 339 point_coordinates = ensure_absolute(point_coordinates, 325 340 geo_reference=point_origin) … … 400 415 def fit_to_mesh(vertex_coordinates, 401 416 triangles, 402 point_coordinates ,403 point_attributes ,417 point_coordinates=None, 418 point_attributes=None, 404 419 alpha = DEFAULT_ALPHA, 405 420 verbose = False, -
anuga_core/source/anuga/fit_interpolate/test_fit.py
r3560 r4129 5 5 import unittest 6 6 from math import sqrt 7 import tempfile 7 8 8 9 from Numeric import zeros, take, compress, Float, Int, dot, concatenate, \ … … 199 200 assert allclose(f, answer) 200 201 202 # test fit 2 mesh as well. 203 def test_fit_file_blocking(self): 204 205 a = [-1.0, 0.0] 206 b = [3.0, 4.0] 207 c = [4.0,1.0] 208 d = [-3.0, 2.0] #3 209 e = [-1.0,-2.0] 210 f = [1.0, -2.0] #5 211 212 vertices = [a, b, c, d,e,f] 213 triangles = [[0,1,3], [1,0,2], [0,4,5], [0,5,2]] #abd bac aef afc 214 215 interp = Fit(vertices, triangles, 216 alpha=0.0) 217 218 219 fileName = tempfile.mktemp(".ddd") 220 file = open(fileName,"w") 221 file.write(" x,y, elevation \n\ 222 -2.0, 2.0, 0.\n\ 223 -1.0, 1.0, 0.\n\ 224 0.0, 2.0 , 2.\n\ 225 1.0, 1.0 , 2.\n\ 226 2.0, 1.0 ,3. \n\ 227 0.0, 0.0 , 0.\n\ 228 1.0, 0.0 , 1.\n\ 229 0.0, -1.0, -1.\n\ 230 -0.2, -0.5, -0.7\n\ 231 -0.9, -1.5, -2.4\n\ 232 0.5, -1.9, -1.4\n\ 233 3.0, 1.0 , 4.\n") 234 file.close() 235 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 201 242 def test_fit_and_interpolation(self): 202 243 -
anuga_core/source/anuga/geospatial_data/geospatial_data.py
r4126 r4129 29 29 longitudes=None, 30 30 points_are_lats_longs=False, 31 max_read_lines=None, 31 max_read_lines=None, 32 load_file_now=True, 32 33 verbose=False): 33 34 … … 105 106 106 107 verbose: 108 109 load_file_now: if load file now is true, the file is 110 loaded during instanciation. 107 111 108 112 """ … … 134 138 self.set_default_attribute_name(default_attribute_name) 135 139 136 el se:140 elif load_file_now is True: 137 141 # watch for case where file name and points, 138 142 # attributes etc are provided!! … … 145 149 self.set_default_attribute_name(default_attribute_name) 146 150 147 148 assert self.attributes is None or isinstance(self.attributes, DictType) 151 #Why? 152 #assert self.attributes is None or isinstance(self.attributes, DictType) 153 #This is a hassle when blocking, so I've removed it. 149 154 150 155 … … 539 544 raise IOError, msg 540 545 541 elif file_name[-4:]== ". xxx":546 elif file_name[-4:]== ".txt" or file_name[-4:]== ".csv": 542 547 #let's do ticket#116 stuff 543 548 # … … 677 682 678 683 #FIXME - what to do if the file isn't there 684 685 #FIXME - give warning if the file format is .xya 679 686 file_pointer = open(self.file_name) 680 687 self.header, self.file_pointer = _read_csv_file_header(file_pointer) … … 771 778 file_pointer, 772 779 header, 773 max_read_lines= 5000) #FIXME: how hacky is that!780 max_read_lines=MAX_READ_LINES) #FIXME: how hacky is that! 774 781 except StopIteration: 775 782 break … … 792 799 def _read_csv_file_blocking(file_pointer, header, 793 800 delimiter=CSV_DELIMITER, 794 max_read_lines= 500,801 max_read_lines=MAX_READ_LINES, 795 802 verbose=False): 796 803 … … 805 812 806 813 #This is to remove the x and y headers. 814 header = header[:] 807 815 header.pop(0) 808 816 header.pop(0) … … 1136 1144 1137 1145 if __name__ == "__main__": 1138 g = Geospatial_data("t. xxx")1146 g = Geospatial_data("t.txt") 1139 1147 print "g.get_data_points()", g.get_data_points() 1140 1148 for i,a in enumerate(g): -
anuga_core/source/anuga/geospatial_data/test_geospatial_data.py
r4103 r4129 912 912 import os 913 913 914 fileName = tempfile.mktemp(". xxx")914 fileName = tempfile.mktemp(".txt") 915 915 file = open(fileName,"w") 916 916 file.write(" x,y, elevation , speed \n\
Note: See TracChangeset
for help on using the changeset viewer.