Changeset 7794
- Timestamp:
- Jun 7, 2010, 9:38:23 AM (15 years ago)
- Location:
- branches/anuga_1_1/anuga_work/production/bunbury_storm_surge_2009
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/anuga_1_1/anuga_work/production/bunbury_storm_surge_2009/build_gems_boundary.py
r7678 r7794 13 13 import sys 14 14 # sys.path.append('W:\\sandpits\\lfountain\\anuga_work\\production\\mandurah_storm_surge_2009\\gems_comparison') 15 sys.path.append('/nas/gemd/georisk_models/inundation/sandpits/lfountain/anuga_work/production/mandurah_storm_surge_2009/gems_comparison')16 import project _GEMS_grid15 #sys.path.append('/nas/gemd/georisk_models/inundation/sandpits/lfountain/anuga_work/production/mandurah_storm_surge_2009/gems_comparison') 16 import project 17 17 from Scientific.IO.NetCDF import NetCDFFile 18 18 from anuga.coordinate_transforms.geo_reference import Geo_reference, write_NetCDF_georeference … … 23 23 state = 'western_australia' 24 24 scenario_folder = 'bunbury_storm_surge_scenario_2009' 25 event = ' case_1' # Baseline TC Alby event25 event = '20100527_gcom_12min' # Baseline TC Alby event 26 26 27 27 ENV_INUNDATIONHOME = 'INUNDATIONHOME' … … 35 35 # Define boundary points to extract from master STS file 36 36 #-------------------------------------------------------- 37 gems_boundary = numpy.array(read_polygon(project_GEMS_grid.gems_order)) 37 gems_boundary = numpy.array(read_polygon(project.gems_order)) 38 #gems_boundary = numpy.array(read_polygon(project.gauges)) 38 39 number_of_points = gems_boundary.shape[0] 40 print 'hello', number_of_points 41 print 'points', gems_boundary 39 42 40 43 #--------------------------------------------------------- … … 42 45 #--------------------------------------------------------- 43 46 print "Reading master NetCDF file" 44 infile = NetCDFFile(os.path.join(event_folder, event + '_master .sts'), 'r')47 infile = NetCDFFile(os.path.join(event_folder, event + '_master_2_1.sts'), 'rl') #rl for large netcdf files 45 48 46 49 grid_size = infile.grid_size … … 69 72 origin = numpy.array([x_origin[0], y_origin[0]]) 70 73 index_array_2D = ((gems_boundary - origin)/grid_size).astype(int) 71 assert index_array_2D[:,0].min() >= 0 and index_array_2D[:,0].max() <= ncols 74 assert index_array_2D[:,0].min() >= 0 and index_array_2D[:,0].max() <= ncols # These test that the boundary points lie within the data area 72 75 assert index_array_2D[:,1].min() >= 0 and index_array_2D[:,1].max() <= nrows 73 76 … … 135 138 s[i] = stage[i,:] 136 139 xm[i] = xmomentum[i,:] 137 ym[i] = ymomentum[i,:] 138 140 ym[i] = ymomentum[i,:] 141 142 #--------------------------------------------------------------------------- 143 # Get timeseries values for wave height and components of momentum 144 #--------------------------------------------------------------------------- 145 146 basename = 'sts_gauge_tide' 147 for i in xrange(number_of_points): 148 out_file = os.path.join(event_folder, 149 basename+'_'+str(i)+'.csv') 150 fid_sts = open(out_file, 'w') 151 fid_sts.write('time, stage, xmomentum, ymomentum, elevation \n') 152 for j in xrange(number_of_timesteps): 153 fid_sts.write('%.6f, %.6f, %.6f, %.6f, %.6f\n' 154 % (time[j], stage[j,i], xmomentum[j,i], ymomentum[j,i], elevation[i])) 155 156 fid_sts.close() 157 139 158 origin = Geo_reference(refzone, x_origin, y_origin) 140 159 geo_ref = write_NetCDF_georeference(origin, fid) 141 160 142 161 fid.variables['x'][:] = x 143 fid.variables['y'][:] = y 162 fid.variables['y'][:] = y 144 163 145 164 fid.close() 165 166 sys.exit() 167 168 print 'get timeseries' 169 #------------------------------------------------------------------------------- 170 # Get gauges (timeseries of index points) 171 #------------------------------------------------------------------------------- 172 173 basename = 'sts_gauge' 174 quantity_names = ['stage', 'xmomentum', 'ymomentum'] 175 quantities = {} 176 for i, name in enumerate(quantity_names): 177 quantities[name] = fid.variables[name][:] 178 179 180 for j in range(len(x)): 181 index = j # permutation[j] 182 stage = quantities['stage'][:,j] 183 #print 'hello', j, stage 184 xmomentum = quantities['xmomentum'][:,j] 185 ymomentum = quantities['ymomentum'][:,j] 186 187 out_file = os.path.join(event_folder, 188 basename+'_'+str(index)+'.csv') 189 fid_sts = open(out_file, 'w') 190 fid_sts.write('time, stage, xmomentum, ymomentum \n') 191 192 #----------------------------------------------------------------------- 193 # End of the get gauges 194 #----------------------------------------------------------------------- 195 for k in range(len(time)-1): 196 fid_sts.write('%.6f, %.6f, %.6f, %.6f\n' 197 % (time[k], stage[k], xmomentum[k], ymomentum[k])) 198 199 -
branches/anuga_1_1/anuga_work/production/bunbury_storm_surge_2009/process_gems_grids.py
r7723 r7794 22 22 state = 'western_australia' 23 23 scenario_folder = 'bunbury_storm_surge_scenario_2009' 24 event = ' gcom_60min'24 event = '20100527_gcom_12min' 25 25 26 26 print "Processing event: ", event … … 45 45 grid_file_names.sort() 46 46 47 grid_file_names_temp = [] 48 for i in range(1, 32, 1): 49 grid_file_names_temp.append(grid_file_names[i]) 50 51 grid_file_names = grid_file_names_temp 47 #grid_file_names_temp = [] 48 # this was to subsample the gz files 49 #for i in range(1, 32, 1): 50 # grid_file_names_temp.append(grid_file_names[i]) 51 52 #grid_file_names = grid_file_names_temp 52 53 53 54 number_of_timesteps = len(grid_file_names) … … 56 57 57 58 start_time = 0 # all times in seconds 58 timestep = 3600 #1440 #720 # all times in seconds59 timestep = 720 # all times in seconds 59 60 end_time = start_time + (timestep*number_of_timesteps) # all times in seconds 60 61 refzone = 50 # UTM zone of model … … 93 94 94 95 #------------------------------------------------------ 95 # Create arrays of elevation, stage, speed and theta96 # Create arrays of elevation, depth, current_x and current_y 96 97 #------------------------------------------------------- 97 print 'creating numpy arrays: elevation, stage, speed, theta'98 99 stage= numpy.empty(number_of_timesteps*nrows*ncols, dtype=float)100 speed= numpy.empty(number_of_timesteps*nrows*ncols, dtype=float)101 theta= numpy.empty(number_of_timesteps*nrows*ncols, dtype=float)98 print 'creating numpy arrays: elevation, depth, current_x, current_y' 99 100 depth = numpy.empty(number_of_timesteps*nrows*ncols, dtype=float) 101 current_x = numpy.empty(number_of_timesteps*nrows*ncols, dtype=float) 102 current_y = numpy.empty(number_of_timesteps*nrows*ncols, dtype=float) 102 103 103 104 for j, f in enumerate(grid_file_names): … … 106 107 gz_file = gzip.open(f, 'rb') 107 108 108 st= []109 sp= []110 t= []109 d = [] 110 cx = [] 111 cy = [] 111 112 112 113 for i, L in enumerate(gz_file): 113 114 114 if i > 7 and i < (8 + nrows): # 7 refers to the number of rows of header info that we skip - always CHECK format 115 st += L.strip().split() 115 #if i > 7 and i < (8 + nrows): # 7 refers to the number of rows of header info that we skip - always CHECK format 116 # print 'first block' 117 118 #if i > (9 + nrows) and i < (10 + 2*nrows): 119 # print 'second block' 120 121 #if i > (11 + 2*nrows): 122 # print 'third block' 123 124 if i > 13 + 3*nrows and i < (14 + 4*nrows): 125 d += L.strip().split() 116 126 117 if i > ( 9 + nrows) and i < (10 + 2*nrows):118 sp+= L.strip().split()127 if i > (15 + 4*nrows) and i < (16 + 5*nrows): 128 cx += L.strip().split() 119 129 120 if i > (1 1 + 2*nrows):121 t+= L.strip().split()122 123 stage[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(st).astype('d'))124 speed[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(sp).astype('d'))125 theta[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(t).astype('d'))130 if i > (17 + 5*nrows): 131 cy += L.strip().split() 132 133 depth[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(d).astype('d')) 134 current_x[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(cx).astype('d')) 135 current_y[j*nrows*ncols : (j+1)*nrows*ncols] = numpy.flipud(numpy.array(cy).astype('d')) 126 136 127 137 gz_file.close() … … 130 140 131 141 print 'Size of elevation array: ', elevation.size 132 print 'Size of stage array: ', stage.size133 print 'Size of speed array: ', speed.size134 print 'Size of theta array: ', theta.size135 136 assert stage.size == speed.size == theta.size == ncols * nrows * number_of_timesteps137 assert stage.size == number_of_timesteps * elevation.size138 139 depth = numpy.empty(stage.size, dtype='d')142 print 'Size of depth array: ', depth.size 143 print 'Size of current x array: ', current_x.size 144 print 'Size of current y array: ', current_y.size 145 146 assert depth.size == current_x.size == current_y.size == ncols * nrows * number_of_timesteps 147 assert depth.size == number_of_timesteps * elevation.size 148 149 stage = numpy.empty(depth.size, dtype='d') 140 150 number_of_points = ncols * nrows 141 151 142 152 # --------------------------------------------- 143 # Create mask of no_data values across stage, speed and thetato ensure all three quantities153 # Create mask of no_data values across depth, current_x and current_y to ensure all three quantities 144 154 # have no_data values in corresponding cells - this is a work-around until GEMS can produce a 145 155 # a consistant dataset 146 156 # --------------------------------------------- 147 import pdb 148 pdb.set_trace() 149 no_value_index = numpy.where(((stage < -100) + (speed < 0) + (theta < 0)) == True)[0] 150 depth = stage - numpy.tile(elevation, number_of_timesteps) 157 158 no_value_index = numpy.where(((depth < -9000) + (current_x < -9000) + (current_y < -9000)) == True)[0] 151 159 152 160 numpy.put(stage, no_value_index, -9999) 153 numpy.put( speed, no_value_index, -9999)154 numpy.put( theta, no_value_index, -9999)161 numpy.put(current_x, no_value_index, -9999) 162 numpy.put(current_y, no_value_index, -9999) 155 163 numpy.put(depth, no_value_index, 0) 156 164 157 # Taking absolute value is to account for -ve depths obtained when stage-elevation165 # Taking absolute value is to account for -ve depths obtained when depth-elevation 158 166 # is slightly -ve - why I don't know, possbly a rounding error? 159 momentum = numpy.absolute(depth * speed) 160 161 print 'Calculating xmomentum and ymomentum' 162 163 xmomentum = momentum*numpy.sin(numpy.radians(theta)) 164 ymomentum = momentum*numpy.cos(numpy.radians(theta)) 167 #momentum = numpy.absolute(depth * current_x) 168 169 print 'Calculating stage, xmomentum and ymomentum' 170 171 #stage = depth - numpy.tile(numpy.absolute(elevation), number_of_timesteps) 172 stage = depth + numpy.tile(elevation, number_of_timesteps) 173 xmomentum = current_x*depth #momentum*numpy.sin(numpy.radians(current_y)) 174 ymomentum = current_y*depth #momentum*numpy.cos(numpy.radians(current_y)) 165 175 166 176 numpy.put(xmomentum, no_value_index, 0) 167 177 numpy.put(ymomentum, no_value_index, 0) 168 178 169 # if t > 0.0 and t < 90.0: 170 # assert mx >= 0 and my >= 0 171 172 # elif t > 90.0 and t < 180.0: 173 # assert mx >= 0 and my <= 0 174 175 # elif t > 180.0 and t < 270.0: 176 # assert mx <= 0 and my <= 0 177 178 # elif t > 270.0 and t < 360.0: 179 # assert mx <= 0 and my >= 0 180 181 # elif t == 0.0 or t == 360.0: 182 # assert my >= 0 183 184 # elif t == 90.0: 185 # assert mx >= 0 186 187 # elif t == 180.0: 188 # assert my <= 0 189 190 # elif t == 270.0: 191 # assert mx <= 0 192 193 # elif t == -9999: 194 # mx = 0 195 # my = 0 196 # else: 197 # print "Unexpected value of theta" 198 # exit() 199 200 # xmomentum[i] = mx 201 # ymomentum[i] = my 202 203 assert len(numpy.where((numpy.sqrt(xmomentum**2 + ymomentum**2) - momentum) > 1.e-06)[0]) == 0 179 #assert len(numpy.where((numpy.sqrt(xmomentum**2 + ymomentum**2) - momentum) > 1.e-06)[0]) == 0 204 180 205 181 x_origin_int = int(10000*x_origin) … … 215 191 216 192 assert time.size == number_of_timesteps 217 assert momentum.size == stage.size193 assert xmomentum.size == depth.size == ymomentum.size 218 194 219 195 # -----------------------------
Note: See TracChangeset
for help on using the changeset viewer.