- Timestamp:
- Jun 15, 2010, 12:06:46 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/file_conversion/test_sww2dem.py
r7814 r7841 20 20 21 21 # local modules 22 from sww2dem import sww2dem 22 from sww2dem import sww2dem, sww2dem_batch 23 23 24 24 class Test_Sww2Dem(unittest.TestCase): … … 1392 1392 os.remove(self.domain.get_name() + '_elevation') 1393 1393 os.remove(self.domain.get_name() + '_elevation.ers') 1394 1395 def test_export_grid_parallel(self): 1396 """Test that sww information can be converted correctly to asc/prj 1397 format readable by e.g. ArcView 1398 """ 1399 1400 import time, os 1401 from Scientific.IO.NetCDF import NetCDFFile 1402 1403 base_name = 'tegp' 1404 #Setup 1405 self.domain.set_name(base_name+'_P0_8') 1406 swwfile = self.domain.get_name() + '.sww' 1407 1408 self.domain.set_datadir('.') 1409 self.domain.format = 'sww' 1410 self.domain.smooth = True 1411 self.domain.set_quantity('elevation', lambda x,y: -x-y) 1412 self.domain.set_quantity('stage', 1.0) 1413 1414 self.domain.geo_reference = Geo_reference(56,308500,6189000) 1415 1416 sww = SWW_file(self.domain) 1417 sww.store_connectivity() 1418 sww.store_timestep() 1419 self.domain.evolve_to_end(finaltime = 0.0001) 1420 #Setup 1421 self.domain.set_name(base_name+'_P1_8') 1422 swwfile2 = self.domain.get_name() + '.sww' 1423 sww = SWW_file(self.domain) 1424 sww.store_connectivity() 1425 sww.store_timestep() 1426 self.domain.evolve_to_end(finaltime = 0.0002) 1427 sww.store_timestep() 1428 1429 cellsize = 0.25 1430 #Check contents 1431 #Get NetCDF 1432 1433 fid = NetCDFFile(sww.filename, netcdf_mode_r) 1434 1435 # Get the variables 1436 x = fid.variables['x'][:] 1437 y = fid.variables['y'][:] 1438 z = fid.variables['elevation'][:] 1439 time = fid.variables['time'][:] 1440 stage = fid.variables['stage'][:] 1441 1442 fid.close() 1443 1444 #Export to ascii/prj files 1445 extra_name_out = 'yeah' 1446 sww2dem_batch(base_name, 1447 quantities = ['elevation', 'depth'], 1448 extra_name_out = extra_name_out, 1449 cellsize = cellsize, 1450 verbose = self.verbose, 1451 format = 'asc') 1452 1453 prjfile = base_name + '_P0_8_elevation_yeah.prj' 1454 ascfile = base_name + '_P0_8_elevation_yeah.asc' 1455 #Check asc file 1456 ascid = open(ascfile) 1457 lines = ascid.readlines() 1458 ascid.close() 1459 #Check grid values 1460 for j in range(5): 1461 L = lines[6+j].strip().split() 1462 y = (4-j) * cellsize 1463 for i in range(5): 1464 #print " -i*cellsize - y", -i*cellsize - y 1465 #print "float(L[i])", float(L[i]) 1466 assert num.allclose(float(L[i]), -i*cellsize - y) 1467 #Cleanup 1468 os.remove(prjfile) 1469 os.remove(ascfile) 1470 1471 prjfile = base_name + '_P1_8_elevation_yeah.prj' 1472 ascfile = base_name + '_P1_8_elevation_yeah.asc' 1473 #Check asc file 1474 ascid = open(ascfile) 1475 lines = ascid.readlines() 1476 ascid.close() 1477 #Check grid values 1478 for j in range(5): 1479 L = lines[6+j].strip().split() 1480 y = (4-j) * cellsize 1481 for i in range(5): 1482 #print " -i*cellsize - y", -i*cellsize - y 1483 #print "float(L[i])", float(L[i]) 1484 assert num.allclose(float(L[i]), -i*cellsize - y) 1485 #Cleanup 1486 os.remove(prjfile) 1487 os.remove(ascfile) 1488 os.remove(swwfile) 1489 1490 #Check asc file 1491 ascfile = base_name + '_P0_8_depth_yeah.asc' 1492 prjfile = base_name + '_P0_8_depth_yeah.prj' 1493 ascid = open(ascfile) 1494 lines = ascid.readlines() 1495 ascid.close() 1496 #Check grid values 1497 for j in range(5): 1498 L = lines[6+j].strip().split() 1499 y = (4-j) * cellsize 1500 for i in range(5): 1501 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y)) 1502 #Cleanup 1503 os.remove(prjfile) 1504 os.remove(ascfile) 1505 1506 #Check asc file 1507 ascfile = base_name + '_P1_8_depth_yeah.asc' 1508 prjfile = base_name + '_P1_8_depth_yeah.prj' 1509 ascid = open(ascfile) 1510 lines = ascid.readlines() 1511 ascid.close() 1512 #Check grid values 1513 for j in range(5): 1514 L = lines[6+j].strip().split() 1515 y = (4-j) * cellsize 1516 for i in range(5): 1517 assert num.allclose(float(L[i]), 1 - (-i*cellsize - y)) 1518 #Cleanup 1519 os.remove(prjfile) 1520 os.remove(ascfile) 1521 os.remove(swwfile2) 1522 1394 1523 1395 1524 #################################################################################
Note: See TracChangeset
for help on using the changeset viewer.