Changeset 5419
- Timestamp:
- Jun 24, 2008, 12:37:05 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/boxingday08/project.py
r5404 r5419 2 2 from Scientific.IO.NetCDF import NetCDFFile 3 3 from Numeric import asarray,transpose,sqrt,argmax,argmin,arange,Float,\ 4 compress,zeros,fabs4 compress,zeros,fabs,allclose 5 5 from anuga.utilities.polygon import inside_polygon,read_polygon 6 6 from os import sep 7 7 from time import localtime, strftime, gmtime 8 def create_sts_boundary(filename,verbose=False): 9 fid = NetCDFFile(filename+'.sts', 'r') #Open existing file for read 8 9 def create_sts_boundary_order_file(order_filename,stsfilename,verbose=False): 10 """ 11 Note This is not a robust algorithm. Be Careful when applying that 12 polygon does not intersect itself and that resulting boundary actually 13 follows the path it is supposed too. 14 """ 15 fid = NetCDFFile(stsfilename+'.sts', 'r') #Open existing file for read 10 16 x = fid.variables['x'][:]+fid.xllcorner #x-coordinates of vertices 11 17 y = fid.variables['y'][:]+fid.yllcorner #y-coordinates of vertices … … 33 39 boundary[0][1]=y[west_index] 34 40 indices.remove(west_index) 41 order=[] 35 42 for i in range(n-1): 36 43 min_dist=1e12 … … 46 53 boundary[i+1][0]=x[index] 47 54 boundary[i+1][1]=y[index] 55 order.append(index) 48 56 #ensure boundary is a polygon i.e no intesections 49 57 #e.g. … … 52 60 53 61 #So far i cannot tell if the wrong point is closer. 62 d="," 63 fid=open(order_filename,'w') 64 header="index,longitude,latitude\n" 65 fid.write(header) 66 line=str(west_index)+d+str(x[west_index])+d+\ 67 str(y[west_index])+"\n" 68 fid.write(line) 69 for i in order: 70 line=str(i)+d+str(x[i])+d+\ 71 str(y[i])+"\n" 72 fid.write(line) 73 fid.close() 54 74 return boundary 75 55 76 56 77 #read in polyline boundary 57 from anuga.shallow_water.data_manager import urs2sts 78 from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary 58 79 base_name='polyline' 59 80 import os 60 81 if os.path.exists(base_name+'.sts'): 61 82 print 'sts boundary file already created.' 62 83 else: 63 urs2sts(base_name,mean_stage=0.0,verbose=False) 64 boundary=create_sts_boundary(base_name,verbose=True) 65 urs_boundary=boundary.tolist() 84 urs2sts(base_name,mean_stage=0.0,verbose=False) 85 86 order_filename='sts_order.txt' 87 boundary=create_sts_boundary_order_file(order_filename,base_name,verbose=False) 88 urs_boundary=create_sts_boundary(order_filename,base_name,lat_long=False) 89 assert allclose(boundary.tolist(),urs_boundary) 66 90 67 91 #Read in large domain boundary … … 70 94 bp = read_polygon(dir+sep+extent) 71 95 96 #Now order of boundary is correct clip sts boundary to small region for 97 #this particular scenario 72 98 indices=inside_polygon(urs_boundary, bp, closed=True, verbose=False) 73 99 bounding_polygon=[] … … 76 102 bounding_polygon.append(urs_boundary[i]) 77 103 104 #Append clipped sts boundary to large domain boundary 78 105 bounding_polygon.extend(bp[2:len(bp)]) 79 106
Note: See TracChangeset
for help on using the changeset viewer.