Changeset 7723
- Timestamp:
- May 13, 2010, 9:51:30 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/anuga_1_1/anuga_work/production/bunbury_storm_surge_2009/process_gems_grids.py
r7692 r7723 22 22 state = 'western_australia' 23 23 scenario_folder = 'bunbury_storm_surge_scenario_2009' 24 event = ' case_1'24 event = 'gcom_60min' 25 25 26 26 print "Processing event: ", event … … 46 46 47 47 grid_file_names_temp = [] 48 for i in range( 0, 240, 2):48 for i in range(1, 32, 1): 49 49 grid_file_names_temp.append(grid_file_names[i]) 50 50 … … 56 56 57 57 start_time = 0 # all times in seconds 58 timestep = 1440 #720 # all times in seconds58 timestep = 3600 #1440 #720 # all times in seconds 59 59 end_time = start_time + (timestep*number_of_timesteps) # all times in seconds 60 60 refzone = 50 # UTM zone of model … … 62 62 63 63 elevation = [] 64 #stage = []65 #speed = []66 #theta = []67 64 68 65 elevation_file = open(elevation_file_name, 'rb') … … 95 92 print 'No data value: ', no_data 96 93 94 #------------------------------------------------------ 95 # Create arrays of elevation, stage, speed and theta 96 #------------------------------------------------------- 97 print 'creating numpy arrays: elevation, stage, speed, theta' 98 97 99 stage = numpy.empty(number_of_timesteps*nrows*ncols, dtype=float) 98 100 speed = numpy.empty(number_of_timesteps*nrows*ncols, dtype=float) 99 101 theta = numpy.empty(number_of_timesteps*nrows*ncols, dtype=float) 100 102 101 import pdb102 103 103 for j, f in enumerate(grid_file_names): 104 104 print 'file: ', f 105 105 106 106 gz_file = gzip.open(f, 'rb') 107 #lines = gz_file.readlines()108 #gz_file.close()109 110 #pdb.set_trace()111 107 112 108 st = [] 113 109 sp = [] 114 t h= []110 t = [] 115 111 116 112 for i, L in enumerate(gz_file): … … 123 119 124 120 if i > (11 + 2*nrows): 125 t h+= L.strip().split()121 t += L.strip().split() 126 122 127 123 stage[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(st).astype('d')) 128 124 speed[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(sp).astype('d')) 129 theta[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(t h).astype('d'))125 theta[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(t).astype('d')) 130 126 131 127 gz_file.close() 132 133 #pdb.set_trace() 134 135 #------------------------------------------------------ 136 # Create arrays of elevation, stage, speed and theta 137 #------------------------------------------------------- 138 print 'creating numpy arrays: elevation, stage, speed, theta' 139 128 140 129 elevation = numpy.array(elevation).astype('d') 141 130 142 #stage_array = numpy.empty([number_of_timesteps*nrows, ncols], dtype=float)143 #speed_array = numpy.empty([number_of_timesteps*nrows, ncols], dtype=float)144 #theta_array = numpy.empty([number_of_timesteps*nrows, ncols], dtype=float)145 146 #for i in range(number_of_timesteps):147 # ii = nrows*i148 # stage_array[ii:ii+nrows, :] = numpy.flipud(numpy.array(stage[ii : ii + nrows]).astype('d'))149 # speed_array[ii:ii+nrows, :] = numpy.flipud(numpy.array(speed[ii:ii + nrows]).astype('d'))150 # theta_array[ii:ii+nrows, :] = numpy.flipud(numpy.array(theta[ii:ii + nrows]).astype('d'))151 152 #stage = stage_array#.ravel()153 #speed = speed_array#.ravel()154 #theta = theta_array#.ravel()155 156 131 print 'Size of elevation array: ', elevation.size 157 132 print 'Size of stage array: ', stage.size … … 162 137 assert stage.size == number_of_timesteps * elevation.size 163 138 164 d = numpy.empty(elevation.size, dtype='d')165 139 depth = numpy.empty(stage.size, dtype='d') 166 140 number_of_points = ncols * nrows … … 171 145 # a consistant dataset 172 146 # --------------------------------------------- 173 174 #for i in xrange(number_of_timesteps): 175 # j = number_of_points * i 176 # k = j + number_of_points 177 # no_value_mask = (stage[j:k] < -9000) + (speed[j:k] < -9000) + (theta[j:k] < -9000) 178 # no_value_index = numpy.where(((stage[j:k] < -100) + (speed[j:k] < 0) + (theta[j:k] < 0)) == True)[0] 179 # depth[j:k] = stage[j:k] - elevation 180 # numpy.put(stage[j:k], no_value_index, -9999) 181 # numpy.put(speed[j:k], no_value_index, -9999) 182 # numpy.put(theta[j:k], no_value_index, -9999) 183 # numpy.put(depth[j:k], no_value_index, 0) 184 147 import pdb 148 pdb.set_trace() 185 149 no_value_index = numpy.where(((stage < -100) + (speed < 0) + (theta < 0)) == True)[0] 186 150 depth = stage - numpy.tile(elevation, number_of_timesteps) 151 187 152 numpy.put(stage, no_value_index, -9999) 188 153 numpy.put(speed, no_value_index, -9999) 189 154 numpy.put(theta, no_value_index, -9999) 190 155 numpy.put(depth, no_value_index, 0) 191 192 # for i in xrange(number_of_timesteps):193 # j = number_of_points * i194 # k = j + number_of_points195 # d = stage[j:k] - elevation # Assumes elevations below sea level are negative196 # depth[j:k] = [0 if x<-9000 else x for x in d] # sets stage to zero for no-data values of stage197 198 # depth[j:k] = [x if x>=0 and elevation>0 else 0 for x in d] # This is to correct for GEMS data which assumes stage=0 onshore when dry but should = elevation199 # for q in xrange(number_of_points):200 # if elevation[q] >= 0 and stage[j+q]==0:201 # depth[j+q] = 0202 156 203 157 # Taking absolute value is to account for -ve depths obtained when stage-elevation … … 205 159 momentum = numpy.absolute(depth * speed) 206 160 207 #xmomentum = numpy.empty(momentum.size, dtype='d')208 #ymomentum = numpy.empty(momentum.size, dtype='d')209 210 161 print 'Calculating xmomentum and ymomentum' 211 212 #for i, t in enumerate(theta):213 214 #mx = momentum[i]*math.sin(math.radians(t)) #Assuming t is in the "to" direction and 0 degrees is north215 #my = momentum[i]*math.cos(math.radians(t))216 162 217 163 xmomentum = momentum*numpy.sin(numpy.radians(theta)) … … 256 202 257 203 assert len(numpy.where((numpy.sqrt(xmomentum**2 + ymomentum**2) - momentum) > 1.e-06)[0]) == 0 258 259 #assert numpy.sqrt(xmomentum**2 + ymomentum**2) - momentum < 1.e-06260 204 261 205 x_origin_int = int(10000*x_origin) … … 280 224 #for j in range(2): 281 225 282 fid = NetCDFFile(os.path.join(event_folder, event + '_master_2_ .sts'), 'wl')226 fid = NetCDFFile(os.path.join(event_folder, event + '_master_2_1.sts'), 'wl') 283 227 fid.institution = 'Geoscience Australia' 284 228 fid.description = "description"
Note: See TracChangeset
for help on using the changeset viewer.