Changeset 2648 for inundation/pyvolution/test_data_manager.py
- Timestamp:
- Mar 31, 2006, 6:21:26 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_data_manager.py
r2639 r2648 79 79 latitudes = [-34.5, -34.33333, -34.16667, -34] 80 80 81 81 long_name = 'LON' 82 82 lat_name = 'LAT' 83 83 … … 89 89 for ext in ['_ha.nc', '_ua.nc', '_va.nc', '_e.nc']: 90 90 fid = NetCDFFile(self.test_MOST_file + ext, 'w') 91 91 92 92 fid.createDimension(long_name,nx) 93 93 fid.createVariable(long_name,'d',(long_name,)) … … 107 107 fid.variables['TIME'].units='seconds' 108 108 fid.variables['TIME'].assignValue([0.0, 0.1, 0.6, 1.1, 1.6, 2.1]) 109 109 110 110 111 111 name = ext[1:3].upper() … … 113 113 fid.createVariable(name,'d',('TIME', lat_name, long_name)) 114 114 fid.variables[name].units='CENTIMETERS' 115 fid.variables[name].missing_value=-1.e+034 116 115 fid.variables[name].missing_value=-1.e+034 116 117 117 fid.variables[name].assignValue([[[0.3400644, 0, -46.63519, -6.50198], 118 118 [-0.1214216, 0, 0, 0], … … 139 139 [0.0004811212, 0.0009622425, 0.0009599366, 8.152277e-007], 140 140 [0, 0.0004811212, 0.0004811212, 0]]]) 141 142 141 142 143 143 fid.close() 144 144 145 145 146 146 147 147 … … 150 150 for ext in ['_ha.nc', '_ua.nc', '_va.nc', '_e.nc']: 151 151 #print 'Trying to remove', self.test_MOST_file + ext 152 os.remove(self.test_MOST_file + ext) 152 os.remove(self.test_MOST_file + ext) 153 153 154 154 def test_sww_constant(self): … … 520 520 #def test_write_pts(self): 521 521 # #Obsolete 522 # 522 # 523 523 # #Get (enough) datapoints 524 524 # … … 546 546 # #Check contents 547 547 # #Get NetCDF 548 # from Scientific.IO.NetCDF import NetCDFFile 548 # from Scientific.IO.NetCDF import NetCDFFile 549 549 # fid = NetCDFFile(ptsfile, 'r') 550 550 # … … 555 555 # 556 556 # #Check values# 557 # 557 # 558 558 # #print points[:] 559 559 # #print ref_points 560 # assert allclose(points, points1) 560 # assert allclose(points, points1) 561 561 # 562 562 # #print attributes[:] … … 569 569 # import os 570 570 # os.remove(ptsfile) 571 571 572 572 573 573 def test_dem2pts_bounding_box_v2(self): … … 591 591 NODATA_value -9999 592 592 """) 593 #Create linear function 593 #Create linear function 594 594 ref_points = [] 595 595 ref_elevation = [] … … 610 610 611 611 fid.close() 612 612 613 613 #print 'sending pts', ref_points 614 614 #print 'sending elev', ref_elevation … … 650 650 651 651 #create new reference points 652 newz = [] 652 newz = [] 653 653 newz[0:5] = ref_elevation[32:38] 654 654 newz[6:11] = ref_elevation[42:48] … … 668 668 x = x0 + xvec[j] 669 669 xnew = x - 2002.0 670 ref_points.append ([xnew,ynew]) #Relative point values 670 ref_points.append ([xnew,ynew]) #Relative point values 671 671 672 672 assert allclose(points, ref_points) … … 704 704 NODATA_value -9999 705 705 """) 706 #Create linear function 706 #Create linear function 707 707 ref_points = [] 708 708 ref_elevation = [] … … 721 721 ref_points.append ([x,y]) 722 722 count += 1 723 z[count] = (4*i - 3*j)%13 723 z[count] = (4*i - 3*j)%13 724 724 if j == 4: z[count] = NODATA_value #column inside clipping region 725 725 if j == 8: z[count] = NODATA_value #column outside clipping region 726 726 if i == 9: z[count] = NODATA_value #row outside clipping region 727 if i == 4 and j == 6: z[count] = NODATA_value #arbitrary point inside clipping region 727 if i == 4 and j == 6: z[count] = NODATA_value #arbitrary point inside clipping region 728 728 ref_elevation.append( z[count] ) 729 729 fid.write('%f ' %z[count]) 730 730 fid.write('\n') 731 731 732 fid.close() 733 732 fid.close() 733 734 734 #print 'sending elev', ref_elevation 735 735 … … 781 781 newz[16:19] = ref_elevation[65:68] 782 782 783 783 784 784 ref_elevation = newz 785 785 ref_points = [] … … 795 795 x = x0 + xvec[j] 796 796 xnew = x - 2002.0 797 if j <> 2 and (i<>1 or j<>4): 797 if j <> 2 and (i<>1 or j<>4): 798 798 ref_points.append([x,y]) 799 799 new_ref_points.append ([xnew,ynew]) 800 800 801 801 802 802 assert allclose(points, new_ref_points) 803 803 assert allclose(elevation, ref_elevation) … … 834 834 NODATA_value -9999 835 835 """) 836 #Create linear function 836 #Create linear function 837 837 ref_points = [] 838 838 ref_elevation = [] … … 851 851 ref_points.append ([x,y]) 852 852 count += 1 853 z[count] = (4*i - 3*j)%13 853 z[count] = (4*i - 3*j)%13 854 854 if j == 4: z[count] = NODATA_value #column inside clipping region 855 855 if j == 8: z[count] = NODATA_value #column outside clipping region 856 856 if i == 6: z[count] = NODATA_value #row on clipping boundary 857 if i == 4 and j == 6: z[count] = NODATA_value #arbitrary point inside clipping region 857 if i == 4 and j == 6: z[count] = NODATA_value #arbitrary point inside clipping region 858 858 ref_elevation.append( z[count] ) 859 859 fid.write('%f ' %z[count]) 860 860 fid.write('\n') 861 861 862 fid.close() 863 862 fid.close() 863 864 864 #print 'sending elev', ref_elevation 865 865 … … 910 910 911 911 912 912 913 913 ref_elevation = newz 914 914 ref_points = [] … … 924 924 x = x0 + xvec[j] 925 925 xnew = x - 2002.0 926 if j <> 2 and (i<>1 or j<>4) and i<>3: 926 if j <> 2 and (i<>1 or j<>4) and i<>3: 927 927 ref_points.append([x,y]) 928 928 new_ref_points.append ([xnew,ynew]) … … 932 932 #print new_ref_points, len(new_ref_points) 933 933 934 assert allclose(elevation, ref_elevation) 934 assert allclose(elevation, ref_elevation) 935 935 assert allclose(points, new_ref_points) 936 936 … … 973 973 PROJECTION ZONE: 50 974 974 DATUM: AGD66 975 VERTICAL DATUM: 976 NUMBER OF REACHES: 19 977 NUMBER OF CROSS-SECTIONS: 2 975 VERTICAL DATUM: 976 NUMBER OF REACHES: 19 977 NUMBER OF CROSS-SECTIONS: 2 978 978 END HEADER: 979 979 … … 984 984 STREAM ID:Southern-Wungong 985 985 REACH ID:Southern-Wungong 986 STATION:21410 986 STATION:21410 987 987 CUT LINE: 988 407546.08 , 6437277.542 989 407329.32 , 6437489.482 990 407283.11 , 6437541.232 988 407546.08 , 6437277.542 989 407329.32 , 6437489.482 990 407283.11 , 6437541.232 991 991 SURFACE LINE: 992 992 407546.08, 6437277.54, 52.14 … … 999 999 1000 1000 CROSS-SECTION: 1001 STREAM ID:Swan River 1002 REACH ID:Swan Mouth 1003 STATION:840.* 1001 STREAM ID:Swan River 1002 REACH ID:Swan Mouth 1003 STATION:840.* 1004 1004 CUT LINE: 1005 381178.0855 , 6452559.0685 1006 380485.4755 , 6453169.272 1005 381178.0855 , 6452559.0685 1006 380485.4755 , 6453169.272 1007 1007 SURFACE LINE: 1008 1008 381178.09, 6452559.07, 4.17 … … 1017 1017 381063.46, 6452660.06, 3.67 1018 1018 381054.41, 6452668.03, 3.67 1019 END: 1019 END: 1020 1020 END CROSS-SECTIONS: 1021 1021 """) … … 1044 1044 [407510.08, 6437312.74]] 1045 1045 1046 ref_points += [[381178.09, 6452559.07], 1047 [381169.49, 6452566.64], 1048 [381157.78, 6452576.96], 1049 [381155.97, 6452578.56], 1050 [381143.72, 6452589.35], 1051 [381136.69, 6452595.54], 1052 [381114.74, 6452614.88], 1053 [381075.53, 6452649.43], 1054 [381071.47, 6452653.00], 1055 [381063.46, 6452660.06], 1056 [381054.41, 6452668.03]] 1057 1058 1046 ref_points += [[381178.09, 6452559.07], 1047 [381169.49, 6452566.64], 1048 [381157.78, 6452576.96], 1049 [381155.97, 6452578.56], 1050 [381143.72, 6452589.35], 1051 [381136.69, 6452595.54], 1052 [381114.74, 6452614.88], 1053 [381075.53, 6452649.43], 1054 [381071.47, 6452653.00], 1055 [381063.46, 6452660.06], 1056 [381054.41, 6452668.03]] 1057 1058 1059 1059 ref_elevation = [52.14, 51.07, 50.56, 49.58, 49.09, 48.76] 1060 1060 ref_elevation += [4.17, 4.26, 4.34, 4.35, 4.43, 4.58, 4.41, 4.17, 3.99, 3.67, 3.67] … … 1127 1127 verbose = False, 1128 1128 format = 'asc') 1129 1129 1130 1130 #Check prj (meta data) 1131 1131 prjid = open(prjfile) … … 1225 1225 cellsize 10.000000 1226 1226 NODATA_value -9999 1227 -100 -110 -120 -130 -140 -150 -160 -170 -180 -190 -200 1228 -90 -100 -110 -120 -130 -140 -150 -160 -170 -180 -190 1229 -80 -90 -100 -110 -120 -130 -140 -150 -160 -170 -180 1230 -70 -80 -90 -100 -110 -120 -130 -140 -150 -160 -170 1231 -60 -70 -80 -90 -100 -110 -120 -130 -140 -150 -160 1232 -50 -60 -70 -80 -90 -100 -110 -120 -130 -140 -150 1227 -100 -110 -120 -130 -140 -150 -160 -170 -180 -190 -200 1228 -90 -100 -110 -120 -130 -140 -150 -160 -170 -180 -190 1229 -80 -90 -100 -110 -120 -130 -140 -150 -160 -170 -180 1230 -70 -80 -90 -100 -110 -120 -130 -140 -150 -160 -170 1231 -60 -70 -80 -90 -100 -110 -120 -130 -140 -150 -160 1232 -50 -60 -70 -80 -90 -100 -110 -120 -130 -140 -150 1233 1233 -40 -50 -60 -70 -80 -90 -100 -110 -120 -130 -140 1234 1234 -30 -40 -50 -60 -70 -80 -90 -100 -110 -120 -130 … … 1236 1236 -10 -20 -30 -40 -50 -60 -70 -80 -90 -100 -110 1237 1237 0 -10 -20 -30 -40 -50 -60 -70 -80 -90 -100 1238 1238 1239 1239 """ 1240 1240 … … 1267 1267 # 1268 1268 domain.set_quantity('elevation', lambda x,y: -x-y) 1269 domain.set_quantity('stage', 0) 1269 domain.set_quantity('stage', 0) 1270 1270 1271 1271 B = Transmissive_boundary(domain) … … 1283 1283 cellsize = 10 #10m grid 1284 1284 1285 1285 1286 1286 #Check contents 1287 1287 #Get NetCDF … … 1303 1303 verbose = False, 1304 1304 format = 'asc') 1305 1306 1305 1306 1307 1307 #Check prj (meta data) 1308 1308 prjid = open(prjfile) … … 1380 1380 #assert allclose(float(value), -(10-i+j)*cellsize) 1381 1381 assert float(value) == -(10-i+j)*cellsize 1382 1382 1383 1383 1384 1384 fid.close() … … 1398 1398 Original extent is 100m x 100m: 1399 1399 1400 Eastings: 308500 - 308600 1400 Eastings: 308500 - 308600 1401 1401 Northings: 6189000 - 6189100 1402 1402 1403 1403 Bounding box changes this to the 50m x 50m square defined by 1404 1404 1405 Eastings: 308530 - 308570 1405 Eastings: 308530 - 308570 1406 1406 Northings: 6189050 - 6189100 1407 1407 1408 1408 The cropped values should be 1409 1409 1410 -130 -140 -150 -160 -170 1411 -120 -130 -140 -150 -160 1412 -110 -120 -130 -140 -150 1413 -100 -110 -120 -130 -140 1414 -90 -100 -110 -120 -130 1410 -130 -140 -150 -160 -170 1411 -120 -130 -140 -150 -160 1412 -110 -120 -130 -140 -150 1413 -100 -110 -120 -130 -140 1414 -90 -100 -110 -120 -130 1415 1415 -80 -90 -100 -110 -120 1416 1416 1417 and the new lower reference point should be 1418 Eastings: 308530 1417 and the new lower reference point should be 1418 Eastings: 308530 1419 1419 Northings: 6189050 1420 1420 1421 1421 Original dataset is the same as in test_sww2dem_larger() 1422 1422 1423 1423 """ 1424 1424 … … 1451 1451 # 1452 1452 domain.set_quantity('elevation', lambda x,y: -x-y) 1453 domain.set_quantity('stage', 0) 1453 domain.set_quantity('stage', 0) 1454 1454 1455 1455 B = Transmissive_boundary(domain) … … 1467 1467 cellsize = 10 #10m grid 1468 1468 1469 1469 1470 1470 #Check contents 1471 1471 #Get NetCDF … … 1487 1487 easting_min = 308530, 1488 1488 easting_max = 308570, 1489 northing_min = 6189050, 1490 northing_max = 6189100, 1489 northing_min = 6189050, 1490 northing_max = 6189100, 1491 1491 verbose = False, 1492 1492 format = 'asc') 1493 1494 fid.close() 1495 1496 1493 1494 fid.close() 1495 1496 1497 1497 #Check prj (meta data) 1498 1498 prjid = open(prjfile) … … 1568 1568 for i, line in enumerate(lines[6:]): 1569 1569 for j, value in enumerate( line.split() ): 1570 #assert float(value) == -(10-i+j)*cellsize 1570 #assert float(value) == -(10-i+j)*cellsize 1571 1571 assert float(value) == -(10-i+j+3)*cellsize 1572 1572 1573 1573 1574 1574 … … 2000 2000 # cellsize = cellsize, 2001 2001 # verbose = False) 2002 2002 2003 2003 sww2dem(self.domain.filename, 2004 2004 quantity = 'elevation', … … 2010 2010 #Check header data 2011 2011 from ermapper_grids import read_ermapper_header, read_ermapper_data 2012 2012 2013 2013 header = read_ermapper_header(self.domain.filename + '_elevation.ers') 2014 2014 #print header 2015 2015 assert header['projection'].lower() == '"utm-56"' 2016 2016 assert header['datum'].lower() == '"wgs84"' 2017 assert header['units'].lower() == '"meters"' 2018 assert header['value'].lower() == '"elevation"' 2017 assert header['units'].lower() == '"meters"' 2018 assert header['value'].lower() == '"elevation"' 2019 2019 assert header['xdimension'] == '0.25' 2020 assert header['ydimension'] == '0.25' 2020 assert header['ydimension'] == '0.25' 2021 2021 assert float(header['eastings']) == 308500.0 #xllcorner 2022 assert float(header['northings']) == 6189000.0 #yllcorner 2022 assert float(header['northings']) == 6189000.0 #yllcorner 2023 2023 assert int(header['nroflines']) == 5 2024 assert int(header['nrofcellsperline']) == 5 2024 assert int(header['nrofcellsperline']) == 5 2025 2025 assert int(header['nullcellvalue']) == NODATA_value 2026 #FIXME - there is more in the header 2027 2028 2029 #Check grid data 2030 grid = read_ermapper_data(self.domain.filename + '_elevation') 2031 2026 #FIXME - there is more in the header 2027 2028 2029 #Check grid data 2030 grid = read_ermapper_data(self.domain.filename + '_elevation') 2031 2032 2032 #FIXME (Ole): Why is this the desired reference grid for -x-y? 2033 2033 ref_grid = [NODATA_value, NODATA_value, NODATA_value, NODATA_value, NODATA_value, 2034 2034 -1, -1.25, -1.5, -1.75, -2.0, 2035 -0.75, -1.0, -1.25, -1.5, -1.75, 2035 -0.75, -1.0, -1.25, -1.5, -1.75, 2036 2036 -0.5, -0.75, -1.0, -1.25, -1.5, 2037 -0.25, -0.5, -0.75, -1.0, -1.25] 2038 2037 -0.25, -0.5, -0.75, -1.0, -1.25] 2038 2039 2039 2040 2040 #print grid … … 2042 2042 2043 2043 fid.close() 2044 2044 2045 2045 #Cleanup 2046 2046 #FIXME the file clean-up doesn't work (eg Permission Denied Error) 2047 #Done (Ole) - it was because sww2ers didn't close it's sww file 2047 #Done (Ole) - it was because sww2ers didn't close it's sww file 2048 2048 os.remove(sww.filename) 2049 2049 os.remove(self.domain.filename + '_elevation') 2050 os.remove(self.domain.filename + '_elevation.ers') 2050 os.remove(self.domain.filename + '_elevation.ers') 2051 2051 2052 2052 … … 2067 2067 # Fourth value (index==3) is -6.50198 cm 2068 2068 2069 2069 2070 2070 2071 2071 #Read 2072 2072 from coordinate_transforms.redfearn import redfearn 2073 2073 #fid = NetCDFFile(self.test_MOST_file) 2074 fid = NetCDFFile(self.test_MOST_file + '_ha.nc') 2074 fid = NetCDFFile(self.test_MOST_file + '_ha.nc') 2075 2075 first_value = fid.variables['HA'][:][0,0,0] 2076 2076 fourth_value = fid.variables['HA'][:][0,0,3] … … 2090 2090 #Read output file 'small.sww' 2091 2091 #fid = NetCDFFile('small.sww') 2092 fid = NetCDFFile(self.test_MOST_file + '.sww') 2092 fid = NetCDFFile(self.test_MOST_file + '.sww') 2093 2093 2094 2094 x = fid.variables['x'][:] … … 2211 2211 h2_list = [-34.5,-34.33333] 2212 2212 2213 2213 long_name = 'LON' 2214 2214 lat_name = 'LAT' 2215 time_name = 'TIME' 2215 time_name = 'TIME' 2216 2216 2217 2217 nx = 3 … … 2253 2253 2254 2254 name = {} 2255 2256 2257 2258 2255 name[fid1]='HA' 2256 name[fid2]='UA' 2257 name[fid3]='VA' 2258 name[fid4]='ELEVATION' 2259 2259 2260 2260 units = {} 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2261 units[fid1]='cm' 2262 units[fid2]='cm/s' 2263 units[fid3]='cm/s' 2264 units[fid4]='m' 2265 2266 values = {} 2267 values[fid1]=[[[5., 10.,15.], [13.,18.,23.]],[[50.,100.,150.],[130.,180.,230.]]] 2268 values[fid2]=[[[1., 2.,3.], [4.,5.,6.]],[[7.,8.,9.],[10.,11.,12.]]] 2269 values[fid3]=[[[13., 12.,11.], [10.,9.,8.]],[[7.,6.,5.],[4.,3.,2.]]] 2270 values[fid4]=[[-3000,-3100,-3200],[-4000,-5000,-6000]] 2271 2271 2272 2272 for fid in [fid1,fid2,fid3]: … … 2276 2276 fid.variables[name[fid]].assignValue(values[fid]) 2277 2277 fid.variables[name[fid]].missing_value = -99999999. 2278 2278 if fid == fid3: break 2279 2279 2280 2280 for fid in [fid4]: 2281 2281 fid.createVariable(name[fid],'d',(lat_name,long_name)) 2282 2282 fid.variables[name[fid]].point_spacing='uneven' 2283 2283 fid.variables[name[fid]].units=units[fid] … … 2323 2323 elevation = fid.variables['elevation'][:] 2324 2324 stage = fid.variables['stage'][:] 2325 2326 2327 2328 2325 xmomentum = fid.variables['xmomentum'][:] 2326 ymomentum = fid.variables['ymomentum'][:] 2327 2328 #print ymomentum 2329 2329 first_height = first_amp/100 - first_elevation 2330 2330 third_height = third_amp/100 - third_elevation … … 2371 2371 h2_list = [-34.5,-34.33333] 2372 2372 2373 long_name = 'LON961_1261' 2374 lat_name = 'LAT481_841' 2375 time_name = 'TIME1' 2373 # long_name = 'LON961_1261' 2374 # lat_name = 'LAT481_841' 2375 # time_name = 'TIME1' 2376 2377 long_name = 'LON' 2378 lat_name = 'LAT' 2379 time_name = 'TIME' 2376 2380 2377 2381 nx = 3 … … 2413 2417 2414 2418 name = {} 2415 2416 2417 2418 2419 name[fid1]='HA' 2420 name[fid2]='UA' 2421 name[fid3]='VA' 2422 name[fid4]='ELEVATION' 2419 2423 2420 2424 units = {} 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2425 units[fid1]='cm' 2426 units[fid2]='cm/s' 2427 units[fid3]='cm/s' 2428 units[fid4]='m' 2429 2430 values = {} 2431 values[fid1]=[[[5., 10.,15.], [13.,18.,23.]],[[50.,100.,150.],[130.,180.,230.]]] 2432 values[fid2]=[[[1., 2.,3.], [4.,5.,6.]],[[7.,8.,9.],[10.,11.,12.]]] 2433 values[fid3]=[[[13., 12.,11.], [10.,9.,8.]],[[7.,6.,5.],[4.,3.,2.]]] 2434 values[fid4]=[[-3000,-3100,-3200],[-4000,-5000,-6000]] 2431 2435 2432 2436 for fid in [fid1,fid2,fid3]: … … 2436 2440 fid.variables[name[fid]].assignValue(values[fid]) 2437 2441 fid.variables[name[fid]].missing_value = -99999999. 2438 2442 if fid == fid3: break 2439 2443 2440 2444 for fid in [fid4]: … … 2468 2472 2469 2473 #Call conversion (with zero origin) 2470 ferret2sww('test', verbose=False, 2471 origin = (56, 0, 0)) 2474 ferret2sww('test', verbose=False, origin = (56, 0, 0)) 2472 2475 2473 2476 os.remove('test_va.nc') … … 2483 2486 elevation = fid.variables['elevation'][:] 2484 2487 stage = fid.variables['stage'][:] 2485 2486 2487 2488 2488 xmomentum = fid.variables['xmomentum'][:] 2489 ymomentum = fid.variables['ymomentum'][:] 2490 2491 #print ymomentum 2489 2492 first_height = first_amp/100 - first_elevation 2490 2493 third_height = third_amp/100 - third_elevation … … 2518 2521 #fid = NetCDFFile('small.sww', 'r') 2519 2522 fid = NetCDFFile(self.test_MOST_file + '.sww') 2520 2523 2521 2524 x = fid.variables['x'][:] 2522 2525 y = fid.variables['y'][:] … … 2642 2645 2643 2646 #os.remove(domain.filename + '.sww') 2644 os.remove(filename) 2647 os.remove(filename) 2645 2648 2646 2649 bits = ['vertex_coordinates'] … … 2782 2785 #Clean up 2783 2786 os.remove(filename) 2784 2787 2785 2788 2786 2789 bits = [ 'geo_reference.get_xllcorner()', … … 3204 3207 3205 3208 os.remove(filename) 3206 3209 3207 3210 def test_asc_csiro2sww(self): 3208 3211 import tempfile 3209 3212 3210 3213 bath_dir = tempfile.mkdtemp() 3211 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3214 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3212 3215 #bath_dir = 'bath_data_manager_test' 3213 #print "os.getcwd( )",os.getcwd( ) 3216 #print "os.getcwd( )",os.getcwd( ) 3214 3217 elevation_dir = tempfile.mkdtemp() 3215 3218 #elevation_dir = 'elev_expanded' 3216 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3217 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3218 3219 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3220 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3221 3219 3222 fid = open(bath_dir_filename, 'w') 3220 3223 fid.write(""" ncols 3 … … 3225 3228 nodata_value -9999.0 3226 3229 9000.000 -1000.000 3000.0 3227 -1000.000 9000.000 -1000.000 3230 -1000.000 9000.000 -1000.000 3228 3231 """) 3229 3232 fid.close() 3230 3233 3231 3234 fid = open(elevation_dir_filename1, 'w') 3232 3235 fid.write(""" ncols 3 … … 3237 3240 nodata_value -9999.0 3238 3241 9000.000 0.000 3000.0 3239 0.000 9000.000 0.000 3242 0.000 9000.000 0.000 3240 3243 """) 3241 3244 fid.close() … … 3249 3252 nodata_value -9999.0 3250 3253 9000.000 4000.000 4000.0 3251 4000.000 9000.000 4000.000 3254 4000.000 9000.000 4000.000 3252 3255 """) 3253 3256 fid.close() 3254 3257 3255 3258 ucur_dir = tempfile.mkdtemp() 3256 3259 ucur_dir_filename1 = ucur_dir + os.sep +'uc19940524.000' 3257 3260 ucur_dir_filename2 = ucur_dir + os.sep +'uc19940524.001' 3258 3261 3259 3262 fid = open(ucur_dir_filename1, 'w') 3260 3263 fid.write(""" ncols 3 … … 3265 3268 nodata_value -9999.0 3266 3269 90.000 60.000 30.0 3267 10.000 10.000 10.000 3270 10.000 10.000 10.000 3268 3271 """) 3269 3272 fid.close() … … 3276 3279 nodata_value -9999.0 3277 3280 90.000 60.000 30.0 3278 10.000 10.000 10.000 3281 10.000 10.000 10.000 3279 3282 """) 3280 3283 fid.close() 3281 3284 3282 3285 vcur_dir = tempfile.mkdtemp() 3283 3286 vcur_dir_filename1 = vcur_dir + os.sep +'vc19940524.000' 3284 3287 vcur_dir_filename2 = vcur_dir + os.sep +'vc19940524.001' 3285 3288 3286 3289 fid = open(vcur_dir_filename1, 'w') 3287 3290 fid.write(""" ncols 3 … … 3292 3295 nodata_value -9999.0 3293 3296 90.000 60.000 30.0 3294 10.000 10.000 10.000 3297 10.000 10.000 10.000 3295 3298 """) 3296 3299 fid.close() … … 3303 3306 nodata_value -9999.0 3304 3307 90.000 60.000 30.0 3305 10.000 10.000 10.000 3308 10.000 10.000 10.000 3306 3309 """) 3307 3310 fid.close() 3308 3311 3309 3312 sww_file = 'a_test.sww' 3310 3313 asc_csiro2sww(bath_dir,elevation_dir, ucur_dir, vcur_dir, sww_file) 3311 3314 3312 3315 # check the sww file 3313 3316 3314 3317 fid = NetCDFFile(sww_file, 'r') #Open existing file for read 3315 3318 x = fid.variables['x'][:] … … 3319 3322 xmomentum = fid.variables['xmomentum'][:] 3320 3323 geo_ref = Geo_reference(NetCDFObject=fid) 3321 #print "geo_ref",geo_ref 3324 #print "geo_ref",geo_ref 3322 3325 x_ref = geo_ref.get_xllcorner() 3323 3326 y_ref = geo_ref.get_yllcorner() … … 3325 3328 assert allclose(x_ref, 587798.418) # (-38, 148) 3326 3329 assert allclose(y_ref, 5793123.477)# (-38, 148.5) 3327 3328 #Zone: 55 3329 #Easting: 588095.674 Northing: 5821451.722 3330 3331 #Zone: 55 3332 #Easting: 588095.674 Northing: 5821451.722 3330 3333 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 0 ' 0.00000 '' 3331 3334 assert allclose((x[0],y[0]), (588095.674 - x_ref, 5821451.722 - y_ref)) 3332 3335 3333 #Zone: 55 3334 #Easting: 632145.632 Northing: 5820863.269 3335 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3336 #Zone: 55 3337 #Easting: 632145.632 Northing: 5820863.269 3338 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3336 3339 assert allclose((x[2],y[2]), (632145.632 - x_ref, 5820863.269 - y_ref)) 3337 3340 3338 #Zone: 55 3339 #Easting: 609748.788 Northing: 5793447.860 3340 #Latitude: -38 0 ' 0.00000 '' Longitude: 148 15 ' 0.00000 '' 3341 #Zone: 55 3342 #Easting: 609748.788 Northing: 5793447.860 3343 #Latitude: -38 0 ' 0.00000 '' Longitude: 148 15 ' 0.00000 '' 3341 3344 assert allclose((x[4],y[4]), (609748.788 - x_ref, 5793447.86 - y_ref)) 3342 3345 … … 3346 3349 #(4000+1000)*60 3347 3350 assert allclose(xmomentum[1][1],300000.0 ) 3348 3349 3350 fid.close() 3351 3351 3352 3353 fid.close() 3354 3352 3355 #tidy up 3353 3356 os.remove(bath_dir_filename) … … 3357 3360 os.remove(elevation_dir_filename2) 3358 3361 os.rmdir(elevation_dir) 3359 3362 3360 3363 os.remove(ucur_dir_filename1) 3361 3364 os.remove(ucur_dir_filename2) 3362 3365 os.rmdir(ucur_dir) 3363 3366 3364 3367 os.remove(vcur_dir_filename1) 3365 3368 os.remove(vcur_dir_filename2) … … 3369 3372 # remove sww file 3370 3373 os.remove(sww_file) 3371 3374 3372 3375 def test_asc_csiro2sww2(self): 3373 3376 import tempfile 3374 3377 3375 3378 bath_dir = tempfile.mkdtemp() 3376 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3379 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3377 3380 #bath_dir = 'bath_data_manager_test' 3378 #print "os.getcwd( )",os.getcwd( ) 3381 #print "os.getcwd( )",os.getcwd( ) 3379 3382 elevation_dir = tempfile.mkdtemp() 3380 3383 #elevation_dir = 'elev_expanded' 3381 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3382 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3383 3384 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3385 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3386 3384 3387 fid = open(bath_dir_filename, 'w') 3385 3388 fid.write(""" ncols 3 … … 3390 3393 nodata_value -9999.0 3391 3394 9000.000 -1000.000 3000.0 3392 -1000.000 9000.000 -1000.000 3395 -1000.000 9000.000 -1000.000 3393 3396 """) 3394 3397 fid.close() 3395 3398 3396 3399 fid = open(elevation_dir_filename1, 'w') 3397 3400 fid.write(""" ncols 3 … … 3402 3405 nodata_value -9999.0 3403 3406 9000.000 0.000 3000.0 3404 0.000 -9999.000 -9999.000 3407 0.000 -9999.000 -9999.000 3405 3408 """) 3406 3409 fid.close() … … 3414 3417 nodata_value -9999.0 3415 3418 9000.000 4000.000 4000.0 3416 4000.000 9000.000 4000.000 3419 4000.000 9000.000 4000.000 3417 3420 """) 3418 3421 fid.close() 3419 3422 3420 3423 ucur_dir = tempfile.mkdtemp() 3421 3424 ucur_dir_filename1 = ucur_dir + os.sep +'uc19940524.000' 3422 3425 ucur_dir_filename2 = ucur_dir + os.sep +'uc19940524.001' 3423 3426 3424 3427 fid = open(ucur_dir_filename1, 'w') 3425 3428 fid.write(""" ncols 3 … … 3430 3433 nodata_value -9999.0 3431 3434 90.000 60.000 30.0 3432 10.000 10.000 10.000 3435 10.000 10.000 10.000 3433 3436 """) 3434 3437 fid.close() … … 3441 3444 nodata_value -9999.0 3442 3445 90.000 60.000 30.0 3443 10.000 10.000 10.000 3446 10.000 10.000 10.000 3444 3447 """) 3445 3448 fid.close() 3446 3449 3447 3450 vcur_dir = tempfile.mkdtemp() 3448 3451 vcur_dir_filename1 = vcur_dir + os.sep +'vc19940524.000' 3449 3452 vcur_dir_filename2 = vcur_dir + os.sep +'vc19940524.001' 3450 3453 3451 3454 fid = open(vcur_dir_filename1, 'w') 3452 3455 fid.write(""" ncols 3 … … 3457 3460 nodata_value -9999.0 3458 3461 90.000 60.000 30.0 3459 10.000 10.000 10.000 3462 10.000 10.000 10.000 3460 3463 """) 3461 3464 fid.close() … … 3468 3471 nodata_value -9999.0 3469 3472 90.000 60.000 30.0 3470 10.000 10.000 10.000 3473 10.000 10.000 10.000 3471 3474 """) 3472 3475 fid.close() 3473 3476 3474 3477 try: 3475 3478 asc_csiro2sww(bath_dir,elevation_dir, ucur_dir, … … 3483 3486 os.remove(elevation_dir_filename2) 3484 3487 os.rmdir(elevation_dir) 3485 3488 3486 3489 os.remove(ucur_dir_filename1) 3487 3490 os.remove(ucur_dir_filename2) 3488 3491 os.rmdir(ucur_dir) 3489 3492 3490 3493 os.remove(vcur_dir_filename1) 3491 3494 os.remove(vcur_dir_filename2) … … 3500 3503 os.rmdir(elevation_dir) 3501 3504 raise 'Should raise exception' 3502 3505 3503 3506 os.remove(ucur_dir_filename1) 3504 3507 os.remove(ucur_dir_filename2) 3505 3508 os.rmdir(ucur_dir) 3506 3509 3507 3510 os.remove(vcur_dir_filename1) 3508 3511 os.remove(vcur_dir_filename2) 3509 3512 os.rmdir(vcur_dir) 3510 3513 3511 3512 3514 3515 3513 3516 def test_asc_csiro2sww3(self): 3514 3517 import tempfile 3515 3518 3516 3519 bath_dir = tempfile.mkdtemp() 3517 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3520 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3518 3521 #bath_dir = 'bath_data_manager_test' 3519 #print "os.getcwd( )",os.getcwd( ) 3522 #print "os.getcwd( )",os.getcwd( ) 3520 3523 elevation_dir = tempfile.mkdtemp() 3521 3524 #elevation_dir = 'elev_expanded' 3522 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3523 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3524 3525 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3526 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3527 3525 3528 fid = open(bath_dir_filename, 'w') 3526 3529 fid.write(""" ncols 3 … … 3531 3534 nodata_value -9999.0 3532 3535 9000.000 -1000.000 3000.0 3533 -1000.000 9000.000 -1000.000 3536 -1000.000 9000.000 -1000.000 3534 3537 """) 3535 3538 fid.close() 3536 3539 3537 3540 fid = open(elevation_dir_filename1, 'w') 3538 3541 fid.write(""" ncols 3 … … 3543 3546 nodata_value -9999.0 3544 3547 9000.000 0.000 3000.0 3545 0.000 -9999.000 -9999.000 3548 0.000 -9999.000 -9999.000 3546 3549 """) 3547 3550 fid.close() … … 3555 3558 nodata_value -9999.0 3556 3559 9000.000 4000.000 4000.0 3557 4000.000 9000.000 4000.000 3560 4000.000 9000.000 4000.000 3558 3561 """) 3559 3562 fid.close() 3560 3563 3561 3564 ucur_dir = tempfile.mkdtemp() 3562 3565 ucur_dir_filename1 = ucur_dir + os.sep +'uc19940524.000' 3563 3566 ucur_dir_filename2 = ucur_dir + os.sep +'uc19940524.001' 3564 3567 3565 3568 fid = open(ucur_dir_filename1, 'w') 3566 3569 fid.write(""" ncols 3 … … 3571 3574 nodata_value -9999.0 3572 3575 90.000 60.000 30.0 3573 10.000 10.000 10.000 3576 10.000 10.000 10.000 3574 3577 """) 3575 3578 fid.close() … … 3582 3585 nodata_value -9999.0 3583 3586 90.000 60.000 30.0 3584 10.000 10.000 10.000 3587 10.000 10.000 10.000 3585 3588 """) 3586 3589 fid.close() 3587 3590 3588 3591 vcur_dir = tempfile.mkdtemp() 3589 3592 vcur_dir_filename1 = vcur_dir + os.sep +'vc19940524.000' 3590 3593 vcur_dir_filename2 = vcur_dir + os.sep +'vc19940524.001' 3591 3594 3592 3595 fid = open(vcur_dir_filename1, 'w') 3593 3596 fid.write(""" ncols 3 … … 3598 3601 nodata_value -9999.0 3599 3602 90.000 60.000 30.0 3600 10.000 10.000 10.000 3603 10.000 10.000 10.000 3601 3604 """) 3602 3605 fid.close() … … 3609 3612 nodata_value -9999.0 3610 3613 90.000 60.000 30.0 3611 10.000 10.000 10.000 3614 10.000 10.000 10.000 3612 3615 """) 3613 3616 fid.close() 3614 3617 3615 3618 sww_file = 'a_test.sww' 3616 3619 asc_csiro2sww(bath_dir,elevation_dir, ucur_dir, vcur_dir, … … 3619 3622 3620 3623 # check the sww file 3621 3624 3622 3625 fid = NetCDFFile(sww_file, 'r') #Open existing file for read 3623 3626 x = fid.variables['x'][:] … … 3627 3630 xmomentum = fid.variables['xmomentum'][:] 3628 3631 geo_ref = Geo_reference(NetCDFObject=fid) 3629 #print "geo_ref",geo_ref 3632 #print "geo_ref",geo_ref 3630 3633 x_ref = geo_ref.get_xllcorner() 3631 3634 y_ref = geo_ref.get_yllcorner() … … 3633 3636 assert allclose(x_ref, 587798.418) # (-38, 148) 3634 3637 assert allclose(y_ref, 5793123.477)# (-38, 148.5) 3635 3636 #Zone: 55 3637 #Easting: 588095.674 Northing: 5821451.722 3638 3639 #Zone: 55 3640 #Easting: 588095.674 Northing: 5821451.722 3638 3641 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 0 ' 0.00000 '' 3639 3642 assert allclose((x[0],y[0]), (588095.674 - x_ref, 5821451.722 - y_ref)) 3640 3643 3641 #Zone: 55 3642 #Easting: 632145.632 Northing: 5820863.269 3643 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3644 #Zone: 55 3645 #Easting: 632145.632 Northing: 5820863.269 3646 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3644 3647 assert allclose((x[2],y[2]), (632145.632 - x_ref, 5820863.269 - y_ref)) 3645 3648 3646 #Zone: 55 3647 #Easting: 609748.788 Northing: 5793447.860 3648 #Latitude: -38 0 ' 0.00000 '' Longitude: 148 15 ' 0.00000 '' 3649 #Zone: 55 3650 #Easting: 609748.788 Northing: 5793447.860 3651 #Latitude: -38 0 ' 0.00000 '' Longitude: 148 15 ' 0.00000 '' 3649 3652 assert allclose((x[4],y[4]), (609748.788 - x_ref, 5793447.86 - y_ref)) 3650 3653 … … 3655 3658 #(100.0 - 9000)*10 3656 3659 assert allclose(xmomentum[0][4], -89000.0 ) 3657 3660 3658 3661 #(100.0 - -1000.000)*10 3659 3662 assert allclose(xmomentum[0][5], 11000.0 ) 3660 3661 fid.close() 3662 3663 3664 fid.close() 3665 3663 3666 #tidy up 3664 3667 os.remove(bath_dir_filename) … … 3668 3671 os.remove(elevation_dir_filename2) 3669 3672 os.rmdir(elevation_dir) 3670 3673 3671 3674 os.remove(ucur_dir_filename1) 3672 3675 os.remove(ucur_dir_filename2) 3673 3676 os.rmdir(ucur_dir) 3674 3677 3675 3678 os.remove(vcur_dir_filename1) 3676 3679 os.remove(vcur_dir_filename2) … … 3679 3682 # remove sww file 3680 3683 os.remove(sww_file) 3681 3682 3684 3685 3683 3686 def test_asc_csiro2sww4(self): 3684 3687 """ 3685 3688 Test specifying the extent 3686 3689 """ 3687 3690 3688 3691 import tempfile 3689 3692 3690 3693 bath_dir = tempfile.mkdtemp() 3691 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3694 bath_dir_filename = bath_dir + os.sep +'ba19940524.000' 3692 3695 #bath_dir = 'bath_data_manager_test' 3693 #print "os.getcwd( )",os.getcwd( ) 3696 #print "os.getcwd( )",os.getcwd( ) 3694 3697 elevation_dir = tempfile.mkdtemp() 3695 3698 #elevation_dir = 'elev_expanded' 3696 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3697 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3698 3699 elevation_dir_filename1 = elevation_dir + os.sep +'el19940524.000' 3700 elevation_dir_filename2 = elevation_dir + os.sep +'el19940524.001' 3701 3699 3702 fid = open(bath_dir_filename, 'w') 3700 3703 fid.write(""" ncols 4 … … 3710 3713 """) 3711 3714 fid.close() 3712 3715 3713 3716 fid = open(elevation_dir_filename1, 'w') 3714 3717 fid.write(""" ncols 4 … … 3738 3741 """) 3739 3742 fid.close() 3740 3743 3741 3744 ucur_dir = tempfile.mkdtemp() 3742 3745 ucur_dir_filename1 = ucur_dir + os.sep +'uc19940524.000' 3743 3746 ucur_dir_filename2 = ucur_dir + os.sep +'uc19940524.001' 3744 3747 3745 3748 fid = open(ucur_dir_filename1, 'w') 3746 3749 fid.write(""" ncols 4 … … 3769 3772 """) 3770 3773 fid.close() 3771 3774 3772 3775 vcur_dir = tempfile.mkdtemp() 3773 3776 vcur_dir_filename1 = vcur_dir + os.sep +'vc19940524.000' 3774 3777 vcur_dir_filename2 = vcur_dir + os.sep +'vc19940524.001' 3775 3778 3776 3779 fid = open(vcur_dir_filename1, 'w') 3777 3780 fid.write(""" ncols 4 … … 3800 3803 """) 3801 3804 fid.close() 3802 3805 3803 3806 sww_file = tempfile.mktemp(".sww") 3804 3807 #sww_file = 'a_test.sww' … … 3812 3815 3813 3816 # check the sww file 3814 3817 3815 3818 fid = NetCDFFile(sww_file, 'r') #Open existing file for read 3816 3819 x = fid.variables['x'][:] … … 3821 3824 ymomentum = fid.variables['ymomentum'][:] 3822 3825 geo_ref = Geo_reference(NetCDFObject=fid) 3823 #print "geo_ref",geo_ref 3826 #print "geo_ref",geo_ref 3824 3827 x_ref = geo_ref.get_xllcorner() 3825 3828 y_ref = geo_ref.get_yllcorner() … … 3830 3833 assert allclose(y_ref, 5820863.269 )# (-37.45, 148.5) 3831 3834 3832 #Easting: 632145.632 Northing: 5820863.269 3833 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3834 3835 #Easting: 632145.632 Northing: 5820863.269 3836 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3837 3835 3838 #print "x",x 3836 #print "y",y 3839 #print "y",y 3837 3840 self.failUnless(len(x) == 4,'failed') # 2*2 3838 3841 self.failUnless(len(x) == 4,'failed') # 2*2 3839 3842 3840 3843 #Zone: 55 3841 #Easting: 632145.632 Northing: 5820863.269 3844 #Easting: 632145.632 Northing: 5820863.269 3842 3845 #Latitude: -37 45 ' 0.00000 '' Longitude: 148 30 ' 0.00000 '' 3843 # magic number - y is close enough for me. 3846 # magic number - y is close enough for me. 3844 3847 assert allclose(x[3], 632145.63 - x_ref) 3845 3848 assert allclose(y[3], 5820863.269 - y_ref + 5.22155314684e-005) 3846 3849 3847 3850 assert allclose(z[0],9000.0 ) #z is elevation info 3848 #print "z",z 3851 #print "z",z 3849 3852 # 2 time steps, 4 points 3850 self.failUnless(xmomentum.shape == (2,4), 'failed') 3851 self.failUnless(ymomentum.shape == (2,4), 'failed') 3852 3853 self.failUnless(xmomentum.shape == (2,4), 'failed') 3854 self.failUnless(ymomentum.shape == (2,4), 'failed') 3855 3853 3856 #(100.0 - -1000.000)*10 3854 3857 #assert allclose(xmomentum[0][5], 11000.0 ) 3855 3856 fid.close() 3857 3858 3859 fid.close() 3860 3858 3861 # is the sww file readable? 3859 3862 #Lets see if we can convert it to a dem! 3860 #print "sww_file",sww_file 3863 #print "sww_file",sww_file 3861 3864 #dem_file = tempfile.mktemp(".dem") 3862 3865 domain = sww2domain(sww_file) ###, dem_file) … … 3870 3873 os.remove(elevation_dir_filename2) 3871 3874 os.rmdir(elevation_dir) 3872 3875 3873 3876 os.remove(ucur_dir_filename1) 3874 3877 os.remove(ucur_dir_filename2) 3875 3878 os.rmdir(ucur_dir) 3876 3879 3877 3880 os.remove(vcur_dir_filename1) 3878 3881 os.remove(vcur_dir_filename2) … … 3880 3883 3881 3884 3882 3883 3885 3886 3884 3887 # remove sww file 3885 3888 os.remove(sww_file) 3886 3889 3887 3890 # remove dem file 3888 3891 #os.remove(dem_file) … … 3907 3910 longitudes == longitudes_news, 3908 3911 'failed') 3909 3912 3910 3913 ## 2nd test 3911 3914 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes( … … 3918 3921 #print "latitudes_new", latitudes_new 3919 3922 #print "longitudes_news",longitudes_news 3920 3923 3921 3924 self.failUnless(latitudes == latitudes_new and \ 3922 3925 longitudes == longitudes_news, 3923 3926 'failed') 3924 3927 3925 3928 ## 3rd test 3926 3929 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes(latitudes, … … 3933 3936 #print "latitudes_new", latitudes_new 3934 3937 #print "longitudes_news",longitudes_news 3935 3938 3936 3939 self.failUnless(latitudes_new == [2, 1] and \ 3937 3940 longitudes_news == [10, 20], 3938 3941 'failed') 3939 3942 3940 3943 3941 3944 ## 4th test 3942 3945 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes( … … 3949 3952 #print "latitudes_new", latitudes_new 3950 3953 #print "longitudes_news",longitudes_news 3951 3954 3952 3955 self.failUnless(latitudes_new == [2, 1, 0] and \ 3953 3956 longitudes_news == [0, 10, 20], … … 3963 3966 #print "latitudes_new", latitudes_new 3964 3967 #print "longitudes_news",longitudes_news 3965 3968 3966 3969 self.failUnless(latitudes_new == [2, 1, 0] and \ 3967 3970 longitudes_news == [0, 10, 20], 3968 3971 'failed') 3969 3972 3970 3973 ## 6th test 3971 3974 3972 3975 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes( 3973 3976 latitudes,longitudes, … … 3979 3982 #print "latitudes_new", latitudes_new 3980 3983 #print "longitudes_news",longitudes_news 3981 3984 3982 3985 self.failUnless(latitudes_new == [3, 2, 1] and \ 3983 3986 longitudes_news == [10, 20, 30], 3984 3987 'failed') 3985 3986 3988 3989 3987 3990 ## 7th test 3988 3991 m2d = array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]) … … 3995 3998 longitudes_news = longitudes[lmin:lmax] 3996 3999 m2d = m2d[kmin:kmax,lmin:lmax] 3997 #print "m2d", m2d 4000 #print "m2d", m2d 3998 4001 #print "latitudes_new", latitudes_new 3999 4002 #print "longitudes_news",longitudes_news 4000 4003 4001 4004 self.failUnless(latitudes_new == [2, 1] and \ 4002 4005 longitudes_news == [10, 20], 4003 4006 'failed') 4004 4007 4005 4008 self.failUnless(m2d == [[5,6],[9,10]], 4006 4009 'failed') 4007 4010 4008 4011 def test_get_min_max_indexes2(self): 4009 4012 latitudes = [-30,-35,-40,-45] … … 4011 4014 4012 4015 m2d = array([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]]) 4013 4016 4014 4017 # k - lat 4015 4018 # l - lon … … 4020 4023 #print "kmin",kmin;print "kmax",kmax 4021 4024 #print "lmin",lmin;print "lmax",lmax 4022 #print "m2d", m2d 4025 #print "m2d", m2d 4023 4026 #print "latitudes", latitudes 4024 4027 #print "longitudes",longitudes 4025 #print "latitudes[kmax]", latitudes[kmax] 4028 #print "latitudes[kmax]", latitudes[kmax] 4026 4029 latitudes_new = latitudes[kmin:kmax] 4027 4030 longitudes_new = longitudes[lmin:lmax] … … 4030 4033 #print "latitudes_new", latitudes_new 4031 4034 #print "longitudes_new",longitudes_new 4032 4035 4033 4036 self.failUnless(latitudes_new == [-30, -35, -40] and \ 4034 4037 longitudes_new == [148, 149,150], … … 4036 4039 self.failUnless(m2d == [[0,1,2],[4,5,6],[8,9,10]], 4037 4040 'failed') 4038 4041 4039 4042 def test_get_min_max_indexes3(self): 4040 4043 latitudes = [-30,-35,-40,-45,-50,-55,-60] … … 4047 4050 -43,-37,148.5,149.5) 4048 4051 4049 4052 4050 4053 #print "kmin",kmin;print "kmax",kmax 4051 4054 #print "lmin",lmin;print "lmax",lmax … … 4056 4059 #print "latitudes_new", latitudes_new 4057 4060 #print "longitudes_news",longitudes_news 4058 4061 4059 4062 self.failUnless(latitudes_new == [-35, -40, -45] and \ 4060 4063 longitudes_news == [148, 149,150], 4061 4064 'failed') 4062 4065 4063 4066 def test_get_min_max_indexes4(self): 4064 4067 latitudes = [-30,-35,-40,-45,-50,-55,-60] … … 4069 4072 kmin, kmax, lmin, lmax = data_manager._get_min_max_indexes( 4070 4073 latitudes,longitudes) 4071 4074 4072 4075 #print "kmin",kmin;print "kmax",kmax 4073 4076 #print "lmin",lmin;print "lmax",lmax … … 4078 4081 #print "latitudes_new", latitudes_new 4079 4082 #print "longitudes_news",longitudes_news 4080 4083 4081 4084 self.failUnless(latitudes_new == latitudes and \ 4082 4085 longitudes_news == longitudes, 4083 4086 'failed') 4084 4087 4085 4088 def test_tsh2sww(self): 4086 4089 import os 4087 4090 import tempfile 4088 4091 4089 4092 tsh_file = tempfile.mktemp(".tsh") 4090 4093 file = open(tsh_file,"w") … … 4124 4127 4125 4128 #sww_file = tempfile.mktemp(".sww") 4126 #print "sww_file",sww_file 4129 #print "sww_file",sww_file 4127 4130 #print "sww_file",tsh_file 4128 4131 tsh2sww(tsh_file) … … 4135 4138 suite = unittest.makeSuite(Test_Data_Manager,'test') 4136 4139 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_missing_points') 4137 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_elevation') 4140 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww2dem_asc_elevation') 4138 4141 #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box') 4139 4142 #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem') … … 4141 4144 runner = unittest.TextTestRunner() 4142 4145 runner.run(suite) 4143 4146 4144 4147 4145 4148 … … 4378 4381 if i == 3 and j == 3: z = NODATA_value 4379 4382 4380 4383 4381 4384 if z <> NODATA_value: 4382 4385 new_ref_elev.append(z) 4383 4386 new_ref_pts.append( [x,y] ) 4384 4387 4385 4388 ref_points.append( [x,y] ) 4386 4389 ref_elevation.append(z) … … 4391 4394 fid.close() 4392 4395 4393 4396 4394 4397 #Write prj file with metadata 4395 4398 metafilename = root+'.prj' … … 4482 4485 new_ref_elev1.append(z) 4483 4486 new_ref_pts1.append( [x,y] ) 4484 4487 4485 4488 ref_points.append( [x,y] ) 4486 4489 ref_elevation.append(z) … … 4506 4509 """) 4507 4510 fid.close() 4508 4511 4509 4512 #Convert to NetCDF pts 4510 4513 convert_dem_from_ascii2netcdf(root) … … 4549 4552 new_ref_pts2.append( [x_new,y_new] ) 4550 4553 4551 4554 4552 4555 ref_points.append( [x_new,y_new] ) 4553 4556 ref_elevation.append(z) … … 4561 4564 #assert allclose(elevation, ref_elevation) 4562 4565 4563 4566 4564 4567 assert len(points) == len(new_ref_pts2), 'length of returned points not correct' 4565 4568 assert allclose(points, new_ref_pts2), 'points do not align' … … 4580 4583 4581 4584 4582
Note: See TracChangeset
for help on using the changeset viewer.