1 | |
---|
2 | |
---|
3 | def prepare_wind_stress(filename): |
---|
4 | """Converting wind timeseries 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 wind timeseries %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 | S = zeros(N, Float) #Speed |
---|
25 | B = zeros(N, Float) #Bearing |
---|
26 | |
---|
27 | Told = 0.0 |
---|
28 | Sold = ' ' |
---|
29 | Lold = ' ' |
---|
30 | |
---|
31 | for i, line in enumerate(lines): |
---|
32 | fields = line.split() |
---|
33 | |
---|
34 | #print fields |
---|
35 | |
---|
36 | l_time = (fields[0]+' '+fields[1])[0:-1] |
---|
37 | from time import strptime, mktime |
---|
38 | |
---|
39 | s_time = strptime(l_time,'%d/%m/%y %H:%M:%S') |
---|
40 | |
---|
41 | #print s_time |
---|
42 | |
---|
43 | T[i] = float(mktime(s_time)) |
---|
44 | |
---|
45 | if i==0: |
---|
46 | Tstart = T[0] |
---|
47 | |
---|
48 | T[i] = T[i] - Tstart |
---|
49 | #this is specific to this data set. deals with daylight saving |
---|
50 | # if i>3270: |
---|
51 | # T[i] = T[i]+3600 |
---|
52 | # |
---|
53 | if T[i]<Told : |
---|
54 | print Lold |
---|
55 | print l_time |
---|
56 | print Sold |
---|
57 | print s_time |
---|
58 | print Told |
---|
59 | print T[i] |
---|
60 | print i, T[i]-Told |
---|
61 | |
---|
62 | S[i] = float(fields[2]) |
---|
63 | B[i] = float(fields[3]) |
---|
64 | |
---|
65 | Told = T[i] |
---|
66 | Sold = s_time |
---|
67 | Lold = l_time |
---|
68 | |
---|
69 | |
---|
70 | #print T |
---|
71 | #Create tms file |
---|
72 | from Scientific.IO.NetCDF import NetCDFFile |
---|
73 | |
---|
74 | outfile = filename[:-4] + '.tms' |
---|
75 | print 'Writing to', outfile |
---|
76 | fid = NetCDFFile(outfile, 'w') |
---|
77 | |
---|
78 | fid.institution = 'Australian National University' |
---|
79 | fid.description = 'Input wind for Merimbula' |
---|
80 | fid.starttime = 0.0 |
---|
81 | fid.createDimension('number_of_timesteps', len(T)) |
---|
82 | fid.createVariable('time', Float, ('number_of_timesteps',)) |
---|
83 | fid.variables['time'][:] = T |
---|
84 | |
---|
85 | fid.createVariable('speed', Float, ('number_of_timesteps',)) |
---|
86 | fid.variables['speed'][:] = S[:] |
---|
87 | |
---|
88 | fid.createVariable('bearing', Float, ('number_of_timesteps',)) |
---|
89 | fid.variables['bearing'][:] = B[:] |
---|
90 | |
---|
91 | |
---|
92 | fid.close() |
---|
93 | |
---|
94 | |
---|
95 | def prepare_timeboundary(filename): |
---|
96 | """Converting tide time series to NetCDF tms file. |
---|
97 | This is a 'throw-away' code taylor made for files like |
---|
98 | 'Benchmark_2_input.txt' from the LWRU2 benchmark |
---|
99 | """ |
---|
100 | |
---|
101 | print 'Preparing time boundary from %s' %filename |
---|
102 | from Numeric import array, zeros, Float, asarray |
---|
103 | |
---|
104 | fid = open(filename) |
---|
105 | |
---|
106 | #Skip first line |
---|
107 | line = fid.readline() |
---|
108 | |
---|
109 | #Read remaining lines |
---|
110 | lines = fid.readlines() |
---|
111 | fid.close() |
---|
112 | |
---|
113 | |
---|
114 | N = len(lines) |
---|
115 | T = zeros(N, Float) #Time |
---|
116 | Q = zeros(N, Float) #Values |
---|
117 | |
---|
118 | Told = 0.0 |
---|
119 | Sold = ' ' |
---|
120 | Lold = ' ' |
---|
121 | for i, line in enumerate(lines): |
---|
122 | fields = line.split() |
---|
123 | |
---|
124 | #print fields |
---|
125 | |
---|
126 | l_time = (fields[0]+' '+fields[1])[0:-1] |
---|
127 | from time import strptime, mktime |
---|
128 | |
---|
129 | s_time = strptime(l_time,'%d/%m/%y %H:%M:%S') |
---|
130 | |
---|
131 | #print s_time |
---|
132 | |
---|
133 | T[i] = float(mktime(s_time)) |
---|
134 | |
---|
135 | if i==0: |
---|
136 | Tstart = T[0] |
---|
137 | |
---|
138 | T[i] = T[i] - Tstart |
---|
139 | #this is specific to this data set. deals with daylight saving |
---|
140 | if i>3270: |
---|
141 | T[i] = T[i]+3600 |
---|
142 | |
---|
143 | if T[i]<Told : |
---|
144 | print Lold |
---|
145 | print l_time |
---|
146 | print Sold |
---|
147 | print s_time |
---|
148 | print Told |
---|
149 | print T[i] |
---|
150 | print i, T[i]-Told |
---|
151 | |
---|
152 | Q[i] = float(fields[2]) |
---|
153 | |
---|
154 | Told = T[i] |
---|
155 | Sold = s_time |
---|
156 | Lold = l_time |
---|
157 | |
---|
158 | |
---|
159 | #print T |
---|
160 | #Create tms file |
---|
161 | from Scientific.IO.NetCDF import NetCDFFile |
---|
162 | |
---|
163 | outfile = filename[:-4] + '.tms' |
---|
164 | print 'Writing to', outfile |
---|
165 | fid = NetCDFFile(outfile, 'w') |
---|
166 | |
---|
167 | fid.institution = 'Australian National University' |
---|
168 | fid.description = 'Input wave for Merimbula' |
---|
169 | fid.starttime = 0.0 |
---|
170 | fid.createDimension('number_of_timesteps', len(T)) |
---|
171 | fid.createVariable('time', Float, ('number_of_timesteps',)) |
---|
172 | fid.variables['time'][:] = T |
---|
173 | |
---|
174 | fid.createVariable('stage', Float, ('number_of_timesteps',)) |
---|
175 | fid.variables['stage'][:] = Q[:] |
---|
176 | |
---|
177 | fid.createVariable('xmomentum', Float, ('number_of_timesteps',)) |
---|
178 | fid.variables['xmomentum'][:] = 0.0 |
---|
179 | |
---|
180 | fid.createVariable('ymomentum', Float, ('number_of_timesteps',)) |
---|
181 | fid.variables['ymomentum'][:] = 0.0 |
---|
182 | |
---|
183 | fid.close() |
---|
184 | |
---|
185 | #------------------------------------------------------------- |
---|
186 | if __name__ == "__main__": |
---|
187 | import project |
---|
188 | print 'Prepare Open sea boundary condition from ',project.original_boundary_filename |
---|
189 | prepare_timeboundary(project.original_boundary_filename ) |
---|
190 | |
---|
191 | |
---|
192 | print 'Prepare wind from ',project.original_wind_filename |
---|
193 | prepare_wind_stress(project.original_wind_filename ) |
---|
194 | |
---|
195 | #Preparing points |
---|
196 | print 'Prepare bathymetry from xya file ',project.bathymetry_filename |
---|
197 | from pyvolution.data_manager import xya2pts |
---|
198 | xya2pts(project.bathymetry_filename, verbose = True) |
---|
199 | |
---|
200 | |
---|
201 | # fit_to_mesh_file(mesh_file, point_file, mesh_output_file, |
---|
202 | # alpha=DEFAULT_ALPHA, verbose= False, |
---|
203 | # expand_search = False, |
---|
204 | # data_origin = None, |
---|
205 | # mesh_origin = None, |
---|
206 | # precrop = False, |
---|
207 | # display_errors = True): |
---|