source: anuga_work/production/australia_ph2/hobart/prepare_timeboundary.py @ 6461

Last change on this file since 6461 was 6461, checked in by kristy, 14 years ago

New scripts added to make tms file

File size: 1.9 KB
Line 
1def prepare_timeboundary(file_in):
2    """Convert benchmark 2 time series to NetCDF tms file.
3    input file is a csv created by build_boundary.py
4    """
5    from Numeric import array, zeros, Float, allclose
6    from Scientific.IO.NetCDF import NetCDFFile
7    from Numeric import array
8    import project
9    from os import sep
10
11    boundary_csv = file_in
12    boundary_tms = boundary_csv[:-4] + '.tms'
13    print 'Creating', boundary_tms
14
15    # Read the ascii (.txt) version of this file
16    fid = open(file_in)
17
18    # Skip first line
19    line = fid.readline()
20
21    # Read remaining lines
22    lines = fid.readlines()
23    fid.close()
24   
25
26    N = len(lines)
27    T = zeros(N, Float)  #Time
28    H = zeros(N, Float)  #Values
29    X = zeros(N, Float)  #Values
30    Y = zeros(N, Float)  #Values
31
32    for i, line in enumerate(lines):
33        fields = line.split(',')
34
35        T[i] = float(fields[0])  #time
36        H[i] = float(fields[1])  #stage
37        X[i] = float(fields[2])  #x-momentum
38        Y[i] = float(fields[3])  #y-momentum
39
40
41    # Create tms NetCDF file
42   
43    fid = NetCDFFile(boundary_tms, 'w')
44    fid.institution = 'Geoscience Australia'
45    fid.description = 'Input wave from index %i' %project.index
46    fid.starttime = T[0]
47    fid.createDimension('number_of_timesteps', len(T))
48    fid.createVariable('time', Float, ('number_of_timesteps',))
49    fid.variables['time'][:] = T-T[0]
50
51    fid.createVariable('stage', Float, ('number_of_timesteps',))
52    fid.variables['stage'][:] = H
53
54    fid.createVariable('xmomentum', Float, ('number_of_timesteps',))
55    fid.variables['xmomentum'][:] = X
56
57    fid.createVariable('ymomentum', Float, ('number_of_timesteps',))
58    fid.variables['ymomentum'][:] = Y
59
60    fid.close()
61
62
63
64##
65###-------------------------------------------------------------
66##if __name__ == "__main__":
67##
68
Note: See TracBrowser for help on using the repository browser.