Changeset 5463
- Timestamp:
- Jul 4, 2008, 12:35:42 PM (15 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5462 r5463 5061 5061 raise Exception, msg 5062 5062 5063 reference_header = 'index, longitude, latitude\n'.split(',') 5063 reference_header = 'index, longitude, latitude\n' 5064 reference_header_split = reference_header.split(',') 5064 5065 for i in range(3): 5065 if not file_header[i] == reference_header [i]:5066 msg = 'File must contain header \n'+header+'\n'5066 if not file_header[i] == reference_header_split[i]: 5067 msg = 'File must contain header: '+reference_header+'\n' 5067 5068 raise Exception, msg 5068 5069 … … 5181 5182 outfile.close() 5182 5183 5183 def create_sts_boundary( order_file,stsname,lat_long=True):5184 def create_sts_boundary(stsname): 5184 5185 """ 5185 5186 Create boundary segments from .sts file. Points can be stored in 5186 5187 arbitrary order within the .sts file. The order in which the .sts points 5187 5188 make up the boundary are given in order.txt file 5188 """ 5189 5190 if not order_file[-3:] == 'txt': 5191 msg = 'Order file must be a txt file' 5192 raise Exception, msg 5193 5194 try: 5195 fid=open(order_file,'r') 5196 file_header=fid.readline() 5197 lines=fid.readlines() 5198 fid.close() 5199 except: 5200 msg = 'Cannot open %s'%filename 5201 raise msg 5202 5203 header="index,longitude,latitude\n" 5204 5205 if not file_header==header: 5206 msg = 'File must contain header\n'+header+"\n" 5207 raise Exception, msg 5208 5209 if len(lines)<2: 5210 msg = 'File must contain at least two points' 5211 raise Exception, msg 5212 5189 5190 FIXME: 5191 Point coordinates are stored in relative eastings and northings. 5192 But boundary is produced in absolute coordinates 5193 5194 """ 5213 5195 try: 5214 5196 fid = NetCDFFile(stsname+'.sts', 'r') … … 5229 5211 sts_points = concatenate((x,y), axis=1) 5230 5212 5231 xllcorner = fid.xllcorner[0] 5232 yllcorner = fid.yllcorner[0] 5233 5234 # Walk through ordering file 5235 boundary_polygon=[] 5236 for line in lines: 5237 fields = line.split(',') 5238 index=int(fields[0]) 5239 if lat_long: 5240 zone,easting,northing=redfearn(float(fields[1]),float(fields[2])) 5241 if not zone == fid.zone[0]: 5242 msg = 'Inconsistent zones' 5243 raise Exception, msg 5244 else: 5245 easting = float(fields[1]) 5246 northing = float(fields[2]) 5247 5248 if not allclose(array([easting,northing]),sts_points[index]): 5249 msg = "Points in sts file do not match those in the"+\ 5250 ".txt file specifying the order of the boundary points" 5251 raise Exception, msg 5252 boundary_polygon.append(sts_points[index].tolist()) 5253 5254 fid.close() 5255 5256 return boundary_polygon 5213 return sts_points.tolist() 5257 5214 5258 5215 class Write_sww: -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r5462 r5463 6937 6937 fid=open(order_file,'w') 6938 6938 #Write Header 6939 header= "index,longitude,latitude\n"6939 header='index, longitude, latitude\n' 6940 6940 fid.write(header) 6941 6941 indices=[3,0,1] 6942 6942 for i in indices: 6943 line=str(i)+d+str(lat_long_points[i][ 0])+d+\6944 str(lat_long_points[i][ 1])+"\n"6943 line=str(i)+d+str(lat_long_points[i][1])+d+\ 6944 str(lat_long_points[i][0])+"\n" 6945 6945 fid.write(line) 6946 6946 fid.close() 6947 6947 6948 6948 sts_file=base_name 6949 urs2sts(base_name,sts_file,mean_stage=tide,verbose=False) 6949 urs2sts(base_name, basename_out=sts_file, 6950 ordering_filename=order_file, 6951 mean_stage=tide, 6952 verbose=False) 6950 6953 self.delete_mux(files) 6951 6954 6952 boundary_polygon = create_sts_boundary( order_file,base_name)6955 boundary_polygon = create_sts_boundary(base_name) 6953 6956 6954 6957 os.remove(order_file)
Note: See TracChangeset
for help on using the changeset viewer.