Changeset 1919 for inundation/pyvolution/test_data_manager.py
- Timestamp:
- Oct 14, 2005, 11:26:21 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/pyvolution/test_data_manager.py
r1902 r1919 1351 1351 1352 1352 1353 def test_sww2dem_asc_derived_quantity(self): 1354 """Test that sww information can be converted correctly to asc/prj 1355 format readable by e.g. ArcView 1356 1357 This tests the use of derived quantities 1358 """ 1359 1360 import time, os 1361 from Numeric import array, zeros, allclose, Float, concatenate 1362 from Scientific.IO.NetCDF import NetCDFFile 1363 1364 #Setup 1365 self.domain.filename = 'datatest' 1366 1367 prjfile = self.domain.filename + '_depth.prj' 1368 ascfile = self.domain.filename + '_depth.asc' 1369 swwfile = self.domain.filename + '.sww' 1370 1371 self.domain.set_datadir('.') 1372 self.domain.format = 'sww' 1373 self.domain.smooth = True 1374 self.domain.set_quantity('elevation', lambda x,y: -x-y) 1375 self.domain.set_quantity('stage', 0.0) 1376 1377 self.domain.geo_reference = Geo_reference(56,308500,6189000) 1378 1379 1380 sww = get_dataobject(self.domain) 1381 sww.store_connectivity() 1382 sww.store_timestep('stage') 1383 1384 self.domain.evolve_to_end(finaltime = 0.01) 1385 sww.store_timestep('stage') 1386 1387 cellsize = 0.25 1388 #Check contents 1389 #Get NetCDF 1390 1391 fid = NetCDFFile(sww.filename, 'r') 1392 1393 # Get the variables 1394 x = fid.variables['x'][:] 1395 y = fid.variables['y'][:] 1396 z = fid.variables['elevation'][:] 1397 time = fid.variables['time'][:] 1398 stage = fid.variables['stage'][:] 1399 1400 1401 #Export to ascii/prj files 1402 sww2dem(self.domain.filename, 1403 basename_out = 'datatest_depth', 1404 quantity = 'stage - elevation', 1405 cellsize = cellsize, 1406 reduction = min, 1407 format = 'asc', 1408 verbose = False) 1409 1410 1411 #Check asc file 1412 ascid = open(ascfile) 1413 lines = ascid.readlines() 1414 ascid.close() 1415 1416 L = lines[0].strip().split() 1417 assert L[0].strip().lower() == 'ncols' 1418 assert L[1].strip().lower() == '5' 1419 1420 L = lines[1].strip().split() 1421 assert L[0].strip().lower() == 'nrows' 1422 assert L[1].strip().lower() == '5' 1423 1424 L = lines[2].strip().split() 1425 assert L[0].strip().lower() == 'xllcorner' 1426 assert allclose(float(L[1].strip().lower()), 308500) 1427 1428 L = lines[3].strip().split() 1429 assert L[0].strip().lower() == 'yllcorner' 1430 assert allclose(float(L[1].strip().lower()), 6189000) 1431 1432 L = lines[4].strip().split() 1433 assert L[0].strip().lower() == 'cellsize' 1434 assert allclose(float(L[1].strip().lower()), cellsize) 1435 1436 L = lines[5].strip().split() 1437 assert L[0].strip() == 'NODATA_value' 1438 assert L[1].strip().lower() == '-9999' 1439 1440 1441 #Check grid values (where applicable) 1442 for j in range(5): 1443 if j%2 == 0: 1444 L = lines[6+j].strip().split() 1445 jj = 4-j 1446 for i in range(5): 1447 if i%2 == 0: 1448 index = jj/2 + i/2*3 1449 val0 = stage[0,index] - z[index] 1450 val1 = stage[1,index] - z[index] 1451 1452 #print i, j, index, ':', L[i], val0, val1 1453 assert allclose(float(L[i]), min(val0, val1)) 1454 1455 1456 fid.close() 1457 1458 #Cleanup 1459 os.remove(prjfile) 1460 os.remove(ascfile) 1461 #os.remove(swwfile) 1462 1463 1464 1465 1353 1466 1354 1467 def test_sww2dem_asc_missing_points(self):
Note: See TracChangeset
for help on using the changeset viewer.