Changeset 2622 for production/merimbula_2005/prepare.py
- Timestamp:
- Mar 28, 2006, 2:36:03 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
production/merimbula_2005/prepare.py
r2225 r2622 1 1 2 2 3 def prepare_ timeboundary(filename):4 """Converting tide timeseries to NetCDF tms file.3 def prepare_wind_stress(filename): 4 """Converting wind timeseries to NetCDF tms file. 5 5 This is a 'throw-away' code taylor made for files like 6 6 'Benchmark_2_input.txt' from the LWRU2 benchmark 7 7 """ 8 8 9 print 'Preparing time boundary from%s' %filename9 print 'Preparing wind timeseries %s' %filename 10 10 from Numeric import array, zeros, Float, asarray 11 11 … … 13 13 14 14 #Skip first line 15 line = fid.readline()15 #line = fid.readline() 16 16 17 17 #Read remaining lines … … 22 22 N = len(lines) 23 23 T = zeros(N, Float) #Time 24 Q = zeros(N, Float) #Values 24 S = zeros(N, Float) #Speed 25 B = zeros(N, Float) #Bearing 25 26 26 27 Told = 0.0 27 28 Sold = ' ' 28 29 Lold = ' ' 30 29 31 for i, line in enumerate(lines): 30 32 fields = line.split() … … 46 48 T[i] = T[i] - Tstart 47 49 #this is specific to this data set. deals with daylight saving 48 if i>3270:49 T[i] = T[i]+360050 50 # if i>3270: 51 # T[i] = T[i]+3600 52 # 51 53 if T[i]<Told : 52 54 print Lold … … 58 60 print i, T[i]-Told 59 61 60 Q[i] = float(fields[2]) 62 S[i] = float(fields[2]) 63 B[i] = float(fields[3]) 61 64 62 65 Told = T[i] … … 65 68 66 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 67 160 #Create tms file 68 161 from Scientific.IO.NetCDF import NetCDFFile … … 90 183 fid.close() 91 184 92 93 185 #------------------------------------------------------------- 94 186 if __name__ == "__main__": … … 96 188 print 'Prepare Open sea boundary condition from ',project.original_boundary_filename 97 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 ) 98 194 99 195 #Preparing points
Note: See TracChangeset
for help on using the changeset viewer.