Changeset 5465 for anuga_work/development/boxingday08/project.py
- Timestamp:
- Jul 4, 2008, 1:56:15 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_work/development/boxingday08/project.py
r5458 r5465 2 2 from Scientific.IO.NetCDF import NetCDFFile 3 3 from Numeric import asarray,transpose,sqrt,argmax,argmin,arange,Float,\ 4 compress,zeros,fabs,allclose 4 compress,zeros,fabs,allclose,ones 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 9 def create_sts_boundary_order_file(order_filename,stsfilename,verbose=False): 8 from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary 9 import os 10 11 def create_sts_boundary_order_file(urs_filename,order_filename,sts_filename,verbose=False): 10 12 """ 11 13 Note This is not a robust algorithm. Be Careful when applying that … … 13 15 follows the path it is supposed too. 14 16 """ 15 fid = NetCDFFile(stsfilename+'.sts', 'r') #Open existing file for read 16 x = fid.variables['x'][:]+fid.xllcorner #x-coordinates of vertices 17 y = fid.variables['y'][:]+fid.yllcorner #y-coordinates of vertices 18 coordinates=transpose(asarray([x.tolist(),y.tolist()])) 17 from anuga.shallow_water.data_manager import read_mux2_py 18 times, y, x, elevation, quantity, starttime = read_mux2_py([urs_filename],weights=ones(1,Float)) 19 19 20 20 #find indices of the southernmost gauges … … 60 60 61 61 #So far i cannot tell if the wrong point is closer. 62 63 boundary=ensure_numeric(boundary) 64 from anuga.coordinate_transforms import redfearn,convert_from_latlon_to_utm 65 boundary_utm,zone=convert_from_latlon_to_utm(longitudes=list(boundary[:,0]),latitudes=list(boundary[:,1])) 66 62 67 d="," 63 68 fid=open(order_filename,'w') 64 header= "index,longitude,latitude\n"69 header='index, longitude, latitude\n' 65 70 fid.write(header) 66 71 line=str(west_index)+d+str(x[west_index])+d+\ … … 72 77 fid.write(line) 73 78 fid.close() 74 return boundary 75 76 77 #read in polyline boundary 78 from anuga.shallow_water.data_manager import urs2sts,create_sts_boundary 79 urs_name='polyline' 80 #base_name=urs_name 81 tide=0.35 82 base_name='tide_polyline' 83 #base_name='most_polyline' 84 import os 85 if os.path.exists(base_name+'.sts'): 86 print 'sts boundary file already created.' 87 else: 88 print 'creatin sts file' 89 urs2sts(urs_name,base_name,mean_stage=tide,verbose=False) 90 91 order_filename='sts_order.txt' 92 boundary=create_sts_boundary_order_file(order_filename,base_name,verbose=False) 93 urs_boundary=create_sts_boundary(order_filename,base_name,lat_long=False) 94 assert allclose(boundary.tolist(),urs_boundary) 95 96 #Read in large domain boundary 97 dir='mesh_polygons' 98 extent = 'extent.csv' 99 bp = read_polygon(dir+sep+extent) 100 101 #Now order of boundary is correct clip sts boundary to small region for 102 #this particular scenario 103 indices=inside_polygon(urs_boundary, bp, closed=True, verbose=False) 104 bounding_polygon=[] 105 for i in indices[:-2]: 106 #disregard last two entries because they are not on boundary 107 bounding_polygon.append(urs_boundary[i]) 108 109 #Append clipped sts boundary to large domain boundary 110 bounding_polygon.extend(bp[2:len(bp)]) 111 112 ############################### 113 # Domain definitions 114 ############################### 79 return boundary,boundary_utm 80 81 ###################### 82 # Domain definitions # 83 ###################### 115 84 116 85 # Bathymetry and topography filenames … … 129 98 extent = 'extent.csv' 130 99 patong_bay_polygon = read_polygon(dir+sep+'patong_bay_polygon.csv') 100 101 tide=0.35 102 103 ###################################### 104 # Create urs boundary from mux2files # 105 ###################################### 106 urs_filename='polyline' 107 base_name='tide_polyline' 108 order_filename='boxingday_boundary_order.txt' 109 110 # Create ordering file 111 # Usually this would be provided before hand 112 boundary,boundary_utm=create_sts_boundary_order_file(urs_filename+'_waveheight-z-mux2',order_filename,base_name,verbose=False) 113 114 # Create ordered sts file 115 if not os.path.exists(base_name+'.sts'): 116 print 'creating sts file' 117 urs2sts(urs_filename,basename_out=base_name, 118 ordering_filename=order_filename, 119 mean_stage=tide, 120 verbose=False) 121 else: 122 print 'sts file exists' 123 124 # Read in boundary from ordered sts file 125 urs_boundary=create_sts_boundary(base_name) 126 127 # Checks that the boundary read from the sts file is the same as the one 128 # defined by the function create_sts_boundary_order_file 129 assert allclose(boundary_utm,urs_boundary) 130 131 ############################################################# 132 # Add urs boundary segment to user defined boundary polygon # 133 ############################################################# 134 135 # Read in specific user defined boundary 136 dir='mesh_polygons' 137 extent = 'extent.csv' 138 user_boundary_polygon = read_polygon(dir+sep+extent) 139 140 # The following is specific to this scenario 141 indices=inside_polygon(urs_boundary, user_boundary_polygon, closed=True, verbose=False) 142 bounding_polygon=[] 143 for i in indices[:-2]: 144 #disregard last two entries because they are not on boundary 145 bounding_polygon.append(urs_boundary[i]) 146 147 # Append clipped sts boundary to user defined domain boundary 148 bounding_polygon.extend(user_boundary_polygon[2:len(user_boundary_polygon)]) 131 149 132 150 ############################### 133 # Interior region definitions 151 # Interior region definitions # 134 152 ############################### 135 153 … … 141 159 patong = read_polygon(dir+sep+'patong.csv') 142 160 bay = read_polygon(dir+sep+'bay.csv') 161 162 ########################################## 163 # Plot urs boundary and internal regions # 164 ########################################## 143 165 144 166 plot=False … … 156 178 show() 157 179 180 181 ####################### 182 # For MOST SIMULATION # 183 ####################### 158 184 east = 97.7 159 185 west = 96.7
Note: See TracChangeset
for help on using the changeset viewer.