Changeset 1044
- Timestamp:
- Mar 8, 2005, 10:19:53 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r1043 r1044 1129 1129 minlon = None, maxlon = None, 1130 1130 mint = None, maxt = None, mean_stage = 0, 1131 origin = None, zscale = 1): 1131 origin = None, zscale = 1, 1132 mean_bathymetry = -100): #FIXME: Bathymetry should be obtained 1133 #from MOST somehow. 1134 #Alternatively from elsewhere 1135 #or, as a last resort, 1136 #specified here. 1137 #The value of -100 will work 1138 #for the Wollongong tsunami 1139 #scenario but is very hacky 1132 1140 """Convert 'Ferret' NetCDF format for wave propagation to 1133 1141 sww format native to pyvolution. … … 1153 1161 ferret2sww uses grid points as vertices in a triangular grid 1154 1162 counting vertices from lower left corner upwards, then right 1155 """ 1163 """ 1156 1164 1157 1165 import os 1158 1166 from Scientific.IO.NetCDF import NetCDFFile 1159 1167 from Numeric import Float, Int, Int32, searchsorted, zeros, array 1160 precision = Float 1168 precision = Float 1161 1169 1162 1170 … … 1165 1173 file_h = NetCDFFile(basename_in + '_ha.nc', 'r') #Wave amplitude (cm) 1166 1174 file_u = NetCDFFile(basename_in + '_ua.nc', 'r') #Velocity (x) (cm/s) 1167 file_v = NetCDFFile(basename_in + '_va.nc', 'r') #Velocity (y) (cm/s) 1175 file_v = NetCDFFile(basename_in + '_va.nc', 'r') #Velocity (y) (cm/s) 1168 1176 1169 1177 if basename_out is None: 1170 1178 swwname = basename_in + '.sww' 1171 1179 else: 1172 swwname = basename_out + '.sww' 1180 swwname = basename_out + '.sww' 1173 1181 1174 1182 times = file_h.variables['TIME'] … … 1178 1186 if mint == None: 1179 1187 jmin = 0 1180 else: 1188 else: 1181 1189 jmin = searchsorted(times, mint) 1182 1190 1183 1191 if maxt == None: 1184 1192 jmax=len(times) 1185 else: 1193 else: 1186 1194 jmax = searchsorted(times, maxt) 1187 1195 1188 1196 if minlat == None: 1189 1197 kmin=0 … … 1198 1206 if minlon == None: 1199 1207 lmin=0 1200 else: 1208 else: 1201 1209 lmin = searchsorted(longitudes, minlon) 1202 1210 1203 1211 if maxlon == None: 1204 1212 lmax = len(longitudes) 1205 1213 else: 1206 lmax = searchsorted(longitudes, maxlon) 1207 1208 times = times[jmin:jmax] 1214 lmax = searchsorted(longitudes, maxlon) 1215 1216 times = times[jmin:jmax] 1209 1217 latitudes = latitudes[kmin:kmax] 1210 1218 longitudes = longitudes[lmin:lmax] … … 1214 1222 amplitudes = file_h.variables['HA'][jmin:jmax, kmin:kmax, lmin:lmax] 1215 1223 xspeed = file_u.variables['UA'][jmin:jmax, kmin:kmax, lmin:lmax] 1216 yspeed = file_v.variables['VA'][jmin:jmax, kmin:kmax, lmin:lmax] 1224 yspeed = file_v.variables['VA'][jmin:jmax, kmin:kmax, lmin:lmax] 1217 1225 1218 1226 number_of_times = times.shape[0] … … 1222 1230 assert amplitudes.shape[0] == number_of_times 1223 1231 assert amplitudes.shape[1] == number_of_latitudes 1224 assert amplitudes.shape[2] == number_of_longitudes 1232 assert amplitudes.shape[2] == number_of_longitudes 1225 1233 1226 1234 #print times … … 1229 1237 1230 1238 #print 'MIN', min(min(min(amplitudes))) 1231 #print 'MAX', max(max(max(amplitudes))) 1239 #print 'MAX', max(max(max(amplitudes))) 1232 1240 1233 1241 #print number_of_latitudes, number_of_longitudes 1234 1242 number_of_points = number_of_latitudes*number_of_longitudes 1235 1243 number_of_volumes = (number_of_latitudes-1)*(number_of_longitudes-1)*2 1236 1244 1237 1245 #print file_h.dimensions.keys() 1238 #print file_h.variables.keys() 1246 #print file_h.variables.keys() 1239 1247 1240 1248 file_h.close() 1241 1249 file_u.close() 1242 file_v.close() 1250 file_v.close() 1243 1251 1244 1252 … … 1246 1254 # NetCDF file definition 1247 1255 outfile = NetCDFFile(swwname, 'w') 1248 1256 1249 1257 #Create new file 1250 1258 outfile.institution = 'Geoscience Australia' … … 1256 1264 1257 1265 #For sww compatibility 1258 outfile.smoothing = 'Yes' 1266 outfile.smoothing = 'Yes' 1259 1267 outfile.order = 1 1260 1268 1261 1269 #Start time in seconds since the epoch (midnight 1/1/1970) 1262 1270 outfile.starttime = times[0] 1263 1271 1264 1272 # dimension definitions 1265 1273 outfile.createDimension('number_of_volumes', number_of_volumes) … … 1267 1275 outfile.createDimension('number_of_vertices', 3) 1268 1276 outfile.createDimension('number_of_points', number_of_points) 1269 1270 1277 1278 1271 1279 #outfile.createDimension('number_of_timesteps', len(times)) 1272 1280 outfile.createDimension('number_of_timesteps', len(times)) … … 1276 1284 outfile.createVariable('y', precision, ('number_of_points',)) 1277 1285 outfile.createVariable('elevation', precision, ('number_of_points',)) 1278 1286 1279 1287 #FIXME: Backwards compatibility 1280 1288 outfile.createVariable('z', precision, ('number_of_points',)) 1281 1289 ################################# 1282 1290 1283 1291 outfile.createVariable('volumes', Int, ('number_of_volumes', 1284 1292 'number_of_vertices')) 1285 1293 1286 1294 outfile.createVariable('time', precision, 1287 1295 ('number_of_timesteps',)) 1288 1296 1289 1297 outfile.createVariable('stage', precision, 1290 1298 ('number_of_timesteps', … … 1294 1302 ('number_of_timesteps', 1295 1303 'number_of_points')) 1296 1304 1297 1305 outfile.createVariable('ymomentum', precision, 1298 1306 ('number_of_timesteps', … … 1308 1316 1309 1317 #Check zone boundaries 1310 refzone, _, _ = redfearn(latitudes[0],longitudes[0]) 1318 refzone, _, _ = redfearn(latitudes[0],longitudes[0]) 1311 1319 1312 1320 vertices = {} 1313 for k, lat in enumerate(latitudes): 1314 for l, lon in enumerate(longitudes): 1321 for k, lat in enumerate(latitudes): 1322 for l, lon in enumerate(longitudes): 1315 1323 1316 1324 vertices[l,k] = i 1317 1325 1318 zone, easting, northing = redfearn(lat,lon) 1326 zone, easting, northing = redfearn(lat,lon) 1319 1327 1320 1328 msg = 'Zone boundary crossed at longitude =', lon … … 1331 1339 for k in range(number_of_latitudes-1): 1332 1340 v1 = vertices[l,k+1] 1333 v2 = vertices[l,k] 1334 v3 = vertices[l+1,k+1] 1335 v4 = vertices[l+1,k] 1341 v2 = vertices[l,k] 1342 v3 = vertices[l+1,k+1] 1343 v4 = vertices[l+1,k] 1336 1344 1337 1345 volumes.append([v1,v2,v3]) #Upper element 1338 volumes.append([v4,v3,v2]) #Lower element 1339 1340 volumes = array(volumes) 1346 volumes.append([v4,v3,v2]) #Lower element 1347 1348 volumes = array(volumes) 1341 1349 1342 1350 if origin == None: 1343 zone = refzone 1351 zone = refzone 1344 1352 xllcorner = min(x) 1345 1353 yllcorner = min(y) … … 1347 1355 zone = origin[0] 1348 1356 xllcorner = origin[1] 1349 yllcorner = origin[2] 1350 1351 1357 yllcorner = origin[2] 1358 1359 1352 1360 outfile.xllcorner = xllcorner 1353 1361 outfile.yllcorner = yllcorner … … 1357 1365 outfile.variables['y'][:] = y - yllcorner 1358 1366 outfile.variables['z'][:] = 0.0 1359 outfile.variables['elevation'][:] = 0.0 1360 outfile.variables['time'][:] = times 1367 outfile.variables['elevation'][:] = 0.0 #Grrrrrrr 1368 outfile.variables['time'][:] = times 1361 1369 outfile.variables['volumes'][:] = volumes.astype(Int32) #On Opteron 64 1362 1370 1363 1371 1364 1372 … … 1366 1374 stage = outfile.variables['stage'] 1367 1375 xmomentum = outfile.variables['xmomentum'] 1368 ymomentum = outfile.variables['ymomentum'] 1369 1376 ymomentum = outfile.variables['ymomentum'] 1377 1378 if mean_bathymetry is not None: 1379 z = mean_bathymetry 1380 else: 1381 pass 1382 #FIXME: z should be obtained from MOST and passed in here 1383 1370 1384 for j in range(len(times)): 1371 1385 i = 0 1372 1386 for k in range(number_of_latitudes): 1373 for l in range(number_of_longitudes): 1374 h = zscale*amplitudes[j,k,l]/100 + mean_stage 1375 stage[j,i] = h 1376 xmomentum[j,i] = xspeed[j,k,l]/100*h 1377 ymomentum[j,i] = yspeed[j,k,l]/100*h 1387 for l in range(number_of_longitudes): 1388 w = zscale*amplitudes[j,k,l]/100 + mean_stage 1389 stage[j,i] = w 1390 1391 h = w-z 1392 1393 xmomentum[j,i] = xspeed[j,k,l]/100*h 1394 ymomentum[j,i] = yspeed[j,k,l]/100*h 1378 1395 i += 1 1379 1380 outfile.close() 1396 1397 outfile.close() 1398 1381 1399 1382 1400 -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r1018 r1044 602 602 603 603 fid = NetCDFFile('small_ha.nc') 604 605 604 first_value = fid.variables['HA'][:][0,0,0] 606 605 fourth_value = fid.variables['HA'][:][0,0,3] 606 607 607 608 608 #Call conversion (with zero origin) … … 627 627 #Check first value 628 628 stage = fid.variables['stage'][:] 629 629 xmomentum = fid.variables['xmomentum'][:] 630 ymomentum = fid.variables['ymomentum'][:] 631 632 #print ymomentum 633 630 634 assert allclose(stage[0,0], first_value/100) #Meters 631 635
Note: See TracChangeset
for help on using the changeset viewer.