Changeset 5418 for anuga_core/source/anuga/shallow_water/data_manager.py
- Timestamp:
- Jun 24, 2008, 11:42:50 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r5412 r5418 5081 5081 outfile.close() 5082 5082 5083 def create_sts_boundary(order_file,stsname): 5084 """ 5085 Create boundary segments from .sts file. Points can be stored in 5086 arbitrary order within the .sts file. The order in which the .sts points 5087 make up the boundary are given in order.txt file 5088 """ 5089 5090 if not order_file[-3:] == 'txt': 5091 msg = 'Order file must be a txt file' 5092 raise Exception, msg 5093 5094 try: 5095 fid=open(order_file,'r') 5096 file_header=fid.readline() 5097 lines=fid.readlines() 5098 fid.close() 5099 except: 5100 msg = 'Cannot open %s'%filename 5101 raise msg 5102 5103 header="index,longitude,latitude\n" 5104 5105 if not file_header==header: 5106 msg = 'File must contain header\n'+header+"\n" 5107 raise Exception, msg 5108 5109 try: 5110 fid = NetCDFFile(stsname+'.sts', 'r') 5111 except: 5112 msg = 'Cannot open %s'%filename+'.sts' 5113 5114 5115 xllcorner = fid.xllcorner[0] 5116 yllcorner = fid.yllcorner[0] 5117 #Points stored in sts file are normailsed to [xllcorner,yllcorner] but 5118 #we cannot assume that boundary polygon will be. At least the 5119 #additional points specified by the user after this function is called 5120 x = fid.variables['x'][:]+xllcorner 5121 y = fid.variables['y'][:]+yllcorner 5122 5123 x = reshape(x, (len(x),1)) 5124 y = reshape(y, (len(y),1)) 5125 sts_points = concatenate((x,y), axis=1) 5126 5127 xllcorner = fid.xllcorner[0] 5128 yllcorner = fid.yllcorner[0] 5129 5130 boundary_polygon=[] 5131 for line in lines: 5132 fields = line.split(',') 5133 index=int(fields[0]) 5134 zone,easting,northing=redfearn(float(fields[1]),float(fields[2])) 5135 if not zone == fid.zone[0]: 5136 msg = 'Inconsitent zones' 5137 raise Exception, msg 5138 if not allclose(array([easting,northing]),sts_points[index]): 5139 msg = "Points in sts file do not match those in the"+\ 5140 ".txt file spcifying the order of the boundary points" 5141 raise Exception, msg 5142 boundary_polygon.append(sts_points[index].tolist()) 5143 5144 return boundary_polygon 5145 5083 5146 class Write_sww: 5084 5147 from anuga.shallow_water.shallow_water_domain import Domain
Note: See TracChangeset
for help on using the changeset viewer.