Changeset 1044


Ignore:
Timestamp:
Mar 8, 2005, 10:19:53 PM (20 years ago)
Author:
ole
Message:

Added temporary fix for momentum computation in ferret2sww

Location:
inundation/ga/storm_surge/pyvolution
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/pyvolution/data_manager.py

    r1043 r1044  
    11291129               minlon = None, maxlon = None,
    11301130               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
    11321140    """Convert 'Ferret' NetCDF format for wave propagation to
    11331141    sww format native to pyvolution.
     
    11531161    ferret2sww uses grid points as vertices in a triangular grid
    11541162    counting vertices from lower left corner upwards, then right
    1155     """
     1163    """ 
    11561164
    11571165    import os
    11581166    from Scientific.IO.NetCDF import NetCDFFile
    11591167    from Numeric import Float, Int, Int32, searchsorted, zeros, array
    1160     precision = Float
     1168    precision = Float 
    11611169
    11621170
     
    11651173    file_h = NetCDFFile(basename_in + '_ha.nc', 'r') #Wave amplitude (cm)
    11661174    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)   
    11681176
    11691177    if basename_out is None:
    11701178        swwname = basename_in + '.sww'
    11711179    else:
    1172         swwname = basename_out + '.sww'
     1180        swwname = basename_out + '.sww'       
    11731181
    11741182    times = file_h.variables['TIME']
     
    11781186    if mint == None:
    11791187        jmin = 0
    1180     else:
     1188    else:   
    11811189        jmin = searchsorted(times, mint)
    1182 
     1190   
    11831191    if maxt == None:
    11841192        jmax=len(times)
    1185     else:
     1193    else:   
    11861194        jmax = searchsorted(times, maxt)
    1187 
     1195       
    11881196    if minlat == None:
    11891197        kmin=0
     
    11981206    if minlon == None:
    11991207        lmin=0
    1200     else:
     1208    else:   
    12011209        lmin = searchsorted(longitudes, minlon)
    1202 
     1210   
    12031211    if maxlon == None:
    12041212        lmax = len(longitudes)
    12051213    else:
    1206         lmax = searchsorted(longitudes, maxlon)
    1207 
    1208     times = times[jmin:jmax]
     1214        lmax = searchsorted(longitudes, maxlon)           
     1215
     1216    times = times[jmin:jmax]       
    12091217    latitudes = latitudes[kmin:kmax]
    12101218    longitudes = longitudes[lmin:lmax]
     
    12141222    amplitudes = file_h.variables['HA'][jmin:jmax, kmin:kmax, lmin:lmax]
    12151223    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]   
    12171225
    12181226    number_of_times = times.shape[0]
     
    12221230    assert amplitudes.shape[0] == number_of_times
    12231231    assert amplitudes.shape[1] == number_of_latitudes
    1224     assert amplitudes.shape[2] == number_of_longitudes
     1232    assert amplitudes.shape[2] == number_of_longitudes         
    12251233
    12261234    #print times
     
    12291237
    12301238    #print 'MIN', min(min(min(amplitudes)))
    1231     #print 'MAX', max(max(max(amplitudes)))
     1239    #print 'MAX', max(max(max(amplitudes)))   
    12321240
    12331241    #print number_of_latitudes, number_of_longitudes
    12341242    number_of_points = number_of_latitudes*number_of_longitudes
    12351243    number_of_volumes = (number_of_latitudes-1)*(number_of_longitudes-1)*2
    1236 
     1244   
    12371245    #print file_h.dimensions.keys()
    1238     #print file_h.variables.keys()
     1246    #print file_h.variables.keys()   
    12391247
    12401248    file_h.close()
    12411249    file_u.close()
    1242     file_v.close()
     1250    file_v.close()   
    12431251
    12441252
     
    12461254    # NetCDF file definition
    12471255    outfile = NetCDFFile(swwname, 'w')
    1248 
     1256       
    12491257    #Create new file
    12501258    outfile.institution = 'Geoscience Australia'
     
    12561264
    12571265    #For sww compatibility
    1258     outfile.smoothing = 'Yes'
     1266    outfile.smoothing = 'Yes' 
    12591267    outfile.order = 1
    1260 
     1268           
    12611269    #Start time in seconds since the epoch (midnight 1/1/1970)
    12621270    outfile.starttime = times[0]
    1263 
     1271   
    12641272    # dimension definitions
    12651273    outfile.createDimension('number_of_volumes', number_of_volumes)
     
    12671275    outfile.createDimension('number_of_vertices', 3)
    12681276    outfile.createDimension('number_of_points', number_of_points)
    1269 
    1270 
     1277                           
     1278               
    12711279    #outfile.createDimension('number_of_timesteps', len(times))
    12721280    outfile.createDimension('number_of_timesteps', len(times))
     
    12761284    outfile.createVariable('y', precision, ('number_of_points',))
    12771285    outfile.createVariable('elevation', precision, ('number_of_points',))
    1278 
     1286           
    12791287    #FIXME: Backwards compatibility
    12801288    outfile.createVariable('z', precision, ('number_of_points',))
    12811289    #################################
    1282 
     1290       
    12831291    outfile.createVariable('volumes', Int, ('number_of_volumes',
    12841292                                            'number_of_vertices'))
    1285 
     1293   
    12861294    outfile.createVariable('time', precision,
    12871295                           ('number_of_timesteps',))
    1288 
     1296       
    12891297    outfile.createVariable('stage', precision,
    12901298                           ('number_of_timesteps',
     
    12941302                           ('number_of_timesteps',
    12951303                            'number_of_points'))
    1296 
     1304   
    12971305    outfile.createVariable('ymomentum', precision,
    12981306                           ('number_of_timesteps',
     
    13081316
    13091317    #Check zone boundaries
    1310     refzone, _, _ = redfearn(latitudes[0],longitudes[0])
     1318    refzone, _, _ = redfearn(latitudes[0],longitudes[0])   
    13111319
    13121320    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):   
    13151323
    13161324            vertices[l,k] = i
    13171325
    1318             zone, easting, northing = redfearn(lat,lon)
     1326            zone, easting, northing = redfearn(lat,lon)               
    13191327
    13201328            msg = 'Zone boundary crossed at longitude =', lon
     
    13311339        for k in range(number_of_latitudes-1):
    13321340            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]           
    13361344
    13371345            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)       
    13411349
    13421350    if origin == None:
    1343         zone = refzone
     1351        zone = refzone       
    13441352        xllcorner = min(x)
    13451353        yllcorner = min(y)
     
    13471355        zone = origin[0]
    13481356        xllcorner = origin[1]
    1349         yllcorner = origin[2]
    1350 
    1351 
     1357        yllcorner = origin[2]               
     1358
     1359   
    13521360    outfile.xllcorner = xllcorner
    13531361    outfile.yllcorner = yllcorner
     
    13571365    outfile.variables['y'][:] = y - yllcorner
    13581366    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       
    13611369    outfile.variables['volumes'][:] = volumes.astype(Int32) #On Opteron 64
    1362 
     1370   
    13631371
    13641372
     
    13661374    stage = outfile.variables['stage']
    13671375    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   
    13701384    for j in range(len(times)):
    13711385        i = 0
    13721386        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               
    13781395                i += 1
    1379 
    1380     outfile.close()
     1396       
     1397    outfile.close()               
     1398   
    13811399
    13821400
  • inundation/ga/storm_surge/pyvolution/test_data_manager.py

    r1018 r1044  
    602602
    603603        fid = NetCDFFile('small_ha.nc')
    604 
    605604        first_value = fid.variables['HA'][:][0,0,0]
    606605        fourth_value = fid.variables['HA'][:][0,0,3]
     606
    607607
    608608        #Call conversion (with zero origin)
     
    627627        #Check first value
    628628        stage = fid.variables['stage'][:]
    629 
     629        xmomentum = fid.variables['xmomentum'][:]
     630        ymomentum = fid.variables['ymomentum'][:]       
     631
     632        #print ymomentum
     633               
    630634        assert allclose(stage[0,0], first_value/100)  #Meters
    631635
Note: See TracChangeset for help on using the changeset viewer.