Changeset 3964
- Timestamp:
- Nov 10, 2006, 3:47:17 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r3961 r3964 4108 4108 Lat and lon are assumed to be in decimal degrees. 4109 4109 NOTE: min Lon is the most east boundary. 4110 4111 origin is a 3-tuple with geo referenced 4112 UTM coordinates (zone, easting, northing) 4113 It will be the origin of the sww file. This shouldn't be used, 4114 since all of anuga should be able to handle an arbitary origin. 4115 4110 4116 4111 4117 URS C binary format has data orgainised as TIME, LONGITUDE, LATITUDE … … 4138 4144 4139 4145 def urs2nc(basename_in = 'o', basename_out = 'urs'): 4146 """ 4147 Convert the 3 urs files to 4 nc files. 4148 4149 The name of the urs file names must be; 4150 [basename_in]-z-mux 4151 [basename_in]-e-mux 4152 [basename_in]-n-mux 4153 4154 """ 4140 4155 files_in = [basename_in+'-z-mux', 4141 4156 basename_in+'-e-mux', … … 4158 4173 file_out, 4159 4174 quantity) 4160 #print "lon",lon4161 #print "lat",lat4162 4175 if hashed_elevation == None: 4163 4176 elevation_file = basename_out+'_e.nc' 4164 write_elevation_ sww(elevation_file,4177 write_elevation_nc(elevation_file, 4165 4178 lon, 4166 4179 lat, … … 4175 4188 def _binary_c2nc(file_in, file_out, quantity): 4176 4189 """ 4177 4178 return the depth info, so it can be written to a file 4190 Reads in a quantity urs file and writes a quantity nc file. 4191 additionally, returns the depth and lat, long info, 4192 so it can be written to a file. 4179 4193 """ 4180 4194 columns = 3 # long, lat , depth 4181 #FIXME use mux_file, not f 4182 f = open(file_in, 'rb') 4195 mux_file = open(file_in, 'rb') 4183 4196 4184 4197 # Number of points/stations 4185 (points_num,)= unpack('i',f.read(4)) 4186 4187 #print 'points_num', points_num 4188 #import sys; sys.exit() 4198 (points_num,)= unpack('i',mux_file.read(4)) 4199 4189 4200 # nt, int - Number of time steps 4190 (time_step_count,)= unpack('i', f.read(4))4201 (time_step_count,)= unpack('i',mux_file.read(4)) 4191 4202 4192 4203 #dt, float - time step, seconds 4193 (time_step,) = unpack('f', f.read(4))4204 (time_step,) = unpack('f', mux_file.read(4)) 4194 4205 4195 4206 msg = "Bad data in the mux file." 4196 4207 if points_num < 0: 4197 f.close()4208 mux_file.close() 4198 4209 raise ANUGAError, msg 4199 4210 if time_step_count < 0: 4200 f.close()4211 mux_file.close() 4201 4212 raise ANUGAError, msg 4202 4213 if time_step < 0: 4203 f.close()4214 mux_file.close() 4204 4215 raise ANUGAError, msg 4205 4216 4206 4217 lonlatdep = p_array.array('f') 4207 ####points_num = 2914 4208 lonlatdep.read(f, columns * points_num) 4218 lonlatdep.read(mux_file, columns * points_num) 4209 4219 lonlatdep = array(lonlatdep, typecode=Float) 4210 4220 lonlatdep = reshape(lonlatdep, (points_num, columns)) 4211 4212 #print "lonlatdep", lonlatdep4213 4221 4214 4222 lon, lat, depth = lon_lat2grid(lonlatdep) … … 4216 4224 lon_sorted.sort() 4217 4225 4218 if not allclose(lon, lon_sorted):4226 if not lon == lon_sorted: 4219 4227 msg = "Longitudes in mux file are not in ascending order" 4220 4228 raise IOError, msg … … 4222 4230 lat_sorted.sort() 4223 4231 4224 if not allclose(lat, lat_sorted):4232 if not lat == lat_sorted: 4225 4233 msg = "Latitudes in mux file are not in ascending order" 4226 4234 … … 4235 4243 #Read in a time slice from mux file 4236 4244 hz_p_array = p_array.array('f') 4237 hz_p_array.read( f, points_num)4245 hz_p_array.read(mux_file, points_num) 4238 4246 hz_p = array(hz_p_array, typecode=Float) 4239 4247 hz_p = reshape(hz_p, (len(lon), len(lat))) … … 4242 4250 #write time slice to nc file 4243 4251 nc_file.store_timestep(hz_p) 4244 #FIXME should I close the mux file here? 4245 f.close() 4252 mux_file.close() 4246 4253 nc_file.close() 4247 4254 … … 4249 4256 4250 4257 4251 def write_elevation_sww(file_out, lon, lat, depth_vector): 4252 4258 def write_elevation_nc(file_out, lon, lat, depth_vector): 4259 """ 4260 Write an nc elevation file. 4261 """ 4262 4253 4263 # NetCDF file definition 4254 4264 outfile = NetCDFFile(file_out, 'w') … … 4267 4277 4268 4278 depth = reshape(depth_vector, ( len(lat), len(lon))) 4269 #print "depth",depth4270 4279 outfile.variables[zname][:]= depth 4271 4280 … … 4273 4282 4274 4283 def nc_lon_lat_header(outfile, lon, lat): 4284 """ 4285 outfile is the netcdf file handle. 4286 lon - a list/array of the longitudes 4287 lat - a list/array of the latitudes 4288 """ 4275 4289 4276 4290 outfile.institution = 'Geoscience Australia' … … 4312 4326 num_points = long_lat_dep.shape[0] 4313 4327 this_rows_long = long_lat_dep[0,LONG] 4314 4328 4315 4329 # Count the length of unique latitudes 4316 4330 i = 0 4317 4331 while long_lat_dep[i,LONG] == this_rows_long and i < num_points: 4318 4332 i += 1 4319 4333 # determine the lats and longsfrom the grid 4320 4334 lat = long_lat_dep[:i, LAT] 4321 long = long_lat_dep[::i, LONG] 4335 long = long_lat_dep[::i, LONG] 4336 4322 4337 lenlong = len(long) 4323 4338 lenlat = len(lat) 4324 #print 'len lat', lat, len(lat)4325 #print 'len long', long, len(long)4339 #print 'len lat', lat, len(lat) 4340 #print 'len long', long, len(long) 4326 4341 4327 4342 msg = 'Input data is not gridded'
Note: See TracChangeset
for help on using the changeset viewer.