Changeset 4238
- Timestamp:
- Feb 7, 2007, 5:14:03 PM (18 years ago)
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/geospatial_data/geospatial_data.py
r4225 r4238 608 608 self.get_all_attributes(), 609 609 as_lat_long=as_lat_long) 610 610 611 elif file_name[-4:] == ".urs" : 612 msg = "ERROR: Can not write a .urs file as a relative file." 613 assert absolute, msg 614 _write_urs_file(file_name, 615 self.get_data_points(as_lat_long=True)) 616 611 617 else: 612 618 msg = 'Unknown file type %s ' %file_name … … 1223 1229 1224 1230 fd.close() 1231 1232 def _write_urs_file(file_name, 1233 points, 1234 delimiter=' '): 1235 """ 1236 export a file, file_name, with the urs format 1237 the data points are in lats and longs 1238 1239 """ 1240 fd = open(file_name,'w') 1241 fd.write(str(len(points))+"\n") 1242 # <lat> <long> <id#> 1243 for i, vert in enumerate( points): 1244 fd.write(str(round(vert[0],7)) + delimiter + \ 1245 str(round(vert[1],7)) + delimiter +str(i+1)+ "\n") 1246 fd.close() 1225 1247 1226 1248 def _point_atts2array(point_atts): -
anuga_core/source/anuga/geospatial_data/test_geospatial_data.py
r4225 r4238 2035 2035 2036 2036 2037 def test_write_urs_file(self): 2038 lat_gong = degminsec2decimal_degrees(-34,00,0) 2039 lon_gong = degminsec2decimal_degrees(150,30,0.) 2040 2041 lat_2 = degminsec2decimal_degrees(-34,00,1) 2042 lon_2 = degminsec2decimal_degrees(150,00,0.) 2043 p1 = (lat_gong, lon_gong) 2044 p2 = (lat_2, lon_2) 2045 points = ImmutableSet([p1, p2, p1]) 2046 gsd = Geospatial_data(data_points=list(points), 2047 points_are_lats_longs=True) 2048 2049 fn = tempfile.mktemp(".urs") 2050 gsd.export_points_file(fn) 2051 #print "fn", fn 2052 handle = open(fn) 2053 lines = handle.readlines() 2054 assert lines[0],'2' 2055 assert lines[1],'-34.0002778 150.0 1' 2056 assert lines[2],'-34.0 150.5 2' 2057 handle.close() 2058 os.remove(fn) 2059 2037 2060 def test_lat_long_set(self): 2038 2061 lat_gong = degminsec2decimal_degrees(-34,30,0.) … … 2096 2119 [5.0, 1.0], [5.0, 2.0],[5.0, 3.0], [5.0, 4.0], [5.0, 5.0]] 2097 2120 attributes = {'depth':[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 2098 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25],'speed':[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 2121 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25], 2122 'speed':[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 2099 2123 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]} 2100 2124 G = Geospatial_data(points, attributes) … … 2104 2128 factor = 0.21 2105 2129 2106 G1, G2 = G.split(factor) #will return G1 with 10% of points and G2 with 90% 2107 2108 # print 'len(G): %s len(G1): %s len(G2): %s' %(len(G), len(G1), len(G2)) 2130 #will return G1 with 10% of points and G2 with 90% 2131 G1, G2 = G.split(factor) 2132 2133 # print 'len(G): %s len(G1): %s len(G2): %s' %(len(G), len(G1), len(G2)) 2109 2134 # print 'G: ', len(G),'G1: ', len(G1), 'G2: ', len(G2) 2110 2135 -
anuga_core/source/anuga/shallow_water/data_manager.py
r4223 r4238 4409 4409 #### URS UNGRIDDED 2 SWW ### 4410 4410 4411 def URS_points_needed_to_file( boundary_polygon, ll_lat, ll_long,4411 def URS_points_needed_to_file(file_name, boundary_polygon, ll_lat, ll_long, 4412 4412 grid_spacing, 4413 4413 lat_amount, long_amount, zone=None): 4414 4414 """ 4415 file_name - name of the urs file produced for David. 4416 boundary_polygon - a list of points that describes a polygon. 4417 The last point is assumed ot join the first point. 4418 This is in UTM (lat long would be better though) 4419 4420 ll_lat - lower left latitude, in decimal degrees 4421 ll-long - lower left longitude, in decimal degrees 4422 grid_spacing - in deciamal degrees 4423 4424 4425 Don't add the file extension. It will be added. 4426 """ 4415 4427 geo = URS_points_needed(boundary_polygon, ll_lat, ll_long, grid_spacing, 4416 4428 lat_amount, long_amount, zone=zone) 4429 if not file[-4:] == ".urs": 4430 file += ".urs" 4431 geo.export_points_file(file_name) 4417 4432 4418 4433 def URS_points_needed(boundary_polygon, ll_lat, ll_long, grid_spacing, … … 4471 4486 max_lat = max(seg_lat_long[0][0], seg_lat_long[1][0]) + buffer 4472 4487 max_long = max(seg_lat_long[0][1], seg_lat_long[1][1]) + buffer 4473 min_lat = m ax(seg_lat_long[0][0], seg_lat_long[1][0]) - buffer4474 min_long = m ax(seg_lat_long[0][1], seg_lat_long[1][1]) - buffer4488 min_lat = min(seg_lat_long[0][0], seg_lat_long[1][0]) - buffer 4489 min_long = min(seg_lat_long[0][1], seg_lat_long[1][1]) - buffer 4475 4490 4476 4491 #print "ll_lat", ll_lat -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4225 r4238 5040 5040 5041 5041 #### TESTS URS UNGRIDDED 2 SWW ### 5042 def X_test_URS_points_needed(self):5042 def test_URS_points_needed(self): 5043 5043 5044 5044 ll_lat = -21.5 … … 5057 5057 #Maybe see if I can fit the data to the polygon - have to represent 5058 5058 # the poly as points though. 5059 geo.export_points_file("results")5059 #geo.export_points_file("results.txt", as_lat_long=True) 5060 5060 results = ImmutableSet(geo.get_data_points(as_lat_long=True)) 5061 print 'results',results5061 #print 'results',results 5062 5062 5063 5063 # These are a set of points that have to be in results 5064 5064 points = [] 5065 5065 for i in range(18): 5066 lat = -21.0 - 8 /60 - grid_spacing * i5066 lat = -21.0 - 8./60 - grid_spacing * i 5067 5067 points.append((lat,degminsec2decimal_degrees(114,35,0))) 5068 #points.append((lat,degminsec2decimal_degrees(114,36,0))) 5069 #points.append((lat,degminsec2decimal_degrees(114,52,0))) 5070 #points.append((lat,degminsec2decimal_degrees(114,53,0))) 5071 5068 points.append((lat,degminsec2decimal_degrees(114,36,0))) 5069 points.append((lat,degminsec2decimal_degrees(114,52,0))) 5070 points.append((lat,degminsec2decimal_degrees(114,53,0))) 5071 geo_answer = Geospatial_data(data_points=points, 5072 points_are_lats_longs=True) 5073 #geo_answer.export_points_file("answer.txt", as_lat_long=True) 5072 5074 answer = ImmutableSet(points) 5073 print "answer", answer5075 5074 5076 outs = answer.difference(results) 5075 print "outs", outs 5076 assert answer.issubset(results) 5077 #print "outs", outs 5078 # This doesn't work. Though visualising the results shows that 5079 # it is correct. 5080 #assert answer.issubset(results) 5081 # this is why; 5082 #point (-21.133333333333333, 114.58333333333333) 5083 #result (-21.133333332232368, 114.58333333300342) 5084 5085 for point in points: 5086 found = False 5087 for result in results: 5088 if allclose(point, result): 5089 found = True 5090 break 5091 if not found: 5092 assert False 5093 5077 5094 5078 5095 def X_test_URS_points_neededII(self): -
anuga_work/development/friction_dam_2006/run_dam.py
r4055 r4238 153 153 if __name__ == "__main__": 154 154 for friction in [ 0.05]: 155 main(friction, is_trial_run = False, outputdir_name='friction_set_A')155 main(friction, is_trial_run = True, outputdir_name='friction_set_A') 156 156 157 157 # to do
Note: See TracChangeset
for help on using the changeset viewer.