source: anuga_validation/Hinwood_2008/prepare_time_boundary.py @ 5716

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

comments mainly

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