1 | |
---|
2 | |
---|
3 | def prepare_timeboundary(filename): |
---|
4 | """Converting tide time series to NetCDF tms file. |
---|
5 | This is a 'throw-away' code taylor made for files like |
---|
6 | 'Benchmark_2_input.txt' from the LWRU2 benchmark |
---|
7 | """ |
---|
8 | |
---|
9 | print 'Preparing time boundary from %s' %filename |
---|
10 | from Numeric import array, zeros, Float, asarray |
---|
11 | |
---|
12 | fid = open(filename) |
---|
13 | |
---|
14 | #Skip first line |
---|
15 | line = fid.readline() |
---|
16 | |
---|
17 | #Read remaining lines |
---|
18 | lines = fid.readlines() |
---|
19 | fid.close() |
---|
20 | |
---|
21 | |
---|
22 | N = len(lines) |
---|
23 | T = zeros(N, Float) #Time |
---|
24 | Q = zeros(N, Float) #Values |
---|
25 | |
---|
26 | Told = 0.0 |
---|
27 | Sold = ' ' |
---|
28 | Lold = ' ' |
---|
29 | for i, line in enumerate(lines): |
---|
30 | fields = line.split() |
---|
31 | |
---|
32 | #print fields |
---|
33 | |
---|
34 | l_time = (fields[0]+' '+fields[1])[0:-1] |
---|
35 | from time import strptime, mktime |
---|
36 | |
---|
37 | s_time = strptime(l_time,'%d/%m/%y %H:%M:%S') |
---|
38 | |
---|
39 | #print s_time |
---|
40 | |
---|
41 | T[i] = float(mktime(s_time)) |
---|
42 | |
---|
43 | if i==0: |
---|
44 | Tstart = T[0] |
---|
45 | |
---|
46 | T[i] = T[i] - Tstart |
---|
47 | #this is specific to this data set. deals with daylight saving |
---|
48 | if i>3270: |
---|
49 | T[i] = T[i]+3600 |
---|
50 | |
---|
51 | if T[i]<Told : |
---|
52 | print Lold |
---|
53 | print l_time |
---|
54 | print Sold |
---|
55 | print s_time |
---|
56 | print Told |
---|
57 | print T[i] |
---|
58 | print i, T[i]-Told |
---|
59 | |
---|
60 | Q[i] = float(fields[2]) |
---|
61 | |
---|
62 | Told = T[i] |
---|
63 | Sold = s_time |
---|
64 | Lold = l_time |
---|
65 | |
---|
66 | |
---|
67 | #Create tms file |
---|
68 | from Scientific.IO.NetCDF import NetCDFFile |
---|
69 | |
---|
70 | outfile = filename[:-4] + '.tms' |
---|
71 | print 'Writing to', outfile |
---|
72 | fid = NetCDFFile(outfile, 'w') |
---|
73 | |
---|
74 | fid.institution = 'Australian National University' |
---|
75 | fid.description = 'Input wave for Merimbula' |
---|
76 | fid.starttime = 0.0 |
---|
77 | fid.createDimension('number_of_timesteps', len(T)) |
---|
78 | fid.createVariable('time', Float, ('number_of_timesteps',)) |
---|
79 | fid.variables['time'][:] = T |
---|
80 | |
---|
81 | fid.createVariable('stage', Float, ('number_of_timesteps',)) |
---|
82 | fid.variables['stage'][:] = Q[:] |
---|
83 | |
---|
84 | fid.createVariable('xmomentum', Float, ('number_of_timesteps',)) |
---|
85 | fid.variables['xmomentum'][:] = 0.0 |
---|
86 | |
---|
87 | fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) |
---|
88 | fid.variables['ymomentum'][:] = 0.0 |
---|
89 | |
---|
90 | fid.close() |
---|
91 | |
---|
92 | |
---|
93 | #------------------------------------------------------------- |
---|
94 | if __name__ == "__main__": |
---|
95 | import project |
---|
96 | print 'Prepare Open sea boundary condition from ',project.original_boundary_filename |
---|
97 | prepare_timeboundary(project.original_boundary_filename ) |
---|
98 | |
---|
99 | #Preparing points |
---|
100 | print 'Prepare bathymetry from xya file ',project.bathymetry_filename |
---|
101 | from pyvolution.data_manager import xya2pts |
---|
102 | xya2pts(project.bathymetry_filename, verbose = True) |
---|
103 | |
---|
104 | |
---|
105 | # fit_to_mesh_file(mesh_file, point_file, mesh_output_file, |
---|
106 | # alpha=DEFAULT_ALPHA, verbose= False, |
---|
107 | # expand_search = False, |
---|
108 | # data_origin = None, |
---|
109 | # mesh_origin = None, |
---|
110 | # precrop = False, |
---|
111 | # display_errors = True): |
---|