source: anuga_validation/Hinwood_2008/prepare_time_boundary.py @ 5686

Last change on this file since 5686 was 5686, checked in by duncan, 16 years ago

Simplifying files

File size: 2.0 KB
Line 
1"""
2Script for running a breaking wave simulation of Jon Hinwoods wave tank.
3Note: this is based on the frinction_ua_flume_2006 structure.
4
5
6Duncan Gray, GA - 2007
7
8"""
9
10
11#----------------------------------------------------------------------------
12# Import necessary modules
13#----------------------------------------------------------------------------
14
15from Scientific.IO.NetCDF import NetCDFFile
16from Numeric import zeros, Float
17 
18from anuga.utilities.numerical_tools import ensure_numeric
19from anuga.utilities.interp import interp
20
21
22def 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
33    # Read remaining lines
34    lines = fid.readlines()
35    fid.close()
36
37    N = len(lines)
38    T = zeros(N, Float)  #Time
39    Q = zeros(N, Float)  #Stage
40    X = zeros(N, Float)  #XMomentum
41    Y = zeros(N, Float)  #YMomentum
42
43    for i, line in enumerate(lines):
44        fields = line.split(',')
45
46        T[i] = float(fields[0])
47        Q[i] = float(fields[1])
48        depth = Q[i] - offshore_bed_elevation
49        X[i] = float(fields[2]) * depth
50        Y[i] = float(fields[3]) * depth
51   
52    # Create tms NetCDF file
53    fid = NetCDFFile(filename, 'w')
54    fid.institution = 'Geoscience Australia'
55    fid.description = 'Input wave for Benchmark 2'
56    fid.starttime = 0.0
57    fid.createDimension('number_of_timesteps', len(T))
58    fid.createVariable('time', Float, ('number_of_timesteps',))
59    fid.variables['time'][:] = T
60
61    fid.createVariable('stage', Float, ('number_of_timesteps',))
62    fid.variables['stage'][:] = Q[:]
63
64    fid.createVariable('xmomentum', Float, ('number_of_timesteps',))
65    fid.variables['xmomentum'][:] =  X[:]
66
67    fid.createVariable('ymomentum', Float, ('number_of_timesteps',))
68    fid.variables['ymomentum'][:] =  Y[:]
69
70    fid.close()
Note: See TracBrowser for help on using the repository browser.