[5686] | 1 | """ |
---|
| 2 | Script for running a breaking wave simulation of Jon Hinwoods wave tank. |
---|
| 3 | Note: this is based on the frinction_ua_flume_2006 structure. |
---|
| 4 | |
---|
| 5 | |
---|
| 6 | Duncan Gray, GA - 2007 |
---|
| 7 | |
---|
| 8 | """ |
---|
| 9 | |
---|
| 10 | |
---|
| 11 | #---------------------------------------------------------------------------- |
---|
| 12 | # Import necessary modules |
---|
| 13 | #---------------------------------------------------------------------------- |
---|
| 14 | |
---|
| 15 | from Scientific.IO.NetCDF import NetCDFFile |
---|
| 16 | from Numeric import zeros, Float |
---|
| 17 | |
---|
| 18 | from anuga.utilities.numerical_tools import ensure_numeric |
---|
| 19 | from anuga.utilities.interp import interp |
---|
| 20 | |
---|
| 21 | |
---|
| 22 | def csv2tms(filename, offshore_bed_elevation): |
---|
| 23 | """Convert benchmark 2 time series to NetCDF tms file. |
---|
| 24 | the filename is the name of the output tms file, eg 'hi.tsm'. |
---|
| 25 | There must be an equivalent .csv file, eg 'hi.csv'. |
---|
| 26 | |
---|
| 27 | """ |
---|
| 28 | print 'Creating', filename |
---|
| 29 | |
---|
| 30 | # Read the ascii (.csv) version of this file |
---|
| 31 | fid = open(filename[:-4] + '.csv') |
---|
| 32 | |
---|
[5691] | 33 | #Skip first line |
---|
| 34 | line = fid.readline() |
---|
| 35 | |
---|
[5686] | 36 | # Read remaining lines |
---|
| 37 | lines = fid.readlines() |
---|
| 38 | fid.close() |
---|
| 39 | |
---|
| 40 | N = len(lines) |
---|
| 41 | T = zeros(N, Float) #Time |
---|
| 42 | Q = zeros(N, Float) #Stage |
---|
| 43 | X = zeros(N, Float) #XMomentum |
---|
| 44 | Y = zeros(N, Float) #YMomentum |
---|
| 45 | |
---|
| 46 | for i, line in enumerate(lines): |
---|
| 47 | fields = line.split(',') |
---|
| 48 | |
---|
| 49 | T[i] = float(fields[0]) |
---|
| 50 | Q[i] = float(fields[1]) |
---|
| 51 | depth = Q[i] - offshore_bed_elevation |
---|
| 52 | X[i] = float(fields[2]) * depth |
---|
| 53 | Y[i] = float(fields[3]) * depth |
---|
| 54 | |
---|
| 55 | # Create tms NetCDF file |
---|
| 56 | fid = NetCDFFile(filename, 'w') |
---|
| 57 | fid.institution = 'Geoscience Australia' |
---|
| 58 | fid.description = 'Input wave for Benchmark 2' |
---|
| 59 | fid.starttime = 0.0 |
---|
| 60 | fid.createDimension('number_of_timesteps', len(T)) |
---|
| 61 | fid.createVariable('time', Float, ('number_of_timesteps',)) |
---|
| 62 | fid.variables['time'][:] = T |
---|
| 63 | |
---|
| 64 | fid.createVariable('stage', Float, ('number_of_timesteps',)) |
---|
| 65 | fid.variables['stage'][:] = Q[:] |
---|
| 66 | |
---|
| 67 | fid.createVariable('xmomentum', Float, ('number_of_timesteps',)) |
---|
| 68 | fid.variables['xmomentum'][:] = X[:] |
---|
| 69 | |
---|
| 70 | fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) |
---|
| 71 | fid.variables['ymomentum'][:] = Y[:] |
---|
| 72 | |
---|
| 73 | fid.close() |
---|