Changeset 2563
- Timestamp:
- Mar 21, 2006, 10:58:32 AM (19 years ago)
- Location:
- inundation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/fit_interpolate/benchmark_least_squares.py
r2184 r2563 22 22 23 23 from pyvolution.least_squares import Interpolation 24 from fit_interpolate.interpolate import Interpolate 24 25 from pmesh.mesh import Mesh 25 26 … … 57 58 max_points_per_cell=4, 58 59 is_fit=True, 60 use_least_squares=True, 59 61 save=False): 60 62 ''' … … 66 68 #print "max_points_per_cell", max_points_per_cell 67 69 68 # make a mesh 70 mesh_dict = self._build_regular_mesh_dict(maxArea=maxArea, 71 save=save) 72 points_dict = self._build_points_dict(num_of_points=num_of_points) 73 74 #Initial time and memory 75 t0 = time.time() 76 #m0 = None on windows 77 m0 = mem_usage() 78 79 if use_least_squares is True: 80 interp = Interpolation(mesh_dict['vertices'], 81 mesh_dict['triangles'], 82 points_dict['points'], 83 expand_search=True, 84 verbose = False, 85 max_points_per_cell = max_points_per_cell) 86 if is_fit is True: 87 calc = interp.fit_points(points_dict['point_attributes']) 88 89 else: 90 # run an interploate problem. 91 print "Interpolate!" 92 calc = interp.interpolate(mesh_dict['vertex_attributes']) 93 else: 94 # need to change to fit_interpolate code 95 interp = Interpolate(mesh_dict['vertices'], 96 mesh_dict['triangles'], 97 max_vertices_per_cell = max_points_per_cell) 98 if is_fit is True: 99 #calc = interp.fit_points(point_atts) 100 pass 101 else: 102 # run an interploate problem. 103 print "Interpolate!" 104 calc = interp.interpolate(mesh_dict['vertex_attributes'] 105 ,points_dict['points'] 106 ,start_blocking_len = 500000) 107 108 time_taken_sec = (time.time()-t0) 109 m1 = mem_usage() 110 if m0 is None or m1 is None: 111 memory_used = None 112 else: 113 memory_used = (m1 - m0) 114 #print 'That took %.2f seconds' %time_taken_sec 115 return time_taken_sec, memory_used, len(mesh_dict['triangles']) 116 117 def _build_regular_mesh_dict(self, 118 maxArea=1000, 119 save=False): 120 # make a mesh 69 121 # pretty regular size, with some segments thrown in. 70 122 m = Mesh() … … 104 156 m.export_mesh_file("aaaa.tsh") 105 157 mesh_dict = m.Mesh2IOTriangulationDict() 106 #print "mesh_dict",mesh_dict 158 159 #Add vert attribute info to the mesh 160 mesh_dict['vertex_attributes'] = [] 161 # There has to be a better way of doing this.. 162 for vertex in mesh_dict['vertices']: 163 mesh_dict['vertex_attributes'].append([10.0]) 164 165 return mesh_dict 166 167 def _build_points_dict(self, num_of_points=20000): 168 169 points_dict = {} 107 170 points = [] 108 171 point_atts = [] 109 vertex_atts = []110 172 111 112 113 173 for point in range(num_of_points): 114 174 points.append([random()*100, random()*100]) 115 175 point_atts.append(10.0) 116 176 117 # There has to be a better way of doing this.. 118 for vertex in mesh_dict['vertices']: 119 vertex_atts.append(10.0) 120 121 #Initial time and memory 122 t0 = time.time() 123 #m0 = None on windows 124 m0 = mem_usage() 177 points_dict['points'] = points 178 points_dict['point_attributes'] = point_atts 179 return points_dict 125 180 126 interp = Interpolation(mesh_dict['vertices'],127 mesh_dict['triangles'], points,128 alpha=0.2, expand_search=True,129 verbose = False,130 max_points_per_cell = 4)131 if is_fit is True:132 calc = interp.fit_points(point_atts)133 181 134 else: 135 # run an interploate problem. 136 print "Interpolate!" 137 calc = interp.interpolate(vertex_atts) 138 139 time_taken_sec = (time.time()-t0) 140 m1 = mem_usage() 141 if m0 is None or m1 is None: 142 memory_used = None 143 else: 144 memory_used = (m1 - m0) 145 #print 'That took %.2f seconds' %time_taken_sec 146 return time_taken_sec, memory_used, len(mesh_dict['triangles']) 182 #------------------------------------------------------------- 183 if __name__ == "__main__": 184 b = BenchmarkLeastSquares() 185 b._build_regular_mesh_dict() 186 b._build_points_dict() -
inundation/fit_interpolate/interpolate.py
r2504 r2563 19 19 20 20 import time 21 import os 22 from warnings import warn 21 23 22 24 from Numeric import zeros, array, Float, Int, dot, transpose, concatenate, \ … … 28 30 from coordinate_transforms.geo_reference import Geo_reference 29 31 from pyvolution.quad import build_quadtree 30 from utilities.numerical_tools import ensure_numeric 32 from utilities.numerical_tools import ensure_numeric, mean 31 33 from utilities.polygon import inside_polygon 32 34 … … 160 162 A[i,j] = sigmas[j] 161 163 else: 162 print 'Could not find triangle for point', x 164 # Hack so this message only appears when the test is 165 #run in fit_interpoate directory. 166 #Error message reminds me to do something 167 #with points outside the polygon 168 if os.getcwd()[-15:] == "fit_interpolate": 169 print 'Could not find triangle for point', x 163 170 return A 164 171 … … 258 265 259 266 260 # FIXME: What is a good start_blocking_ countvalue?267 # FIXME: What is a good start_blocking_len value? 261 268 def interpolate(self, f, point_coordinates = None, 262 269 start_blocking_len = 500000, verbose=False): … … 298 305 #There are no good point_coordinates. import sys; sys.exit() 299 306 msg = 'ERROR (interpolate.py): No point_coordinates inputted' 300 raise msg 307 raise Exception(msg) 308 301 309 302 310 if point_coordinates is not None: … … 342 350 343 351 344 class Interpolation_ interface:352 class Interpolation_function: 345 353 """Interpolation_interface - creates callable object f(t, id) or f(t,x,y) 346 354 which is interpolated from time series defined at vertices of … … 394 402 395 403 396 from util import mean, ensure_numeric404 #from util import mean, ensure_numeric 397 405 from config import time_format 398 406 import types … … 532 540 if x is None or y is None: 533 541 msg = 'Either point_id or x and y must be specified' 534 raise msg542 raise Exception(msg) 535 543 else: 536 544 if self.interpolation_points is None: … … 538 546 'with a list of interpolation points before parameter ' +\ 539 547 'point_id can be used' 540 raise msg548 raise Exception(msg) 541 549 542 550 543 551 msg = 'Time interval [%s:%s]' %(self.T[0], self.T[1]) 544 552 msg += ' does not match model time: %s\n' %t 545 if t < self.T[0]: raise msg546 if t > self.T[-1]: raise msg553 if t < self.T[0]: raise Exception(msg) 554 if t > self.T[-1]: raise Exception(msg) 547 555 548 556 oldindex = self.index #Time index … … 698 706 def read_sww(file_name): 699 707 """ 708 obsolete - Nothing should be calling this 709 700 710 Read in an sww file. 701 711 -
inundation/fit_interpolate/run_long_benchmark.py
r2184 r2563 7 7 delimiter = ',' 8 8 9 is_fit_list = [True, False] 10 num_of_points_list = [10, 1000, 100000, 10000000] 11 maxArea_list = [0.1, 0.001, 0.00001, 0.0000001] 9 use_least_squares_list = [True,False] 10 is_fit_list = [False] 11 num_of_points_list = [10] 12 maxArea_list = [0.1, 0.001] 13 #num_of_points_list = [10, 1000, 100000, 10000000] 14 #maxArea_list = [0.1, 0.001, 0.00001, 0.0000001] 12 15 max_points_per_cell_list = [8] 13 16 … … 15 18 # write the title line 16 19 17 fd.write("num_of_points" + delimiter + 20 fd.write("use_least_squares" + delimiter + 21 "num_of_points" + delimiter + 18 22 "maxArea" + delimiter + 19 23 "num_of_triangles" + delimiter + … … 23 27 "time" + delimiter + "\n") 24 28 25 for is_fit in is_fit_list: 26 for num_of_points in num_of_points_list: 27 for maxArea in maxArea_list: 28 for max_points_per_cell in max_points_per_cell_list: 29 30 for use_least_squares in use_least_squares_list: 31 for is_fit in is_fit_list: 32 for num_of_points in num_of_points_list: 33 for maxArea in maxArea_list: 34 for max_points_per_cell in max_points_per_cell_list: 29 35 30 time, mem, num_tri = ben.trial(num_of_points=num_of_points 31 ,maxArea=maxArea 32 ,max_points_per_cell=max_points_per_cell 33 ,is_fit=is_fit 34 ) 35 print "time",time 36 print "mem", mem 37 fd.write(str(is_fit) + delimiter + 38 str(num_of_points) + delimiter + 39 str(maxArea) + delimiter + 40 str(num_tri) + delimiter + 41 str(max_points_per_cell) + delimiter + 42 str(mem) + delimiter + 43 str(time) + delimiter + "\n") 36 time, mem, num_tri = ben.trial(num_of_points=num_of_points 37 ,maxArea=maxArea 38 ,max_points_per_cell=max_points_per_cell 39 ,is_fit=is_fit 40 ,use_least_squares=use_least_squares 41 ) 42 print "time",time 43 print "mem", mem 44 fd.write(str(use_least_squares) + delimiter + 45 str(is_fit) + delimiter + 46 str(num_of_points) + delimiter + 47 str(maxArea) + delimiter + 48 str(num_tri) + delimiter + 49 str(max_points_per_cell) + delimiter + 50 str(mem) + delimiter + 51 str(time) + delimiter + "\n") 44 52 fd.close() -
inundation/fit_interpolate/test_interpolate.py
r2394 r2563 20 20 from coordinate_transforms.geo_reference import Geo_reference 21 21 from shallow_water import Domain, Transmissive_boundary #, mean 22 from util import mean22 from utilities.numerical_tools import mean 23 23 from data_manager import get_dataobject 24 24 … … 623 623 #Check basic interpolation of one quantity using averaging 624 624 #(no interpolation points or spatial info) 625 from util import mean 626 I = Interpolation_interface(time, [mean(Q[0,:]), 625 I = Interpolation_function(time, [mean(Q[0,:]), 627 626 mean(Q[1,:]), 628 627 mean(Q[2,:])]) … … 702 701 703 702 #Check interpolation of one quantity using interpolaton points 704 I = Interpolation_ interface(time, Q,703 I = Interpolation_function(time, Q, 705 704 vertex_coordinates = points, 706 705 triangles = triangles, … … 770 769 771 770 #Check interpolation of one quantity using interpolaton points) 772 I = Interpolation_ interface(time, Q,771 I = Interpolation_function(time, Q, 773 772 vertex_coordinates = points, 774 773 triangles = triangles, -
inundation/test_all.py
r2530 r2563 16 16 #E.g. if they are known to fail and under development 17 17 exclude_files = ['test_metis.py', 'test_version.py', 18 'test_interpolate.py',# this is under development18 #'test_interpolate.py',# this is under development 19 19 ] 20 20 #'test_calculate_region.py', 'test_calculate_point.py']
Note: See TracChangeset
for help on using the changeset viewer.