Changeset 1669
- Timestamp:
- Aug 2, 2005, 12:36:06 PM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/data_manager.py
r1667 r1669 2402 2402 """ 2403 2403 2404 #FIXME: does not yet deal sensibly with NODATA values, they are2405 # included in calculations2406 2407 2404 import os 2408 2405 from Scientific.IO.NetCDF import NetCDFFile 2409 from Numeric import Float, zeros, sum, reshape 2406 from Numeric import Float, zeros, sum, reshape, equal 2410 2407 2411 2408 root = basename_in … … 2493 2490 for j in range(ncols_new): 2494 2491 tcol = j * cellsize_ratio 2495 telev[local_index] = \ 2496 sum(sum(dem_elevation_r[trow:trow+nrows_stencil, tcol:tcol+ncols_stencil] * stencil)) 2492 tmp = dem_elevation_r[trow:trow+nrows_stencil, tcol:tcol+ncols_stencil] 2493 2494 #if dem contains 1 or more NODATA_values set value in 2495 #decimated dem to NODATA_value, else compute decimated 2496 #value using stencil 2497 if sum(sum(equal(tmp, NODATA_value))) > 0: 2498 telev[local_index] = NODATA_value 2499 else: 2500 telev[local_index] = sum(sum(tmp * stencil)) 2501 2497 2502 global_index += 1 2498 2503 local_index += 1 -
inundation/ga/storm_surge/pyvolution/test_data_manager.py
r1666 r1669 1902 1902 os.remove(root + '_100.dem') 1903 1903 1904 def test_decimate_dem_NODATA(self): 1905 """Test decimation of dem file that includes NODATA values 1906 """ 1907 1908 import os 1909 from Numeric import ones, allclose, Float, arange, reshape 1910 from Scientific.IO.NetCDF import NetCDFFile 1911 1912 #Write test dem file 1913 root = 'decdemtest' 1914 1915 filename = root + '.dem' 1916 fid = NetCDFFile(filename, 'w') 1917 1918 fid.institution = 'Geoscience Australia' 1919 fid.description = 'NetCDF DEM format for compact and portable ' +\ 1920 'storage of spatial point data' 1921 1922 nrows = 15 1923 ncols = 18 1924 NODATA_value = -9999 1925 1926 fid.ncols = ncols 1927 fid.nrows = nrows 1928 fid.xllcorner = 2000.5 1929 fid.yllcorner = 3000.5 1930 fid.cellsize = 25 1931 fid.NODATA_value = NODATA_value 1932 1933 fid.zone = 56 1934 fid.false_easting = 0.0 1935 fid.false_northing = 0.0 1936 fid.projection = 'UTM' 1937 fid.datum = 'WGS84' 1938 fid.units = 'METERS' 1939 1940 fid.createDimension('number_of_points', nrows*ncols) 1941 1942 fid.createVariable('elevation', Float, ('number_of_points',)) 1943 1944 elevation = fid.variables['elevation'] 1945 1946 #generate initial elevation values 1947 elevation_tmp = (arange(nrows*ncols)) 1948 #add some NODATA values 1949 elevation_tmp[0] = NODATA_value 1950 elevation_tmp[95] = NODATA_value 1951 elevation_tmp[188] = NODATA_value 1952 elevation_tmp[189] = NODATA_value 1953 elevation_tmp[190] = NODATA_value 1954 elevation_tmp[209] = NODATA_value 1955 elevation_tmp[252] = NODATA_value 1956 1957 elevation[:] = elevation_tmp 1958 1959 fid.close() 1960 1961 #generate the elevation values expected in the decimated file 1962 ref_elevation = [NODATA_value, 1963 ( 4+ 5+ 6+ 22+ 23+ 24+ 40+ 41+ 42) / 9.0, 1964 ( 8+ 9+ 10+ 26+ 27+ 28+ 44+ 45+ 46) / 9.0, 1965 ( 12+ 13+ 14+ 30+ 31+ 32+ 48+ 49+ 50) / 9.0, 1966 ( 72+ 73+ 74+ 90+ 91+ 92+108+109+110) / 9.0, 1967 NODATA_value, 1968 ( 80+ 81+ 82+ 98+ 99+100+116+117+118) / 9.0, 1969 ( 84+ 85+ 86+102+103+104+120+121+122) / 9.0, 1970 (144+145+146+162+163+164+180+181+182) / 9.0, 1971 (148+149+150+166+167+168+184+185+186) / 9.0, 1972 NODATA_value, 1973 (156+157+158+174+175+176+192+193+194) / 9.0, 1974 NODATA_value, 1975 (220+221+222+238+239+240+256+257+258) / 9.0, 1976 (224+225+226+242+243+244+260+261+262) / 9.0, 1977 (228+229+230+246+247+248+264+265+266) / 9.0] 1978 1979 #generate a stencil for computing the decimated values 1980 stencil = ones((3,3), Float) / 9.0 1981 1982 decimate_dem(root, stencil=stencil, cellsize_new=100) 1983 1984 #Open decimated NetCDF file 1985 fid = NetCDFFile(root + '_100.dem', 'r') 1986 1987 # Get decimated elevation 1988 elevation = fid.variables['elevation'] 1989 1990 #Check values 1991 assert allclose(elevation, ref_elevation) 1992 1993 #Cleanup 1994 fid.close() 1995 1996 os.remove(root + '.dem') 1997 os.remove(root + '_100.dem') 1998 1904 1999 1905 2000 #------------------------------------------------------------- … … 1907 2002 #suite = unittest.makeSuite(Test_Data_Manager,'test') 1908 2003 #suite = unittest.makeSuite(Test_Data_Manager,'test_dem2pts_bounding_box') 1909 suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem') 2004 #suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem') 2005 suite = unittest.makeSuite(Test_Data_Manager,'test_decimate_dem_NODATA') 1910 2006 runner = unittest.TextTestRunner() 1911 2007 runner.run(suite)
Note: See TracChangeset
for help on using the changeset viewer.