Changeset 4563
- Timestamp:
- Jun 26, 2007, 11:30:29 AM (17 years ago)
- Location:
- anuga_core/source/anuga/shallow_water
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/shallow_water/data_manager.py
r4558 r4563 5464 5464 5465 5465 Optional arguments polygon and time_interval restricts the maximum runup calculation 5466 to a points that lie within the specified polygon and time interval. 5466 to a points that lie within the specified polygon and time interval. Polygon is 5467 assumed to be in (absolute) UTM coordinates in the same zone as domain. 5467 5468 5468 5469 If no inundation is found within polygon and time_interval the return value … … 5486 5487 if verbose: 5487 5488 print 'Reading from %s' %filename 5489 # FIXME: Use general swwstats (when done) 5490 5488 5491 5489 5492 from Scientific.IO.NetCDF import NetCDFFile 5490 5493 fid = NetCDFFile(filename) 5491 5494 5492 # Get extent and reference 5495 # Get geo_reference 5496 # sww files don't have to have a geo_ref 5497 try: 5498 geo_reference = Geo_reference(NetCDFObject=fid) 5499 except AttributeError, e: 5500 geo_reference = Geo_reference() # Default georef object 5501 5502 xllcorner = geo_reference.get_xllcorner() 5503 yllcorner = geo_reference.get_yllcorner() 5504 zone = geo_reference.get_zone() 5505 5506 # Get extent 5493 5507 volumes = fid.variables['volumes'][:] 5494 x = fid.variables['x'][:] 5495 y = fid.variables['y'][:] 5508 x = fid.variables['x'][:] + xllcorner 5509 y = fid.variables['y'][:] + yllcorner 5510 5496 5511 5497 5512 # Get the relevant quantities -
anuga_core/source/anuga/shallow_water/test_data_manager.py
r4562 r4563 1962 1962 os.remove(ascfile) 1963 1963 os.remove(swwfile) 1964 1964 1965 1965 1966 … … 7030 7031 7031 7032 7033 def test_get_maximum_inundation(self): 7034 """Test that sww information can be converted correctly to maximum 7035 runup elevation and location (without and with georeferencing) 7036 7037 This test creates a slope and a runup which is maximal (~11m) at around 10s 7038 and levels out to the boundary condition (1m) at about 30s. 7039 """ 7040 7041 import time, os 7042 from Numeric import array, zeros, allclose, Float, concatenate 7043 from Scientific.IO.NetCDF import NetCDFFile 7044 7045 #Setup 7046 7047 from mesh_factory import rectangular 7048 7049 #Create basic mesh (100m x 100m) 7050 points, vertices, boundary = rectangular(20, 5, 100, 50) 7051 7052 #Create shallow water domain 7053 domain = Domain(points, vertices, boundary) 7054 domain.default_order = 2 7055 domain.set_minimum_storable_height(0.01) 7056 7057 domain.set_name('runuptest') 7058 swwfile = domain.get_name() + '.sww' 7059 7060 domain.set_datadir('.') 7061 domain.format = 'sww' 7062 domain.smooth = True 7063 7064 7065 Br = Reflective_boundary(domain) 7066 Bd = Dirichlet_boundary([1.0,0,0]) 7067 7068 7069 #---------- First run without geo referencing 7070 7071 domain.set_quantity('elevation', lambda x,y: -0.2*x + 14) # Slope 7072 domain.set_quantity('stage', -6) 7073 domain.set_boundary( {'left': Br, 'right': Bd, 'top': Br, 'bottom': Br}) 7074 7075 for t in domain.evolve(yieldstep=1, finaltime = 50): 7076 pass 7077 7078 7079 # Check maximal runup 7080 runup = get_maximum_inundation_elevation(swwfile) 7081 location = get_maximum_inundation_location(swwfile) 7082 assert allclose(runup, 11) 7083 assert allclose(location[0], 15) 7084 7085 # Check final runup 7086 runup = get_maximum_inundation_elevation(swwfile, time_interval=[45,50]) 7087 location = get_maximum_inundation_location(swwfile, time_interval=[45,50]) 7088 assert allclose(runup, 1) 7089 assert allclose(location[0], 65) 7090 7091 # Check runup restricted to a polygon 7092 p = [[50,1], [99,1], [99,49], [50,49]] 7093 runup = get_maximum_inundation_elevation(swwfile, polygon=p) 7094 location = get_maximum_inundation_location(swwfile, polygon=p) 7095 assert allclose(runup, 4) 7096 assert allclose(location[0], 50) 7097 7098 #Cleanup 7099 os.remove(swwfile) 7100 7101 7102 7103 #------------- Now the same with georeferencing 7104 7105 domain.time=0.0 7106 E = 308500 7107 N = 6189000 7108 #E = N = 0 7109 domain.geo_reference = Geo_reference(56, E, N) 7110 7111 domain.set_quantity('elevation', lambda x,y: -0.2*x + 14) # Slope 7112 domain.set_quantity('stage', -6) 7113 domain.set_boundary( {'left': Br, 'right': Bd, 'top': Br, 'bottom': Br}) 7114 7115 for t in domain.evolve(yieldstep=1, finaltime = 50): 7116 pass 7117 7118 # Check maximal runup 7119 runup = get_maximum_inundation_elevation(swwfile) 7120 location = get_maximum_inundation_location(swwfile) 7121 assert allclose(runup, 11) 7122 assert allclose(location[0], 15+E) 7123 7124 # Check final runup 7125 runup = get_maximum_inundation_elevation(swwfile, time_interval=[45,50]) 7126 location = get_maximum_inundation_location(swwfile, time_interval=[45,50]) 7127 assert allclose(runup, 1) 7128 assert allclose(location[0], 65+E) 7129 7130 # Check runup restricted to a polygon 7131 p = array([[50,1], [99,1], [99,49], [50,49]]) + array([E, N]) 7132 7133 runup = get_maximum_inundation_elevation(swwfile, polygon=p) 7134 location = get_maximum_inundation_location(swwfile, polygon=p) 7135 assert allclose(runup, 4) 7136 assert allclose(location[0], 50+E) 7137 7138 7139 #Cleanup 7140 os.remove(swwfile) 7141 7032 7142 7033 7143 7034 7144 #------------------------------------------------------------- 7035 7145 if __name__ == "__main__": 7036 #suite = unittest.makeSuite(Test_Data_Manager,'test_ urs2sww_origin')7146 #suite = unittest.makeSuite(Test_Data_Manager,'test_get_maximum_inundation') 7037 7147 #suite = unittest.makeSuite(Test_Data_Manager,'test_sww_header') 7038 7148 #suite = unittest.makeSuite(Test_Data_Manager,'test_export_grid_parallel') 7039 7149 #suite = unittest.makeSuite(Test_Data_Manager,'test_export_gridIII') 7040 7150 suite = unittest.makeSuite(Test_Data_Manager,'test') 7151 7152 7041 7153 if len(sys.argv) > 1 and sys.argv[1][0].upper() == 'V': 7042 7154 Test_Data_Manager.verbose=True
Note: See TracChangeset
for help on using the changeset viewer.