Changeset 1865 for inundation/pyvolution/test_data_manager.py
- Timestamp:
- Oct 4, 2005, 8:39:27 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_data_manager.py
r1864 r1865 740 740 741 741 742 def test_sww2 asc_elevation(self):742 def test_sww2dem_asc_elevation(self): 743 743 """Test that sww information can be converted correctly to asc/prj 744 744 format readable by e.g. ArcView … … 785 785 786 786 #Export to ascii/prj files 787 sww2 asc(self.domain.filename,787 sww2dem(self.domain.filename, 788 788 quantity = 'elevation', 789 789 cellsize = cellsize, 790 verbose = False )791 792 790 verbose = False, 791 format = 'asc') 792 793 793 #Check prj (meta data) 794 794 prjid = open(prjfile) … … 877 877 878 878 879 def test_sww2 asc_stage_reduction(self):879 def test_sww2dem_asc_stage_reduction(self): 880 880 """Test that sww information can be converted correctly to asc/prj 881 881 format readable by e.g. ArcView … … 925 925 926 926 #Export to ascii/prj files 927 sww2 asc(self.domain.filename,927 sww2dem(self.domain.filename, 928 928 quantity = 'stage', 929 929 cellsize = cellsize, 930 reduction = min) 930 reduction = min, 931 format = 'asc') 931 932 932 933 … … 986 987 987 988 988 def test_sww2 asc_missing_points(self):989 def test_sww2dem_asc_missing_points(self): 989 990 """Test that sww information can be converted correctly to asc/prj 990 991 format readable by e.g. ArcView … … 1073 1074 1074 1075 #Export to ascii/prj files 1075 sww2 asc(domain.filename,1076 sww2dem(domain.filename, 1076 1077 quantity = 'elevation', 1077 1078 cellsize = cellsize, 1078 verbose = False) 1079 verbose = False, 1080 format = 'asc') 1079 1081 1080 1082 … … 1128 1130 os.remove(ascfile) 1129 1131 os.remove(swwfile) 1132 1133 def test_sww2ers_simple(self): 1134 """Test that sww information can be converted correctly to asc/prj 1135 format readable by e.g. ArcView 1136 """ 1137 1138 import time, os 1139 from Numeric import array, zeros, allclose, Float, concatenate 1140 from Scientific.IO.NetCDF import NetCDFFile 1141 1142 #Setup 1143 self.domain.filename = 'datatest' 1144 1145 headerfile = self.domain.filename + '.ers' 1146 swwfile = self.domain.filename + '.sww' 1147 1148 self.domain.set_datadir('.') 1149 self.domain.format = 'sww' 1150 self.domain.smooth = True 1151 self.domain.set_quantity('elevation', lambda x,y: -x-y) 1152 1153 self.domain.geo_reference = Geo_reference(56,308500,6189000) 1154 1155 sww = get_dataobject(self.domain) 1156 sww.store_connectivity() 1157 sww.store_timestep('stage') 1158 1159 self.domain.evolve_to_end(finaltime = 0.01) 1160 sww.store_timestep('stage') 1161 1162 cellsize = 0.25 1163 #Check contents 1164 #Get NetCDF 1165 1166 fid = NetCDFFile(sww.filename, 'r') 1167 1168 # Get the variables 1169 x = fid.variables['x'][:] 1170 y = fid.variables['y'][:] 1171 z = fid.variables['elevation'][:] 1172 time = fid.variables['time'][:] 1173 stage = fid.variables['stage'][:] 1174 1175 1176 #Export to ers files 1177 #sww2ers(self.domain.filename, 1178 # quantity = 'elevation', 1179 # cellsize = cellsize, 1180 # verbose = False) 1181 1182 sww2dem(self.domain.filename, 1183 quantity = 'elevation', 1184 cellsize = cellsize, 1185 verbose = False, 1186 format = 'ers') 1187 1188 #Check header data 1189 from ermapper_grids import read_ermapper_header, read_ermapper_data 1190 1191 header = read_ermapper_header(self.domain.filename + '_elevation.ers') 1192 #print header 1193 assert header['projection'].lower() == '"utm-56"' 1194 assert header['datum'].lower() == '"wgs84"' 1195 assert header['units'].lower() == '"meters"' 1196 assert header['value'].lower() == '"elevation"' 1197 assert header['xdimension'] == '0.25' 1198 assert header['ydimension'] == '0.25' 1199 assert float(header['eastings']) == 308500.0 #xllcorner 1200 assert float(header['northings']) == 6189000.0 #yllcorner 1201 assert int(header['nroflines']) == 5 1202 assert int(header['nrofcellsperline']) == 5 1203 assert int(header['nullcellvalue']) == 0 #? 1204 #FIXME - there is more in the header 1205 1206 1207 #Check grid data 1208 grid = read_ermapper_data(self.domain.filename + '_elevation') 1209 1210 #FIXME (Ole): Why is this the desired reference grid for -x-y? 1211 ref_grid = [0, 0, 0, 0, 0, 1212 -1, -1.25, -1.5, -1.75, -2.0, 1213 -0.75, -1.0, -1.25, -1.5, -1.75, 1214 -0.5, -0.75, -1.0, -1.25, -1.5, 1215 -0.25, -0.5, -0.75, -1.0, -1.25] 1216 1217 1218 assert allclose(grid, ref_grid) 1219 1220 fid.close() 1221 1222 #Cleanup 1223 #FIXME the file clean-up doesn't work (eg Permission Denied Error) 1224 #Done (Ole) - it was because sww2ers didn't close it's sww file 1225 os.remove(sww.filename) 1226 1227 1228 def xxxtestz_sww2ers_real(self): 1229 """Test that sww information can be converted correctly to asc/prj 1230 format readable by e.g. ArcView 1231 """ 1232 1233 import time, os 1234 from Numeric import array, zeros, allclose, Float, concatenate 1235 from Scientific.IO.NetCDF import NetCDFFile 1236 1237 1238 1239 1240 #Export to ascii/prj files 1241 sww2ers('karratha_100m.sww', 1242 quantity = 'depth', 1243 cellsize = 5, 1244 verbose = False) 1130 1245 1131 1246 … … 2052 2167 os.remove(root + '_100.dem') 2053 2168 2054 def test_sww2ers_simple(self):2055 """Test that sww information can be converted correctly to asc/prj2056 format readable by e.g. ArcView2057 """2058 2059 import time, os2060 from Numeric import array, zeros, allclose, Float, concatenate2061 from Scientific.IO.NetCDF import NetCDFFile2062 2063 #Setup2064 self.domain.filename = 'datatest'2065 2066 headerfile = self.domain.filename + '.ers'2067 swwfile = self.domain.filename + '.sww'2068 2069 self.domain.set_datadir('.')2070 self.domain.format = 'sww'2071 self.domain.smooth = True2072 self.domain.set_quantity('elevation', lambda x,y: -x-y)2073 2074 self.domain.geo_reference = Geo_reference(56,308500,6189000)2075 2076 sww = get_dataobject(self.domain)2077 sww.store_connectivity()2078 sww.store_timestep('stage')2079 2080 self.domain.evolve_to_end(finaltime = 0.01)2081 sww.store_timestep('stage')2082 2083 cellsize = 0.252084 #Check contents2085 #Get NetCDF2086 2087 fid = NetCDFFile(sww.filename, 'r')2088 2089 # Get the variables2090 x = fid.variables['x'][:]2091 y = fid.variables['y'][:]2092 z = fid.variables['elevation'][:]2093 time = fid.variables['time'][:]2094 stage = fid.variables['stage'][:]2095 2096 2097 #Export to ascii/prj files2098 sww2ers(self.domain.filename,2099 quantity = 'elevation',2100 cellsize = cellsize,2101 verbose = False)2102 2103 #FIXME (Ole) Why aren't we testing anything2104 2105 ## #Check prj (meta data)2106 ## prjid = open(prjfile)2107 ## lines = prjid.readlines()2108 ## prjid.close()2109 ##2110 ## L = lines[0].strip().split()2111 ## assert L[0].strip().lower() == 'projection'2112 ## assert L[1].strip().lower() == 'utm'2113 ##2114 ## L = lines[1].strip().split()2115 ## assert L[0].strip().lower() == 'zone'2116 ## assert L[1].strip().lower() == '56'2117 ##2118 ## L = lines[2].strip().split()2119 ## assert L[0].strip().lower() == 'datum'2120 ## assert L[1].strip().lower() == 'wgs84'2121 ##2122 ## L = lines[3].strip().split()2123 ## assert L[0].strip().lower() == 'zunits'2124 ## assert L[1].strip().lower() == 'no'2125 ##2126 ## L = lines[4].strip().split()2127 ## assert L[0].strip().lower() == 'units'2128 ## assert L[1].strip().lower() == 'meters'2129 ##2130 ## L = lines[5].strip().split()2131 ## assert L[0].strip().lower() == 'spheroid'2132 ## assert L[1].strip().lower() == 'wgs84'2133 ##2134 ## L = lines[6].strip().split()2135 ## assert L[0].strip().lower() == 'xshift'2136 ## assert L[1].strip().lower() == '500000'2137 ##2138 ## L = lines[7].strip().split()2139 ## assert L[0].strip().lower() == 'yshift'2140 ## assert L[1].strip().lower() == '10000000'2141 ##2142 ## L = lines[8].strip().split()2143 ## assert L[0].strip().lower() == 'parameters'2144 ##2145 ##2146 ## #Check asc file2147 ## ascid = open(ascfile)2148 ## lines = ascid.readlines()2149 ## ascid.close()2150 ##2151 ## L = lines[0].strip().split()2152 ## assert L[0].strip().lower() == 'ncols'2153 ## assert L[1].strip().lower() == '5'2154 ##2155 ## L = lines[1].strip().split()2156 ## assert L[0].strip().lower() == 'nrows'2157 ## assert L[1].strip().lower() == '5'2158 ##2159 ## L = lines[2].strip().split()2160 ## assert L[0].strip().lower() == 'xllcorner'2161 ## assert allclose(float(L[1].strip().lower()), 308500)2162 ##2163 ## L = lines[3].strip().split()2164 ## assert L[0].strip().lower() == 'yllcorner'2165 ## assert allclose(float(L[1].strip().lower()), 6189000)2166 ##2167 ## L = lines[4].strip().split()2168 ## assert L[0].strip().lower() == 'cellsize'2169 ## assert allclose(float(L[1].strip().lower()), cellsize)2170 ##2171 ## L = lines[5].strip().split()2172 ## assert L[0].strip() == 'NODATA_value'2173 ## assert L[1].strip().lower() == '-9999'2174 ##2175 ## #Check grid values2176 ## for j in range(5):2177 ## L = lines[6+j].strip().split()2178 ## y = (4-j) * cellsize2179 ## for i in range(5):2180 ## assert allclose(float(L[i]), -i*cellsize - y)2181 ##2182 2183 fid.close()2184 2185 #Cleanup2186 #FIXME the file clean-up doesn't work (eg Permission Denied Error)2187 #Done (Ole) - it was because sww2ers didn't close it's sww file2188 os.remove(sww.filename)2189 2190 2191 def xxxtestz_sww2ers_real(self):2192 """Test that sww information can be converted correctly to asc/prj2193 format readable by e.g. ArcView2194 """2195 2196 import time, os2197 from Numeric import array, zeros, allclose, Float, concatenate2198 from Scientific.IO.NetCDF import NetCDFFile2199 2200 2201 2202 2203 #Export to ascii/prj files2204 sww2ers('karratha_100m.sww',2205 quantity = 'depth',2206 cellsize = 5,2207 verbose = False)2208 2209 2169 2210 2170
Note: See TracChangeset
for help on using the changeset viewer.