Changeset 3820
- Timestamp:
- Oct 18, 2006, 11:04:59 AM (18 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r3750 r3820 64 64 65 65 from Numeric import concatenate, array, Float, Int, Int32, resize, sometrue, \ 66 searchsorted, zeros, allclose, around, reshape 66 searchsorted, zeros, allclose, around, reshape, transpose 67 67 from Scientific.IO.NetCDF import NetCDFFile 68 68 … … 4200 4200 files_out, 4201 4201 quantities): 4202 lonlatdep, lon, lat = _binary_c2nc(file_in,4202 lonlatdep, lon, lat, depth = _binary_c2nc(file_in, 4203 4203 file_out, 4204 4204 quantity) … … 4210 4210 lon, 4211 4211 lat, 4212 lonlatdep[:,2])4212 depth) 4213 4213 hashed_elevation = myhash(lonlatdep) 4214 4214 else: … … 4251 4251 lonlatdep = reshape(lonlatdep, ( points_num, columns)) 4252 4252 4253 lon, lat = lon_lat2grid(lonlatdep) 4253 #print "lonlatdep", lonlatdep 4254 4255 lon, lat, depth = lon_lat2grid(lonlatdep) 4254 4256 lon_sorted = lon[:] 4255 4257 lon_sorted.sort() … … 4275 4277 hz_p_array.read(f, points_num) 4276 4278 hz_p = array(hz_p_array, typecode=Float) 4277 hz_p = reshape(hz_p, ( len(lat), len(lon))) 4279 hz_p = reshape(hz_p, (len(lon), len(lat))) 4280 hz_p = transpose(hz_p) #mux has lat varying fastest, nc has long v.f. 4278 4281 4279 4282 nc_file.store_timestep(hz_p) … … 4281 4284 nc_file.close() 4282 4285 4283 return lonlatdep, lon, lat 4286 return lonlatdep, lon, lat, depth 4284 4287 4285 4288 … … 4336 4339 The first column is longitudes. 4337 4340 The second column is latitudes. 4341 4342 The latitude is the fastest varying dimension - in mux files 4338 4343 """ 4339 4344 LONG = 0 4340 4345 LAT = 1 4346 QUANTITY = 2 4341 4347 points_num = len(long_lat_dep) 4342 4348 lat = [long_lat_dep[0][LAT]] 4343 4349 this_rows_long = long_lat_dep[0][LONG] 4344 i = 1 # Index of long_lat_dep 4345 4350 i = 1 # Index of long_lat_dep 4351 4346 4352 #Working out the lat's 4347 4353 while long_lat_dep[i][LONG] == this_rows_long and i < points_num: … … 4362 4368 for l in lat:assert -90 < l < 90 , msg 4363 4369 for l in long:assert -180 < l < 180 , msg 4364 4365 return long, lat 4370 4371 #changing quantity from lat being the fastest varying dimension to 4372 # long being the fastest varying dimension 4373 # FIXME - make this faster/do this a better way 4374 # use numeric transpose, after reshaping the quantity vector 4375 quantity = zeros(len(long_lat_dep), Float) 4376 lenlong = len(long) 4377 lenlat = len(lat) 4378 for lat_i, _ in enumerate(lat): 4379 for long_i, _ in enumerate(long): 4380 q_index = lat_i*lenlong+long_i 4381 lld_index = long_i*lenlat+lat_i 4382 quantity[q_index] = long_lat_dep[lld_index][QUANTITY] 4383 4384 return long, lat, quantity 4366 4385 4367 4386 #### END URS 2 SWW ### -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r3761 r3820 4703 4703 base_name = 'o-e-mux' 4704 4704 file_name = base_name + '.nc' 4705 lonlatdep_numeric, lon, lat = _binary_c2nc(base_name, file_name, 'HA') 4705 lonlatdep_numeric, lon, lat, depth = \ 4706 _binary_c2nc(base_name, file_name, 'HA') 4706 4707 4707 4708 #os.remove(file_name) … … 4709 4710 def test_lon_lat2grid(self): 4710 4711 lonlatdep = [ 4711 [ 113.06700134 , -26.06669998 , 0. ] ,4712 [ 113.06700134 , -26.33329964 , 0. ] ,4713 [ 113.19999695 , -26.06669998 , 0. ] ,4714 [ 113.19999695 , -26.33329964 , 0. ] ]4712 [ 113.06700134 , -26.06669998 , 1. ] , 4713 [ 113.06700134 , -26.33329964 , 3. ] , 4714 [ 113.19999695 , -26.06669998 , 2. ] , 4715 [ 113.19999695 , -26.33329964 , 4. ] ] 4715 4716 4716 long, lat = lon_lat2grid(lonlatdep)4717 long, lat, quantity = lon_lat2grid(lonlatdep) 4717 4718 4718 4719 for i, result in enumerate(lat): … … 4724 4725 assert len(long) == 2 4725 4726 4727 for i,q in enumerate(quantity): 4728 assert q == i+1 4729 4726 4730 def test_lon_lat2grid_bad(self): 4727 4731 lonlatdep = [ … … 4743 4747 [ -26.43330002 , 113.43299866, 16. ]] 4744 4748 try: 4745 long, lat = lon_lat2grid(lonlatdep)4749 long, lat, quantity = lon_lat2grid(lonlatdep) 4746 4750 except AssertionError: 4747 4751 pass … … 4752 4756 def test_lon_lat2gridII(self): 4753 4757 lonlatdep = [ 4754 [ 113.06700134 , -26.06669998 , 0. ] ,4755 [ 113.06700134 , -26.33329964 , 0. ] ,4756 [ 113.19999695 , -26.06669998 , 0. ] ,4757 [ 113.19999695 , -26.344329964 , 0. ] ]4758 [ 113.06700134 , -26.06669998 , 1. ] , 4759 [ 113.06700134 , -26.33329964 , 2. ] , 4760 [ 113.19999695 , -26.06669998 , 3. ] , 4761 [ 113.19999695 , -26.344329964 , 4. ] ] 4758 4762 try: 4759 long, lat = lon_lat2grid(lonlatdep)4763 long, lat, quantity = lon_lat2grid(lonlatdep) 4760 4764 except AssertionError: 4761 4765 pass … … 4767 4771 basename_in = 'karratha' 4768 4772 basename_out = basename_in 4769 urs2sww(basename_in, basename_out) 4773 urs2sww(basename_in, basename_out, remove_nc_files=True, 4774 zscale=10000000) 4770 4775 #### END TESTS FOR URS 2 SWW ### 4771 4776 … … 4773 4778 #------------------------------------------------------------- 4774 4779 if __name__ == "__main__": 4775 #suite = unittest.makeSuite(Test_Data_Manager,'test_ urs2sww_test_fail')4776 #suite = unittest.makeSuite(Test_Data_Manager,'t est_urs2sww')4780 #suite = unittest.makeSuite(Test_Data_Manager,'test_lon') 4781 #suite = unittest.makeSuite(Test_Data_Manager,'trial') 4777 4782 suite = unittest.makeSuite(Test_Data_Manager,'test') 4778 4783 runner = unittest.TextTestRunner()
Note: See TracChangeset
for help on using the changeset viewer.