Changeset 4037
- Timestamp:
- Nov 28, 2006, 11:54:54 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
r4031 r4037 64 64 65 65 from Numeric import concatenate, array, Float, Int, Int32, resize, sometrue, \ 66 searchsorted, zeros, allclose, around, reshape, transpose 66 searchsorted, zeros, allclose, around, reshape, transpose, sort 67 67 from Scientific.IO.NetCDF import NetCDFFile 68 68 … … 2686 2686 jmax = searchsorted(times, maxt) 2687 2687 2688 #print "latitudes[:]",latitudes[:] 2689 #print "longitudes[:]",longitudes [:] 2688 2690 kmin, kmax, lmin, lmax = _get_min_max_indexes(latitudes[:], 2689 2691 longitudes[:], … … 2697 2699 longitudes = longitudes[lmin:lmax] 2698 2700 2701 #print "latitudes[:]",latitudes[:] 2702 #print "longitudes[:]",longitudes [:] 2699 2703 2700 2704 if verbose: print 'cropping' … … 3889 3893 outfile.close() 3890 3894 3891 def _get_min_max_indexes(latitudes ,longitudes,3895 def _get_min_max_indexes(latitudes_ref,longitudes_ref, 3892 3896 minlat=None, maxlat=None, 3893 3897 minlon=None, maxlon=None): … … 3901 3905 has a section outside of the latitudes/longitudes area.) 3902 3906 3903 ass ume latitudess &longitudes are sorted,3907 asset longitudes are sorted, 3904 3908 long - from low to high (west to east, eg 148 - 151) 3905 lat - from high to low (north to south, eg -35 - -38) 3906 """ 3907 3908 # reverse order of lat, so it's in ascending order 3909 try: 3910 latitudes = latitudes.tolist() 3911 except: 3912 pass 3909 assert latitudes are sorted, ascending or decending 3910 """ 3911 latitudes = latitudes_ref[:] 3912 longitudes = longitudes_ref[:] 3913 3914 latitudes = ensure_numeric(latitudes) 3915 longitudes = ensure_numeric(longitudes) 3913 3916 3914 latitudes.reverse() 3917 assert allclose(sort(longitudes), longitudes) 3918 3919 lat_ascending = True 3920 if not allclose(sort(latitudes), latitudes): 3921 lat_ascending = False 3922 # reverse order of lat, so it's in ascending order 3923 latitudes = latitudes[::-1] 3924 assert allclose(sort(latitudes), latitudes) 3925 #print "latitudes in funct", latitudes 3915 3926 3916 3927 largest_lat_index = len(latitudes)-1 … … 3943 3954 lon_max_index = searchsorted(longitudes, maxlon) 3944 3955 3945 # Take into account that the latitude list was reversed3946 latitudes.reverse() # Python passes by reference, need to swap back3947 lat_min_index, lat_max_index = largest_lat_index - lat_max_index , \3948 largest_lat_index - lat_min_index3956 # Reversing the indexes, if the lat array is decending 3957 if lat_ascending is False: 3958 lat_min_index, lat_max_index = largest_lat_index - lat_max_index , \ 3959 largest_lat_index - lat_min_index 3949 3960 lat_max_index = lat_max_index + 1 # taking into account how slicing works 3950 3961 lon_max_index = lon_max_index + 1 # taking into account how slicing works -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4026 r4037 2320 2320 # LON = 150.66667, 150.83334, 151, 151.16667 2321 2321 # LAT = -34.5, -34.33333, -34.16667, -34 ; 2322 # TIME = 0, 0.1, 0.6, 1.1, 1.6, 2.1 ; 2323 # 2324 # First value (index=0) in small_ha.nc is 0.3400644 cm, 2325 # Fourth value (index==3) is -6.50198 cm 2326 2327 2328 2322 2329 2323 #Read 2330 2324 from anuga.coordinate_transforms.redfearn import redfearn … … 2361 2355 2362 2356 2357 def test_ferret2sww_lat_longII(self): 2358 # Test that min lat long works 2359 2360 #The test file has 2361 # LON = 150.66667, 150.83334, 151, 151.16667 2362 # LAT = -34.5, -34.33333, -34.16667, -34 ; 2363 2364 #Read 2365 from anuga.coordinate_transforms.redfearn import redfearn 2366 fid = NetCDFFile(self.test_MOST_file + '_ha.nc') 2367 first_value = fid.variables['HA'][:][0,0,0] 2368 fourth_value = fid.variables['HA'][:][0,0,3] 2369 fid.close() 2370 2371 2372 #Call conversion (with zero origin) 2373 #ferret2sww('small', verbose=False, 2374 # origin = (56, 0, 0)) 2375 ferret2sww(self.test_MOST_file, verbose=False, 2376 origin = (56, 0, 0), minlat=-34.4, maxlat=-34.2) 2377 2378 #Work out the UTM coordinates for first point 2379 zone, e, n = redfearn(-34.5, 150.66667) 2380 #print zone, e, n 2381 2382 #Read output file 'small.sww' 2383 #fid = NetCDFFile('small.sww') 2384 fid = NetCDFFile(self.test_MOST_file + '.sww') 2385 2386 x = fid.variables['x'][:] 2387 y = fid.variables['y'][:] 2388 #Check that first coordinate is correctly represented 2389 assert 12 == len(x) 2390 2391 fid.close() 2392 2393 #Cleanup 2394 import os 2395 os.remove(self.test_MOST_file + '.sww') 2396 2363 2397 def test_ferret2sww3(self): 2364 2398 """Elevation included … … 4171 4205 4172 4206 self.failUnless(m2d == [[5,6],[9,10]], 4207 'failed') 4208 4209 def test_get_min_max_indexes_lat_ascending(self): 4210 latitudes = [0,1,2,3] 4211 longitudes = [0,10,20,30] 4212 4213 # k - lat 4214 # l - lon 4215 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes( 4216 latitudes,longitudes, 4217 -10,4,-10,31) 4218 4219 #print "kmin",kmin;print "kmax",kmax 4220 #print "lmin",lmin;print "lmax",lmax 4221 latitudes_new = latitudes[kmin:kmax] 4222 longitudes_news = longitudes[lmin:lmax] 4223 #print "latitudes_new", latitudes_new 4224 #print "longitudes_news",longitudes_news 4225 self.failUnless(latitudes == latitudes_new and \ 4226 longitudes == longitudes_news, 4227 'failed') 4228 4229 ## 3rd test 4230 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes(\ 4231 latitudes, 4232 longitudes, 4233 1.1,1.9,12,17) 4234 #print "kmin",kmin;print "kmax",kmax 4235 #print "lmin",lmin;print "lmax",lmax 4236 latitudes_new = latitudes[kmin:kmax] 4237 longitudes_news = longitudes[lmin:lmax] 4238 #print "latitudes_new", latitudes_new 4239 #print "longitudes_news",longitudes_news 4240 4241 self.failUnless(latitudes_new == [1, 2] and \ 4242 longitudes_news == [10, 20], 4173 4243 'failed') 4174 4244 … … 4806 4876 self.delete_mux(files) 4807 4877 os.remove(sww_file) 4878 4879 def test_urs2sww_minmaxlatlong(self): 4880 4881 #longitudes = [150.66667, 150.83334, 151., 151.16667] 4882 #latitudes = [-34.5, -34.33333, -34.16667, -34] 4883 4884 tide = 1 4885 base_name, files = self.create_mux() 4886 urs2sww(base_name, 4887 minlat=-34.5, 4888 maxlat=-34, 4889 minlon= 150.66667, 4890 maxlon= 151.16667, 4891 mean_stage=tide, 4892 remove_nc_files=False 4893 ) 4894 sww_file = base_name + '.sww' 4895 4896 #Let's interigate the sww file 4897 # Note, the sww info is not gridded. It is point data. 4898 fid = NetCDFFile(sww_file) 4899 4900 4901 # Make x and y absolute 4902 x = fid.variables['x'][:] 4903 y = fid.variables['y'][:] 4904 geo_reference = Geo_reference(NetCDFObject=fid) 4905 points = geo_reference.get_absolute(map(None, x, y)) 4906 points = ensure_numeric(points) 4907 x = points[:,0] 4908 y = points[:,1] 4909 4910 #Check that first coordinate is correctly represented 4911 #Work out the UTM coordinates for first point 4912 zone, e, n = redfearn(-34.5, 150.66667) 4913 assert allclose([x[0],y[0]], [e,n]) 4914 4915 4916 #Check first value 4917 stage = fid.variables['stage'][:] 4918 xmomentum = fid.variables['xmomentum'][:] 4919 ymomentum = fid.variables['ymomentum'][:] 4920 elevation = fid.variables['elevation'][:] 4921 assert allclose(stage[0,0], e +tide) #Meters 4922 4923 #Check the momentums - ua 4924 #momentum = velocity*(stage-elevation) 4925 #momentum = velocity*(stage+elevation) 4926 # -(-elevation) since elevation is inverted in mux files 4927 # = n*(e+tide+n) based on how I'm writing these files 4928 answer = n*(e+tide+n) 4929 actual = xmomentum[0,0] 4930 assert allclose(answer, actual) #Meters 4931 4932 # check the stage values, first time step. 4933 # These arrays are equal since the Easting values were used as 4934 # the stage 4935 assert allclose(stage[0], x +tide) #Meters 4936 4937 # check the elevation values. 4938 # -ve since urs measures depth, sww meshers height, 4939 # these arrays are equal since the northing values were used as 4940 # the elevation 4941 assert allclose(-elevation, y) #Meters 4942 4943 fid.close() 4944 self.delete_mux(files) 4945 os.remove(sww_file) 4808 4946 4809 4947 def test_lon_lat2grid(self): … … 4877 5015 #------------------------------------------------------------- 4878 5016 if __name__ == "__main__": 4879 #suite = unittest.makeSuite(Test_Data_Manager,'test_lon') 5017 #suite = unittest.makeSuite(Test_Data_Manager,'test_urs2sww_m') 5018 #suite = unittest.makeSuite(Test_Data_Manager,'test_get_min_max_indexes_lat_ascending') 4880 5019 #suite = unittest.makeSuite(Test_Data_Manager,'test_ferret2sww_lat_long') 4881 5020 suite = unittest.makeSuite(Test_Data_Manager,'test')
Note: See TracChangeset
for help on using the changeset viewer.