def CreateRasts(Input_SWW, path_final, filename): quantities = ['stage', 'depth', 'momentum'] for i in range(len(quantities)): print('Creating raster for quantity ' + quantities[i]) outname = path_final + '\\' + str(filename) + "_" + str(quantities[i] + ".asc") anuga.sww2dem(Input_SWW, outname, quantity=quantities[i], reduction=max, cellsize=1)
def CreateRasts(Input_SWW,Output_DEM_Path,Full_Series): quantities = ['elevation','stage','depth','momentum'] sww_file = sww.Read_sww(Input_SWW) timeinfo = sww_file.time if Full_Series == 'Yes': for i in range(len(quantities)): for j in range(len(timeinfo)): outname = Output_DEM_Path + '\\' + str(filename) + "_" + str(quantities[i] + "_" + str(int(timeinfo[j])) + ".asc") anuga.sww2dem(Input_SWW,outname,quantity=quantities[i],reduction = j, cellsize = 5) else: for i in range(len(quantities)): outname = Output_DEM_Path + '\\' + str(filename) + "_" + str(quantities[i] + "_" + str(int(timeinfo[j])) + ".asc") anuga.sww2dem(Input_SWW,outname,quantity=quantities[i],reduction = (len(timeinfo)-1), cellsize = 5)
quantityname = 'stage' if which_var == 1: # Absolute Momentum outname = name + '_momentum' quantityname = '(xmomentum**2 + ymomentum**2)**0.5' #Absolute momentum if which_var == 2: # Depth outname = name + '_depth' quantityname = 'stage-elevation' #Depth if which_var == 3: # Speed outname = name + '_speed' quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-30)' #Speed if which_var == 4: # Elevation outname = name + '_elevation' quantityname = 'elevation' #Elevation print 'start sww2dem' anuga.sww2dem(name+'.sww', outname+'.asc', quantity=quantityname, cellsize=100, easting_min=project.eastingmin, easting_max=project.eastingmax, northing_min=project.northingmin, northing_max=project.northingmax, reduction=max, verbose=True)
if which_var == 1: # Absolute Momentum outname = name + '_momentum' quantityname = '(xmomentum**2 + ymomentum**2)**0.5' #Absolute momentum if which_var == 2: # Depth outname = name + '_depth' quantityname = 'stage-elevation' #Depth if which_var == 3: # Speed outname = name + '_speed' quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-3)' #Speed if which_var == 4: # Elevation outname = name + '_elevation' quantityname = 'elevation' #Elevation print 'start sww2dem' anuga.sww2dem( name + '.sww', outname + '.asc', quantity=quantityname, cellsize=100, #easting_min=project.eastingmin, #easting_max=project.eastingmax, #northing_min=project.northingmin, #northing_max=project.northingmax, reduction=max, verbose=True)
outname = name + '_depth' quantityname = 'stage-elevation' #Depth if which_var == 3: # Speed outname = name + '_speed' quantityname = '(xmomentum**2 + ymomentum**2)**0.5/(stage-elevation+1.e-30)' #Speed if which_var == 4: # Elevation outname = name + '_elevation' quantityname = 'elevation' #Elevation # Save every 20 secs for t in domain.evolve(yieldstep=20, finaltime=tend): print domain.timestepping_statistics() anuga.sww2dem(project_minecraft.outpath + 'anuga_output_minecraft.sww', outname + '.asc', quantity=quantityname, cellsize=0.5, easting_min=627724, easting_max=627893, northing_min=5804634, northing_max=5804828, reduction=max, verbose=False) #print domain.boundary_statistics(tags='east') # Save every 30 secs as wave starts inundating ashore #for t in domain.evolve(yieldstep=100, finaltime=10000, # skip_initial_step=True): # print domain.timestepping_statistics() # print domain.boundary_statistics(tags='east') print '.That took %.2f seconds' % (time.time() - t0)
def run_chennai(sim_id): project_root = os.path.abspath(os.path.dirname(__file__)) if not os.path.exists(project_root): os.makedirs(project_root) print "project_root = " + project_root inputs_dir = '%s/inputs/' % project_root if not os.path.exists(inputs_dir): os.makedirs(inputs_dir) print "inputs_dir = " + inputs_dir working_dir = '%s/working/%s/' % (project_root, sim_id) if not os.path.exists(working_dir): os.makedirs(working_dir) print "working_dir = " + working_dir outputs_dir = '%s/outputs/%s' % (project_root, sim_id) if not os.path.exists(outputs_dir): os.makedirs(outputs_dir) print "outputs_dir = " + outputs_dir # get data print "downloading data..." urllib.urlretrieve( 'http://chennaifloodmanagement.org/uploaded/layers/utm44_1arc_v3.tif', inputs_dir + 'utm44_1arc_v3.tif' ) print os.listdir(inputs_dir) # configure logging TODO: get this working! log_location = project_root + '/' + sim_id + '.log' open(log_location, 'a').close() log.console_logging_level = log.INFO log.log_logging_level = log.DEBUG log.log_filename = log_location print "# log.log_filename is: " + log.log_filename print "# log_location is: " + log_location log.debug('A message at DEBUG level') log.info('Another message, INFO level') print "# starting" bounding_polygon_01 = [ [303382.14647903712, 1488780.8996663219], [351451.89152459265, 1499834.3704521982], [378957.03975921532, 1493150.8764886451], [422656.80798244767, 1504204.3472745214], [433196.16384805075, 1471300.9923770288], [421885.63560203766, 1413463.0638462803], [408261.59021479468, 1372590.9276845511], [371245.31595511554, 1427344.16669366], [316492.0769460068, 1417833.0406686035], [303382.14647903712, 1488780.8996663219] ] boundary_tags_01 = { 'inland': [0, 1, 2, 6, 7, 8], 'ocean': [3, 4, 5] } print "# Create domain:" print "# mesh_filename = " + working_dir + 'mesh_01.msh' domain = anuga.create_domain_from_regions(bounding_polygon=bounding_polygon_01, boundary_tags=boundary_tags_01, mesh_filename=working_dir + 'mesh_01.msh', maximum_triangle_area=100000, verbose=True) domain.set_name(sim_id) domain.set_datadir(outputs_dir) poly_fun_pairs = [ [ 'Extent', inputs_dir + 'utm44_1arc_v3.tif' ] ] print "# create topography_function" print "input raster = " + inputs_dir + 'utm44_1arc_v3.tif' topography_function = qs.composite_quantity_setting_function( poly_fun_pairs, domain, nan_treatment='exception', ) print topography_function print "# set_quantity elevation" domain.set_quantity('elevation', topography_function) # Use function for elevation domain.set_quantity('friction', 0.03) # Constant friction domain.set_quantity('stage', 1) # Constant initial stage print "# all quantities set" print "# Setup boundary conditions" Br = anuga.Reflective_boundary(domain) # Solid reflective wall Bt = anuga.Transmissive_boundary(domain) # Continue all values on boundary Bd = anuga.Dirichlet_boundary([-20, 0., 0.]) # Constant boundary values Bi = anuga.Dirichlet_boundary([10.0, 0, 0]) # Inflow Bw = anuga.Time_boundary( domain=domain, # Time dependent boundary function=lambda t: [(10 * sin(t * 2 * pi) - 0.3) * exp(-t), 0.0, 0.0] ) print "# Associate boundary tags with boundary objects" domain.set_boundary({'inland': Br, 'ocean': Bd}) print domain.get_boundary_tags() catchmentrainfall = Rainfall( domain=domain, rate=0.2 ) # # Note need path to File in String. # # Else assumed in same directory domain.forcing_terms.append(catchmentrainfall) print "# Evolve system through time" counter_timestep = 0 for t in domain.evolve(yieldstep=300, finaltime=6000): counter_timestep += 1 print counter_timestep print domain.timestepping_statistics() asc_out_momentum = outputs_dir + '/' + sim_id + '_momentum.asc' asc_out_depth = outputs_dir + '/' + sim_id + '_depth.asc' anuga.sww2dem(outputs_dir + '/' + sim_id + '.sww', asc_out_momentum, quantity='momentum', number_of_decimal_places=3, cellsize=30, reduction=max, verbose=True) anuga.sww2dem(outputs_dir + '/' + sim_id + '.sww', asc_out_depth, quantity='depth', number_of_decimal_places=3, cellsize=30, reduction=max, verbose=True) outputs =[asc_out_depth, asc_out_momentum] for output in outputs: print "# Convert ASCII grid to GeoTiff so geonode can import it" src_ds = gdal.Open(output) dst_filename = (output[:-3] + 'tif') print "# Create gtif instance" driver = gdal.GetDriverByName("GTiff") print "# Output to geotiff" dst_ds = driver.CreateCopy(dst_filename, src_ds, 0) print "# Properly close the datasets to flush the disk" dst_filename = None src_ds = None print "Done. Nice work."
def main(): try: try: usage = "usage: jezero.py -1*initialstage-in-m \n Note that -2260 flows but barely does anything. So range for jezero is ~2260 to 2200. \n" parser = optparse.OptionParser(usage=usage) (options, inargs) = parser.parse_args() if not inargs: parser.error("need parameters") jezerostage = -1.0 * float(inargs[0]) # Before doing anything else, set gravity to Mars anuga.g = gravity #domain parameters poly_highres = anuga.read_polygon('JezeroData/PolyHi.csv') poly_bound = anuga.read_polygon( 'JezeroData/PolyBoundBiggerPts.csv') base_scale = 25600 #160 m #HIRES REGION lowres = 10000 * base_scale # 10 km boundary_tags = {'exterior': [0]} # Define list of interior regions with associated resolutions interior_regions = [[poly_highres, base_scale]] meshname = 'JezeroData/jezero.msh' mesh = anuga.create_mesh_from_regions( poly_bound, boundary_tags=boundary_tags, maximum_triangle_area=lowres, interior_regions=interior_regions, verbose=True, filename=meshname, fail_if_polygons_outside=False) evolved_quantities = [ 'stage', 'xmomentum', 'ymomentum', 'concentration', 'sedvolx', 'sedvoly' ] domain = anuga.Domain(meshname, use_cache=False, evolved_quantities=evolved_quantities) domain.g = anuga.g # make sure the domain inherits the package's gravity. domain.set_quantity("elevation", filename="JezeroData/jbigger.pts", use_cache=False, verbose=True) domain.smooth = True name = "jezero" + str(jezerostage) + "_" + str( grainD * 1000.0) + "mm" domain.set_name(name) # Choose between DE0 (less accurate), DE1 (more accurate, slower), DE2 (even more accurate, slower still) domain.set_flow_algorithm('DE0') domain.set_CFL(cfl=1.0) domain.set_minimum_allowed_height( 0.01 ) #raise the default minimum depth from 1 mm to 1 cm to speed the simulation (for computation) domain.set_minimum_storable_height( 0.01 ) #raise the default minimum depth from 1 mm to 1 cm to speed the simulation (for storage/visualization) domain.set_maximum_allowed_speed( 1.0 ) #maximum particle speed that is allowed in water shallower than minimum_allowed_height (back of the envelope suggests 1m/s should be below tau_crit) np.seterr(invalid='ignore') voltotal = np.sum(domain.quantities['elevation'].centroid_values * domain.areas) domain.set_quantity('concentration', 0.00) # Start with no esd domain.set_quantity( 'friction', constantn ) # Constant Manning friction. Only used to initialize domain (calculated every time step). domain.set_quantity('stage', -10000.0) stagepolygon = anuga.read_polygon('JezeroData/stage.csv') domain.set_quantity('stage', jezerostage, polygon=stagepolygon) domain.set_quantities_to_be_stored({ 'stage': 2, 'xmomentum': 2, 'ymomentum': 2, 'elevation': 2 }) np.seterr(invalid='warn') Br = anuga.Reflective_boundary(domain) domain.set_boundary({'exterior': Br}) # fixed_inflow = anuga.Inlet_operator(domain, stagepolygon, Q=1000.0) operatezero = suspendedtransport_operator(domain) operateone = bedloadtransport_operator(domain) operatetwo = friction_operator(domain) operatethree = AoR_operator(domain) breachpoint = [[19080.340, 1097556.781]] initialdomain = copy.deepcopy(domain) initial = domain.get_quantity('elevation').get_values( interpolation_points=breachpoint, location='centroids') print str(initial) ystep = 300.0 ftime = 86400.0 * 5.0 polyline = [[40000, 1090000], [15000, 1120000]] count = 0 for t in domain.evolve(yieldstep=ystep, finaltime=ftime): print domain.timestepping_statistics() print 'xmom:' + str( domain.get_quantity('xmomentum').get_values( interpolation_points=breachpoint, location='centroids')) breacherosion = domain.get_quantity('elevation').get_values( interpolation_points=breachpoint, location='centroids') - initial print 'erosion: ' + str(breacherosion) volcurr = np.sum( domain.quantities['elevation'].centroid_values * domain.areas) volsed = np.sum( domain.quantities['concentration'].centroid_values * domain.quantities['height'].centroid_values * domain.areas) conservation = (volcurr + volsed - voltotal) / voltotal print 'conservation: ' + '{:.8%}'.format(conservation) count = count + 1 time, Q = anuga.get_flow_through_cross_section( name + '.sww', polyline) print Q initname = "initial_" + name + ".asc" finname = "final_" + name + ".asc" fluxname = "flux_" + name + ".txt" np.savetxt(fluxname, Q) anuga.sww2dem(name + '.sww', initname, reduction=0) anuga.sww2dem(name + '.sww', finname, reduction=(count - 1)) finalstats(domain, initialdomain) np.save('XconcC.npy', domain.quantities['concentration'].centroid_values) np.save('XelevC.npy', domain.quantities['elevation'].centroid_values) np.save('XxmC.npy', domain.quantities['xmomentum'].centroid_values) np.save('XymC.npy', domain.quantities['ymomentum'].centroid_values) np.save('XstageC.npy', domain.quantities['stage'].centroid_values) np.save('XconcV.npy', domain.quantities['concentration'].vertex_values) np.save('XelevV.npy', domain.quantities['elevation'].vertex_values) np.save('XxmV.npy', domain.quantities['xmomentum'].vertex_values) np.save('XymV.npy', domain.quantities['ymomentum'].vertex_values) np.save('XstageV.npy', domain.quantities['stage'].vertex_values) except optparse.OptionError, msg: raise Usage(msg) except Usage, err: print >> sys.stderr, err.msg # print >>sys.stderr, "for help use --help" return 2