Changeset 1133
- Timestamp:
- Mar 23, 2005, 10:54:19 AM (20 years ago)
- Location:
- inundation/ga/storm_surge/pyvolution
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/ga/storm_surge/pyvolution/_test_sww2domain.py
r1089 r1133 55 55 #Evolution 56 56 for t in domain.evolve(yieldstep = 1, finaltime = 2.0): 57 domain.write_time() 57 # domain.write_time() 58 pass 58 59 59 60 … … 63 64 from Numeric import allclose 64 65 65 filename = domain. filename+'.sww'66 filename = domain.datadir+'\\'+domain.filename+'.sww' 66 67 67 domain2 = sww2domain(filename,fail_if_NaN=False )68 domain2 = sww2domain(filename,fail_if_NaN=False,verbose = False) 68 69 69 70 … … 74 75 75 76 for bit in bits: 76 print 'testing that domain.'+bit+' has been restored'77 # print 'testing that domain.'+bit+' has been restored' 77 78 assert allclose(eval('domain.'+bit),eval('domain2.'+bit)) 78 79 79 print 'passed'80 #print 'passed' -
inundation/ga/storm_surge/pyvolution/_test_sww2domain2.py
r1090 r1133 23 23 domain.filename = 'bedslope' 24 24 domain.default_order=2 25 domain.quantities_to_be_stored=['stage'] 25 26 26 27 ####################### … … 49 50 50 51 domain.check_integrity() 51 dir(domain)52 53 52 ###################### 54 53 #Evolution 55 54 for t in domain.evolve(yieldstep = 1, finaltime = 2.0): 56 domain.write_time() 55 pass 56 #domain.write_time() 57 57 58 58 … … 62 62 from Numeric import allclose 63 63 64 filename = domain. filename+'.sww'64 filename = domain.datadir+'\\'+domain.filename+'.sww' 65 65 66 66 try: 67 domain2 = sww2domain(filename )67 domain2 = sww2domain(filename,verbose=False) 68 68 assert True == False 69 69 except: 70 domain2 = sww2domain(filename,fail_if_NaN=False) 70 filler = 0 71 domain2 = sww2domain(filename,fail_if_NaN=False,NaN_filler = filler,verbose=False) 71 72 72 73 bits = ['xllcorner','yllcorner','vertex_coordinates','time','starttime'] … … 76 77 77 78 for bit in bits: 78 print 'testing that domain.'+bit+' has been restored'79 # print 'testing that domain.'+bit+' has been restored' 79 80 assert allclose(eval('domain.'+bit),eval('domain2.'+bit)) 80 81 81 print max(max(domain2.get_quantity('xmomentum')))82 print min(min(domain2.get_quantity('xmomentum')))83 print max(max(domain2.get_quantity('ymomentum')))84 print min(min(domain2.get_quantity('ymomentum')))82 #print max(max(domain2.get_quantity('xmomentum'))) 83 #print min(min(domain2.get_quantity('xmomentum'))) 84 #print max(max(domain2.get_quantity('ymomentum'))) 85 #print min(min(domain2.get_quantity('ymomentum'))) 85 86 86 assert max(max(domain2.get_quantity('xmomentum')))== 087 assert min(min(domain2.get_quantity('xmomentum')))== 088 assert max(max(domain2.get_quantity('ymomentum')))== 089 assert min(min(domain2.get_quantity('ymomentum')))== 087 assert max(max(domain2.get_quantity('xmomentum')))==filler 88 assert min(min(domain2.get_quantity('xmomentum')))==filler 89 assert max(max(domain2.get_quantity('ymomentum')))==filler 90 assert min(min(domain2.get_quantity('ymomentum')))==filler 90 91 91 print 'passed' 92 #print 'passed' 93 94 #cleanup 95 #import os 96 #os.remove(domain.datadir+'/'+domain.filename+'.sww') -
inundation/ga/storm_surge/pyvolution/data_manager.py
r1120 r1133 1623 1623 1624 1624 1625 def sww2domain(filename,t=None,fail_if_NaN=True,NaN_filler=0): 1626 """Read sww Net CDF file containing Shallow Water Wave simulation 1627 1628 Quantities stage, elevation, xmomentum and ymomentum. 1629 1630 The momentum is not always stored. 1631 1625 def sww2domain(filename,t=None,fail_if_NaN=True,NaN_filler=0,verbose = True): 1626 """ 1627 Usage: domain = sww2domain('file.sww',t=time (default = last time in file)) 1628 1629 If the sww has stages, but not 1632 1630 """ 1633 1631 NaN=9.969209968386869e+036 1632 #initialise NaN. 1633 1634 1634 from Scientific.IO.NetCDF import NetCDFFile 1635 1635 from domain import Domain 1636 1636 from Numeric import asarray, transpose 1637 #print 'Reading from ', filename 1637 1638 if verbose: print 'Reading from ', filename 1638 1639 fid = NetCDFFile(filename, 'r') #Open existing file for read 1639 1640 time = fid.variables['time'] #Timesteps … … 1641 1642 t = time[-1] 1642 1643 time_interp = get_time_interp(time,t) 1643 ################################ 1644 ######################################## 1644 1645 1645 # Get the variables as Numeric arrays 1646 1646 x = fid.variables['x'][:] #x-coordinates of vertices … … 1649 1649 stage = fid.variables['stage'] #Water level 1650 1650 xmomentum = fid.variables['xmomentum'] #Momentum in the x-direction 1651 ymomentum = fid.variables['ymomentum'] #Momentum in the y-direction 1652 ################################# 1651 ymomentum = fid.variables['ymomentum'] #Momentum in the y-direction 1652 1653 1653 xllcorner = fid.xllcorner[0] 1654 1654 yllcorner = fid.yllcorner[0] … … 1657 1657 volumes = fid.variables['volumes'][:] #Connectivity 1658 1658 coordinates=transpose(asarray([x.tolist(),y.tolist()])) 1659 # 1659 1660 1660 conserved_quantities = [] 1661 1661 interpolated_quantities = {} 1662 1662 other_quantities = [] 1663 # 1664 #print ' interpolating quantities'1663 1664 if verbose: print ' interpolating quantities' 1665 1665 for quantity in fid.variables.keys(): 1666 1666 dimensions = fid.variables[quantity].dimensions … … 1670 1670 interpolated_quantity(fid.variables[quantity][:],time_interp) 1671 1671 else: other_quantities.append(quantity) 1672 # 1672 1673 1673 other_quantities.remove('x') 1674 1674 other_quantities.remove('y') 1675 1675 other_quantities.remove('z') 1676 1676 other_quantities.remove('volumes') 1677 # 1677 1678 1678 conserved_quantities.remove('time') 1679 # 1680 #print other_quantities 1681 #print conserved_quantities 1682 #print ' building domain' 1679 1680 if verbose: print ' building domain' 1683 1681 domain = Domain(coordinates, volumes,\ 1684 1682 conserved_quantities = conserved_quantities,\ … … 1688 1686 domain.time=t 1689 1687 for quantity in other_quantities: 1688 try: 1689 NaN = fid.variables[quantity].missing_value 1690 except: 1691 pass #quantity has no missing_value number 1690 1692 X = fid.variables[quantity][:] 1691 #print quantity 1692 #print 'max(X)' 1693 #print max(X) 1694 #print 'max(X)==NaN' 1695 #print max(X)==NaN 1693 if verbose: 1694 print ' ',quantity 1695 print ' NaN =',NaN 1696 print ' max(X)' 1697 print ' ',max(X) 1698 print ' max(X)==NaN' 1699 print ' ',max(X)==NaN 1700 print '' 1696 1701 if (max(X)==NaN) or (min(X)==NaN): 1697 1702 if fail_if_NaN: 1698 msg = 'quantity %scontains no_data entry'%quantity1703 msg = 'quantity "%s" contains no_data entry'%quantity 1699 1704 raise msg 1700 1705 else: … … 1704 1709 # 1705 1710 for quantity in conserved_quantities: 1711 try: 1712 NaN = fid.variables[quantity].missing_value 1713 except: 1714 pass #quantity has no missing_value number 1706 1715 X = interpolated_quantities[quantity] 1707 #print quantity 1708 #print 'max(X)' 1709 #print max(X) 1710 #print 'max(X)==NaN' 1711 #print max(X)==NaN 1716 if verbose: 1717 print ' ',quantity 1718 print ' NaN =',NaN 1719 print ' max(X)' 1720 print ' ',max(X) 1721 print ' max(X)==NaN' 1722 print ' ',max(X)==NaN 1723 print '' 1712 1724 if (max(X)==NaN) or (min(X)==NaN): 1713 1725 if fail_if_NaN: 1714 msg = 'quantity %scontains no_data entry'%quantity1726 msg = 'quantity "%s" contains no_data entry'%quantity 1715 1727 raise msg 1716 1728 else: … … 1718 1730 X = (X*data)+(data==0)*NaN_filler 1719 1731 domain.set_quantity(quantity,X) 1732 fid.close() 1720 1733 return domain 1721 1734
Note: See TracChangeset
for help on using the changeset viewer.