Changeset 2252
- Timestamp:
- Jan 19, 2006, 12:00:08 PM (19 years ago)
- Location:
- inundation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/combine_pts.py
r2022 r2252 1 """Add two point files by the union of the fine and coarse points. 2 Course points that are in the extent of the fine points are removed. 3 4 The extent of the fine points file is assumed to be a rectangle, parallel 5 to the x and y axis. 1 """Functionality for aggregation of points files 6 2 7 3 Ole Nielsen, Stephen Roberts, Duncan Gray 8 4 Geoscience Australia, 2005. 9 5 """ 6 10 7 from utilities.polygon import outside_polygon, inside_polygon 11 8 from Numeric import take, concatenate … … 16 13 17 14 def combine_rectangular_points_files(fine_points_file, 18 coarse_points_file,19 output_points_file,15 coarse_points_file, 16 output_points_file, 20 17 verbose = False): 18 """Add two point files by the union of the fine and coarse points. 21 19 22 from load_mesh.loadASCII import import_points_file, extent, point_atts2array, export_points_file, add_point_dictionaries,take_points 20 Course points that are in the extent of the fine points are removed. 21 22 The extent of the fine points file is assumed to be a rectangle, parallel 23 to the x and y axis. 24 """ 25 26 from load_mesh.loadASCII import import_points_file, extent, point_atts2array, export_points_file, add_point_dictionaries, take_points 23 27 24 28 25 29 # load fine points file 26 if verbose: print "loading Point files"30 if verbose: print "loading Point files" 27 31 fine = import_points_file(fine_points_file) 28 32 … … 30 34 coarse = import_points_file(coarse_points_file) 31 35 32 if verbose: print "doing other stuff"36 if verbose: print "doing other stuff" 33 37 # convert to Numeric 34 38 fine = point_atts2array(fine) … … 44 48 if coarse.has_key('geo_reference'): 45 49 coarse['pointlist'] = \ 46 fine['geo_reference'].change_points_geo_ref(coarse['pointlist'],47 points_geo_ref=coarse['geo_reference'])50 fine['geo_reference'].change_points_geo_ref(coarse['pointlist'], 51 points_geo_ref=coarse['geo_reference']) 48 52 # find extent of course points 49 53 extent = extent(fine['pointlist']) … … 55 59 t0 = time.time() 56 60 outside_coarse_indices = outside_polygon(coarse['pointlist'], 57 extent, closed=True)61 extent, closed=True) 58 62 if verbose: 59 63 print "Points outside determined" … … 64 68 65 69 # add fine points and out_points 66 if verbose: print "Adding points"70 if verbose: print "Adding points" 67 71 combined = add_point_dictionaries(fine, coarse) 68 72 69 73 # save 70 if verbose: print "writing points"74 if verbose: print "writing points" 71 75 export_points_file(output_points_file, combined) 72 76 73 77 def add_points_files(fine_points_file, 74 coarse_points_file, 75 output_points_file, 76 verbose = False): 78 coarse_points_file, 79 output_points_file, 80 verbose = False): 81 """ 82 """ 77 83 78 84 from load_mesh.loadASCII import import_points_file, extent, point_atts2array, export_points_file, add_point_dictionaries,take_points … … 113 119 114 120 # add fine points and out_points 115 if verbose: print "Adding points"121 if verbose: print "Adding points" 116 122 combined = add_point_dictionaries(fine, coarse) 117 123 118 124 # save 119 if verbose: print "writing points"125 if verbose: print "writing points" 120 126 export_points_file(output_points_file, combined) 121 127 122 128 def reduce_points_to_mesh_extent(points_file, 123 mesh_file, 124 output_points_file, 125 verbose = False): 129 mesh_file, 130 output_points_file, 131 verbose = False): 132 """ 133 """ 126 134 127 135 from load_mesh.loadASCII import import_points_file, extent, point_atts2array, export_points_file, add_point_dictionaries,take_points, import_mesh_file … … 145 153 extent = \ 146 154 points['geo_reference'].change_points_geo_ref(extent, 147 points_geo_ref=mesh['geo_reference'])155 points_geo_ref=mesh['geo_reference']) 148 156 #print "extent",extent 149 157 -
inundation/pyvolution/test_all.py
r2141 r2252 49 49 files = get_test_files(path) 50 50 51 #print 'Testing:', files 51 52 52 53 53 #test = re.compile('^test_[\w]*.py$', re.IGNORECASE) … … 60 60 files.remove('test_all.py') 61 61 62 print 'Testing:' 63 for file in files: 64 print ' ' + file 62 65 63 66 if globals().has_key('exclude'): … … 76 79 77 80 from os import sep 78 81 79 82 #Attempt to compile all extensions 80 83 execfile('..' + sep + 'utilities' + sep + 'compile.py') -
inundation/pyvolution/test_combine_pts.py
r2075 r2252 38 38 fine_dict['geo_reference'] = Geo_reference(56,2.0,1.0) 39 39 40 fine_file = tempfile.mktemp( ".pts")40 fine_file = tempfile.mktemp('.pts') 41 41 export_points_file(fine_file, fine_dict) 42 42 … … 51 51 coarse_dict['geo_reference'] = Geo_reference(56,4.0,3.0) 52 52 53 coarse_file = tempfile.mktemp( ".pts")53 coarse_file = tempfile.mktemp('.pts') 54 54 export_points_file(coarse_file, coarse_dict) 55 55 56 out_file = tempfile.mktemp( ".pts")56 out_file = tempfile.mktemp('.pts') 57 57 58 58 combine_rectangular_points_files(fine_file,coarse_file,out_file) … … 63 63 64 64 results = import_points_file(out_file, 65 delimiter = ',')65 delimiter = ',') 66 66 answer = [[2.0, 0.0], 67 67 [0.0, 1.0], … … 73 73 74 74 self.failUnless(len(results['pointlist']) == len(answer), 75 75 'final number of points wrong. failed.') 76 76 77 77 assert allclose(results['pointlist'], answer) … … 84 84 85 85 self.failUnless(results['geo_reference'] == fine_dict['geo_reference'], 86 86 ' failed.') 87 87 #clean up 88 88 os.remove(out_file) … … 100 100 fine_dict['geo_reference'] = Geo_reference(56,2.0,1.0) 101 101 102 fine_file = tempfile.mktemp( ".pts")102 fine_file = tempfile.mktemp('.pts') 103 103 export_points_file(fine_file, fine_dict) 104 104 … … 113 113 coarse_dict['geo_reference'] = Geo_reference(56,4.0,3.0) 114 114 115 coarse_file = tempfile.mktemp( ".pts")115 coarse_file = tempfile.mktemp('.pts') 116 116 export_points_file(coarse_file, coarse_dict) 117 117 118 out_file = tempfile.mktemp( ".pts")118 out_file = tempfile.mktemp('.pts') 119 119 120 120 combine_rectangular_points_files(fine_file,coarse_file,out_file) … … 149 149 150 150 self.failUnless(results['geo_reference'] == fine_dict['geo_reference'], 151 151 ' failed.') 152 152 #clean up 153 153 os.remove(out_file) … … 167 167 fine_dict['geo_reference'] = Geo_reference(56,2.0,1.0) 168 168 169 fine_file = tempfile.mktemp( ".pts")169 fine_file = tempfile.mktemp('.pts') 170 170 export_points_file(fine_file, fine_dict) 171 171 … … 180 180 coarse_dict['geo_reference'] = Geo_reference(56,4.0,3.0) 181 181 182 coarse_file = tempfile.mktemp( ".pts")182 coarse_file = tempfile.mktemp('.pts') 183 183 export_points_file(coarse_file, coarse_dict) 184 184 185 out_file = tempfile.mktemp( ".pts")185 out_file = tempfile.mktemp('.pts') 186 186 try: 187 187 combine_rectangular_points_files(fine_file,coarse_file,out_file) … … 189 189 pass 190 190 else: 191 self.failUnless(0 == 1,192 'bad pts files did not raise error!')191 self.failUnless(0 == 1, 192 'bad pts files did not raise error!') 193 193 #clean up 194 194 os.remove(fine_file) … … 216 216 fine_dict['geo_reference'] = Geo_reference(56,x_origin,y_origin) 217 217 218 points_file = tempfile.mktemp( ".pts")218 points_file = tempfile.mktemp('.pts') 219 219 export_points_file(points_file, fine_dict) 220 220 … … 236 236 mesh['geo_reference'] = Geo_reference(56,x_origin+7.,y_origin+7.) 237 237 238 mesh_file = tempfile.mktemp( ".tsh")238 mesh_file = tempfile.mktemp('.tsh') 239 239 export_mesh_file(mesh_file, mesh) 240 240 241 out_file = tempfile.mktemp( ".pts")241 out_file = tempfile.mktemp('.pts') 242 242 243 243 reduce_points_to_mesh_extent(points_file,mesh_file,out_file)
Note: See TracChangeset
for help on using the changeset viewer.