def SetRoughness(rough_in): # Import roughness raster # Create DEM from asc data anuga.asc2dem(rough_in + '.asc', use_cache=False, verbose=True) # Create pts from DEM data anuga.dem2pts(rough_in + '.dem', use_cache=False, verbose=True)
def build_elevation(): """Create combined elevation data. Combine all raw elevation data and clip to bounding polygon. """ # Create Geospatial data from ASCII files geospatial_data = {} for filename in project.ascii_grid_filenames: log.info('Reading elevation file %s' % filename) absolute_filename = os.path.join(project.raw_elevation_folder, filename) anuga.asc2dem(absolute_filename+'.asc', use_cache=False, verbose=False) anuga.dem2pts(absolute_filename+'.dem', use_cache=False, verbose=False) G_grid = anuga.geospatial_data.\ Geospatial_data(file_name=absolute_filename+'.pts', verbose=False) geospatial_data[filename] = G_grid.clip(project.bounding_polygon) # Create Geospatial data from TXT files for filename in project.point_filenames: log.info('Reading elevation file %s' % filename) absolute_filename = os.path.join(project.raw_elevation_folder, filename) G_points = anuga.geospatial_data.\ Geospatial_data(file_name=absolute_filename, verbose=False) geospatial_data[filename] = G_points.clip(project.bounding_polygon) ##### # Combine, clip and export dataset ##### G = None for key in geospatial_data: G += geospatial_data[key] G.export_points_file(project.combined_elevation_filestem + '.pts') # Use for comparision in ARC # DO WE NEED THIS? G.export_points_file(project.combined_elevation_filestem + '.txt')
def CreateDomain(topo_in, bound_in, datadir, inlet_btag, outlet_btag, res, parlist): # Import Channel topography DEM # Create DEM from asc data anuga.asc2dem(topo_in + '.asc', use_cache=False, verbose=True) # Create DEM from asc data anuga.dem2pts(topo_in + '.dem', use_cache=False, verbose=True) # Define boundaries for mesh # Read in coordinate file bounding_polygon = anuga.read_polygon(bound_in + '.csv') print(inlet_btag) #Determine tag to assign as reflective exterior for i in numpy.arange(1, 4): print(i) if int(i) == int(inlet_btag): print(str(inlet_btag) + ' already taken') else: print(str(i) + ' used as exterior tag') break # Create mesh with bounding polygon domain = anuga.create_domain_from_regions(bounding_polygon, boundary_tags={ 'inlet': [inlet_btag], 'exterior': [i], 'outlet': [outlet_btag] }, maximum_triangle_area=res, mesh_filename=parlist + '.msh', use_cache=False, verbose=True) # Name domain and decide where to save domain.set_name(parlist) domain.set_datadir('.') return domain
args = anuga.get_args() alg = args.alg verbose = args.verbose if myid == 0: # Unzip asc from zip file import zipfile as zf if verbose: print 'Reading ASC from ' + zip_name zf.ZipFile(zip_name).extract(asc_name) # Create DEM from asc data anuga.asc2dem(asc_name, verbose=verbose, use_cache=use_cache) # Create pts file for onshore DEM anuga.dem2pts(dem_name, verbose=verbose, use_cache=use_cache) #------------------------------------------------------------------------------ # Create the triangular mesh based on overall clipping polygon with a tagged # boundary and interior regions defined in project.py along with # resolutions (maximal area of per triangle) for each polygon #------------------------------------------------------------------------------ remainder_res = 2.0 houses_res = 1.0 merewether_res = 1.0 holes_res = 1.0 interior_regions = [[project.poly_merewether, merewether_res]] # Either use houses as holes, or as part of the mesh (with breaklines) houses_as_holes = False
import anuga from anuga import rectangular_cross from anuga import Domain from anuga import Dirichlet_boundary, Reflective_boundary #=============================================================================== # Setup Functions #=============================================================================== filename_root = 'topo' # Convert an elevation raster into a point file anuga.asc2dem(filename_root + '.asc', use_cache = False, verbose = True) anuga.dem2pts(filename_root + '.dem', use_cache = False, verbose = True) """ Include the process-specific quantities when creating the domain """ # import bounding polygon text file, set boundary tags bounding_polygon = anuga.read_polygon('outline.csv') boundary_tags = {'bottom':[0], 'side1':[1], 'side2':[2], 'top':[3], 'side3':[4], 'side4':[5]}
mesh_file = 'jakarta.msh' init_stage = 17 inflow_stage = init_stage+10+5 base_scale = 2 # 1 -> ~3 meter wide triangles default_res = 100 * base_scale # Background resolution # coordinates extracted out of boundary layer bounding_polygon = [(704627,9.30357e+06), (704937,9.30354e+06), (705274,9.30368e+06), (705246,9.30445e+06), (704679,9.30491e+06), (704646,9.30526e+06), (705521,9.30634e+06), (705961,9.30702e+06), (706430,9.30703e+06), (706449,9.30741e+06), (706229,9.30769e+06), (704918,9.30769e+06), (704890,9.30667e+06), (704019,9.30582e+06), (704057,9.30488e+06), (703789,9.30459e+06), (704359,9.3042e+06), (704627,9.30357e+06)] # Create NetCDF file from asc data res = anuga.asc2dem(dem_asc_file, use_cache=cache, verbose=verbose) # Create pts file from dem anuga.dem2pts(dem_cdf_file, use_cache=cache, verbose=verbose) interior_regions = [] # this makes huge mesh [bounding_polygon, base_scale] ] # name + list of segments boundary_tags = { 'in': [0] } # {'in': [0], 'other': [1,2,3,4] } #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #------------------------------------------------------------------------------ domain = anuga.create_domain_from_regions(bounding_polygon, boundary_tags=boundary_tags, maximum_triangle_area=default_res, mesh_filename=mesh_file,
args = anuga.get_args() alg = args.alg verbose = args.verbose if myid == 0: # Unzip asc from zip file import zipfile as zf if verbose: print('Reading ASC from ' + zip_name) zf.ZipFile(zip_name).extract(asc_name) # Create DEM from asc data anuga.asc2dem(asc_name, verbose=verbose, use_cache=use_cache) # Create pts file for onshore DEM anuga.dem2pts(dem_name, verbose=verbose, use_cache=use_cache) #------------------------------------------------------------------------------ # Create the triangular mesh based on overall clipping polygon with a tagged # boundary and interior regions defined in project.py along with # resolutions (maximal area of per triangle) for each polygon #------------------------------------------------------------------------------ remainder_res = 2.0 houses_res = 1.0 merewether_res = 1.0 holes_res = 1.0 interior_regions = [[project.poly_merewether, merewether_res]] # Either use houses as holes, or as part of the mesh (with breaklines) houses_as_holes = False
geospatial_data = {} if not project.ascii_grid_filenames == []: for filename in project.ascii_grid_filenames: absolute_filename = join(project.topographies_folder, filename) # convert_dem_from_ascii2netcdf(absolute_filename, # basename_out=absolute_filename, # use_cache=True, # verbose=True) # dem2pts(absolute_filename, use_cache=True, verbose=True) anuga.asc2dem(absolute_filename + '.asc', use_cache=False, verbose=True) anuga.dem2pts(absolute_filename + '.dem', use_cache=False, verbose=True) G_grid = anuga.geospatial_data.Geospatial_data( file_name=absolute_filename + '.pts', verbose=True) print 'Clip geospatial object' geospatial_data[filename] = G_grid.clip(project.bounding_polygon) # Create Geospatial data from TXT files if not project.point_filenames == []: for i in range(0, len(project.point_filenames)): filename = project.point_filenames[i] # for filename in project.point_filenames: print 'filename:', filename, i absolute_filename = project.topographies_folder + '/' + str(filename) G_points = anuga.geospatial_data.Geospatial_data( file_name=absolute_filename, verbose=True)
#Save Parameter List as Metadata with open(identifier + '_par.txt', 'w') as f: for item in Parameters: f.write(str(item) + "\n") #Save Parameter List as Pkl fname = identifier + '_par.pkl' pickle_out = open(fname, "wb") pickle.dump(Parameters, pickle_out) # Import Channel topography DEM # Create DEM from asc data anuga.asc2dem(topo_in + '.asc', use_cache=False, verbose=True) # Create DEM from asc data anuga.dem2pts(topo_in + '.dem', use_cache=False, verbose=True) # Define boundaries for mesh # Read in coordinate file bounding_polygon = anuga.read_polygon(bound_in + '.csv') # Create mesh with bounding polygon domain = anuga.create_domain_from_regions(bounding_polygon, boundary_tags={ 'inlet': [inlet_btag], 'exterior': [ref_btag], 'outlet': [outlet_btag] }, maximum_triangle_area=res, mesh_filename=identifier + '.msh', use_cache=False, verbose=True)
# Preparation of topographic data # Convert GEOTIFF to NC to ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------ # Create nc from geotif data VHIRL_conversions.geotif2nc(dataset, '/tmp/'+name_stem) # Create ASC from nc data VHIRL_conversions.nc2asc('/tmp/'+name_stem, name_stem) # Create DEM from asc data anuga.asc2dem(name_stem+'.asc', use_cache=v_cache, verbose=v_verbose) # Create pts file for onshore DEM anuga.dem2pts(name_stem+'.dem', use_cache=v_cache, verbose=v_verbose) #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #------------------------------------------------------------------------------ domain = anuga.create_domain_from_regions(bounding_polygon, boundary_tags={'land_sse': [0], 'land_s': [1], 'bottom': [2], 'ocean_wsw': [3], 'ocean_w': [4], 'ocean_wnw': [5], 'top': [6], 'land_nne': [7],
#------------------------------------------------------------------------------ # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------ # Unzip asc from zip file import zipfile as zf if project.verbose: print 'Reading ASC from cairns.zip' zf.ZipFile(project.name_stem+'.zip').extract(project.name_stem+'.asc') # Create DEM from asc data anuga.asc2dem(project.name_stem+'.asc', use_cache=project.cache, verbose=project.verbose) # Create pts file for onshore DEM anuga.dem2pts(project.name_stem+'.dem', use_cache=project.cache, verbose=project.verbose) #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #------------------------------------------------------------------------------ domain = anuga.create_domain_from_regions(project.bounding_polygon, boundary_tags={'top': [0], 'ocean_east': [1], 'bottom': [2], 'onshore': [3]}, maximum_triangle_area=project.default_res, mesh_filename=project.meshname, interior_regions=project.interior_regions, use_cache=project.cache,
####### Do not change anything below this line ####### ###################################################### jobstart = time.time() # Create ASC from nc data VHIRL_conversions.nc2asc(dataset, name_stem, zone=zone) # Create DEM from asc data anuga.asc2dem(name_stem+'.asc', use_cache=v_cache, verbose=v_verbose) # Create pts file for onshore DEM anuga.dem2pts(name_stem+'.dem', use_cache=v_cache, verbose=v_verbose) #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #------------------------------------------------------------------------------ domain = anuga.create_domain_from_regions(busselton_extent, boundary_tags={'land_sse': [0], 'land_s': [1], 'bottom': [2], 'ocean_wsw': [3], 'ocean_w': [4], 'ocean_wnw': [5], 'top': [6], 'land_nne': [7],
import os import time import sys import anuga from anuga import distribute, myid, numprocs, finalize #------------------------------------------------------------------------------ # Do the domain creation on processor 0 #------------------------------------------------------------------------------ if myid == 0: # Create DEM from asc data anuga.asc2dem('11_fbe_c.asc', use_cache=False, verbose=True) # Create DEM from asc data anuga.dem2pts('11_fbe_c.dem', use_cache=False, verbose=True) bounding_polygon = anuga.read_polygon('channel.csv') domain = anuga.create_domain_from_regions(bounding_polygon, boundary_tags={'exterior': [1]}, maximum_triangle_area=1, mesh_filename='11f.msh', use_cache=False, verbose=True) #Name domain domain.set_name('11_fbe_c') domain.set_datadir('.') #Set quantities for domain, set dry bed
def generate_cairns_domain(gpu=False): #----------------------------------------------------------------------- # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data # and store result in source data #----------------------------------------------------------------------- # Create DEM from asc data anuga.asc2dem(project.name_stem+'.asc', use_cache=True, verbose=True) # Create pts file for onshore DEM anuga.dem2pts(project.name_stem+'.dem', use_cache=True, verbose=True) #----------------------------------------------------------------------- # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #----------------------------------------------------------------------- domain = anuga.create_domain_from_regions(project.bounding_polygon, boundary_tags={'top': [0], 'ocean_east': [1], 'bottom': [2], 'onshore': [3]}, maximum_triangle_area=project.default_res, mesh_filename=project.meshname, interior_regions=project.interior_regions, use_cache=True, verbose=True) if gpu : #domain.__class__ = GPU_domain domain = GPU_domain(domain=domain) # Print some stats about mesh and domain print 'Number of triangles = ', len(domain) #print 'The extent is ', domain.get_extent() #print domain.statistics() #----------------------------------------------------------------------- # Setup parameters of computational domain #----------------------------------------------------------------------- domain.set_name('cairns_' + project.scenario) # Name of sww file domain.set_datadir('.') # Store sww output here domain.set_minimum_storable_height(0.01) # Store only depth > 1cm domain.set_flow_algorithm('tsunami') #----------------------------------------------------------------------- # Setup initial conditions #----------------------------------------------------------------------- tide = 0.0 domain.set_quantity('stage', tide) domain.set_quantity('friction', 0.0) domain.set_quantity('elevation', filename=project.name_stem + '.pts', use_cache=True, verbose=True, alpha=0.1) #----------------------------------------------------------------------- # Setup information for slide scenario # (to be applied 1 min into simulation #----------------------------------------------------------------------- if project.scenario == 'slide': # Function for submarine slide tsunami_source = anuga.slide_tsunami(length=35000.0, depth=project.slide_depth, slope=6.0, thickness=500.0, x0=project.slide_origin[0], y0=project.slide_origin[1], alpha=0.0, domain=domain, verbose=True) #----------------------------------------------------------------------- # Setup boundary conditions #----------------------------------------------------------------------- print 'Available boundary tags', domain.get_boundary_tags() Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary if project.scenario == 'fixed_wave': # Huge 50m wave starting after 60 seconds and lasting 1 hour. Bw=anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary( domain=domain, function=lambda t: [(60<t<3660)*50, 0, 0]) domain.set_boundary({'ocean_east': Bw, 'bottom': Bs, 'onshore': Bd, 'top': Bs}) if project.scenario == 'slide': # Boundary conditions for slide scenario domain.set_boundary({'ocean_east': Bd, 'bottom': Bd, 'onshore': Bd, 'top': Bd}) if gpu: if '-gpu' in sys.argv: domain.using_gpu = True print " --> Enable GPU version" return domain
xvec = range(ncols) for i in range(nrows): srow = ' '.join([ str(x) for x in elev[i, :] ]) fid.write(srow) fid.write('\n') fid.close() metafilename = 'okada.prj' fid = open(metafilename, 'w') fid.write("""Projection UTM Zone 54 Datum WGS84 Zunits NO Units METERS Spheroid WGS84 Xshift 0.0000000000 Yshift 10000000.0000000000 Parameters """) fid.close() import anuga anuga.asc2dem(filename) anuga.dem2pts(filename)
#from floodpoint import * #from polygons import * #from breaklines import * #from culverts import * #------------------------------------------------------------------------------ # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------ # Create DEM from asc data anuga.asc2dem(project_minecraft.tmppath + 'mc_heightv2_utm.asc', use_cache=False, verbose=verbose) # Create pts file for onshore DEM anuga.dem2pts(project_minecraft.tmppath + 'mc_heightv2_utm.dem', use_cache=False, verbose=verbose) #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #------------------------------------------------------------------------------ bounding_polygon = anuga.read_polygon(project_minecraft.configpath + 'extent_minecraft.csv') meshname = project_minecraft.tmppath + 'output_minecraft.msh' mesh = anuga.create_mesh_from_regions( bounding_polygon, boundary_tags={
import anuga # application specific import import project # project.py consists of definition of file names and so on time00 = time.time() #------------------------------------------------------------------------------ # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------ path_to_data_dir = 'C:/anuga/thesis/pwrj_initcond/' if project.verbose: print 'Reading DEM data from pwrj.dem' # create PTS file from onshore DEM anuga.dem2pts(path_to_data_dir + project.name_stem + '.dem', use_cache=project.cache, verbose=project.verbose) #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on overall clipping # polygons with a tagged boundary and interior regions as defined # in project.py #------------------------------------------------------------------------------ domain = anuga.create_domain_from_regions( project.bounding_polygon, boundary_tags={ 'onshore': [0], 'east': [1], 'bottom_ocean': [2], 'west': [3] },
""" from anuga.operators.sed_transport.sed_transport_utils import create_domain_from_regions_sed """ Import file conversion and quantity setting functions for vegetation file """ from anuga.operators.sed_transport.file_conversion.generic_asc2dem import generic_asc2dem from anuga.operators.sed_transport.file_conversion.generic_dem2pts import generic_dem2pts from anuga.operators.sed_transport.sed_transport_utils import set_quantity_NNeigh #=============================================================================== # Setup Functions #=============================================================================== # Convert an elevation raster into a point file anuga.asc2dem('topo.asc', use_cache=False, verbose=True) anuga.dem2pts('topo.dem', use_cache=False, verbose=True) """ Include the process-specific quantities when creating the domain """ evolved_quantities = ['stage', 'xmomentum', 'ymomentum', 'concentration'] other_quantities=['elevation', 'friction', 'height', 'xvelocity', \ 'yvelocity', 'x', 'y', 'vegetation', 'diffusivity'] # import bounding polygon text file, set boundary tags bounding_polygon = anuga.read_polygon('outline.csv') boundary_tags = { 'bottom': [0], 'side1': [1], 'side2': [2], 'top': [3],
ny=len(mat['yh'][0,4][0]) f=open('talcahuano4.asc','w') f.write('ncols\t%i\n'%(nx)) f.write('nrows\t%i\n'%(ny)) f.write('xllcorner\t%.2f\n'%(x.min())) f.write('yllcorner\t%.2f\n'%(y.min())) f.write('cellsize\t%.2f\n'%(54.)) f.write('NODATA_value\t-9999\n') for j in range(ny): s='' for i in range(nx): s+='%.7f '%z[ny-j-1,i] f.write('%s\n'%s) f.close() anuga.asc2dem('talcahuano4.asc', use_cache=True, verbose=True) anuga.dem2pts('talcahuano4.dem') #ahora quiero sacar la triangulacion e interpolacion domain = anuga.Domain('talcahuano4.msh', use_cache=False, verbose=True) domain.set_quantity('elevation', filename='talcahuano4.pts') t=domain.get_triangles() xy=domain.get_nodes() xt,yt,zt,t=domain.get_quantity('elevation').get_vertex_values() plt.figure() plt.pcolormesh(x-b[:,0].min(),y-b[:,1].min(),z,cmap=cm.gray) plt.tripcolor(xt,yt,t,zt,cmap=cm.gist_earth) plt.contour(x-b[:,0].min(),y-b[:,1].min(),z,[0.],colors='w') plt.axis('equal') #plt.axis('off')
def generate_cairns_domain(gpu=False): #----------------------------------------------------------------------- # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data # and store result in source data #----------------------------------------------------------------------- # Create DEM from asc data anuga.asc2dem(project.name_stem + '.asc', use_cache=True, verbose=True) # Create pts file for onshore DEM anuga.dem2pts(project.name_stem + '.dem', use_cache=True, verbose=True) #----------------------------------------------------------------------- # Create the triangular mesh and domain based on # overall clipping polygon with a tagged # boundary and interior regions as defined in project.py #----------------------------------------------------------------------- domain = anuga.create_domain_from_regions( project.bounding_polygon, boundary_tags={ 'top': [0], 'ocean_east': [1], 'bottom': [2], 'onshore': [3] }, maximum_triangle_area=project.default_res, mesh_filename=project.meshname, interior_regions=project.interior_regions, use_cache=True, verbose=True) if gpu: #domain.__class__ = GPU_domain domain = GPU_domain(domain=domain) # Print some stats about mesh and domain print 'Number of triangles = ', len(domain) #print 'The extent is ', domain.get_extent() #print domain.statistics() #----------------------------------------------------------------------- # Setup parameters of computational domain #----------------------------------------------------------------------- domain.set_name('cairns_' + project.scenario) # Name of sww file domain.set_datadir('.') # Store sww output here domain.set_minimum_storable_height(0.01) # Store only depth > 1cm domain.set_flow_algorithm('tsunami') #----------------------------------------------------------------------- # Setup initial conditions #----------------------------------------------------------------------- tide = 0.0 domain.set_quantity('stage', tide) domain.set_quantity('friction', 0.0) domain.set_quantity('elevation', filename=project.name_stem + '.pts', use_cache=True, verbose=True, alpha=0.1) #----------------------------------------------------------------------- # Setup information for slide scenario # (to be applied 1 min into simulation #----------------------------------------------------------------------- if project.scenario == 'slide': # Function for submarine slide tsunami_source = anuga.slide_tsunami(length=35000.0, depth=project.slide_depth, slope=6.0, thickness=500.0, x0=project.slide_origin[0], y0=project.slide_origin[1], alpha=0.0, domain=domain, verbose=True) #----------------------------------------------------------------------- # Setup boundary conditions #----------------------------------------------------------------------- print 'Available boundary tags', domain.get_boundary_tags() Bd = anuga.Dirichlet_boundary([tide, 0, 0]) # Mean water level Bs = anuga.Transmissive_stage_zero_momentum_boundary(domain) # Neutral boundary if project.scenario == 'fixed_wave': # Huge 50m wave starting after 60 seconds and lasting 1 hour. Bw = anuga.Transmissive_n_momentum_zero_t_momentum_set_stage_boundary( domain=domain, function=lambda t: [(60 < t < 3660) * 50, 0, 0]) domain.set_boundary({ 'ocean_east': Bw, 'bottom': Bs, 'onshore': Bd, 'top': Bs }) if project.scenario == 'slide': # Boundary conditions for slide scenario domain.set_boundary({ 'ocean_east': Bd, 'bottom': Bd, 'onshore': Bd, 'top': Bd }) if gpu: if '-gpu' in sys.argv: domain.using_gpu = True print " --> Enable GPU version" return domain
import zipfile as zf path_to_data_dir = 'C:/anuga/thesis/pwrj_initcond/' if project.verbose: print 'Reading ASC from pwrjdem.zip' zf.ZipFile(path_to_data_dir + project.name_stem + '.zip').extract(project.name_stem + '.asc') zf.ZipFile(path_to_data_dir + project.name_stem + '.zip').extract(project.name_stem + '.prj') # building DEM from ASC data anuga.asc2dem(project.name_stem + '.asc', use_cache=project.cache, verbose=project.verbose) # create PTS file from onshore DEM anuga.dem2pts(project.name_stem + '.dem', use_cache=project.cache, verbose=project.verbose) #------------------------------------------------------------------------------ # Create the triangular mesh and domain based on overall clipping # polygons with a tagged boundary and interior regions as defined # in project.py #------------------------------------------------------------------------------ domain = anuga.create_domain_from_regions( project.bounding_polygon, boundary_tags={ 'east': [0], 'bottom_ocean': [1], 'west': [2], 'onshore': [3] },
#from floodpoint import * #from polygons import * #from breaklines import * #from culverts import * #------------------------------------------------------------------------------ # Preparation of topographic data # Convert ASC 2 DEM 2 PTS using source data and store result in source data #------------------------------------------------------------------------------ # Create DEM from asc data anuga.asc2dem(project.tmppath + 'dtm_utm.mean.asc', use_cache=False, verbose=verbose) # Create pts file for onshore DEM anuga.dem2pts(project.tmppath + 'dtm_utm.mean.dem', use_cache=False, verbose=verbose) bounding_polygon = anuga.read_polygon(project.configpath + 'extent.csv') #------------------------------------------------------------------------------ # Prepare breaklines # #------------------------------------------------------------------------------ conn_params = "host=titania dbname=research user=geodan" conn = psycopg2.connect(conn_params) cur = conn.cursor() breaklines = [] querystring = """ WITH extent AS ( SELECT ST_Transform(ST_SetSrid(ST_MakeEnvelope(%s),32631),28992) as geom
""" Import file conversion and quantity setting functions for vegetation file """ from anuga.operators.sed_transport.file_conversion.generic_asc2dem import generic_asc2dem from anuga.operators.sed_transport.file_conversion.generic_dem2pts import generic_dem2pts from anuga.operators.sed_transport.sed_transport_utils import set_quantity_NNeigh #=============================================================================== # Setup Functions #=============================================================================== # Convert an elevation raster into a point file anuga.asc2dem('topo.asc', use_cache = False, verbose = True) anuga.dem2pts('topo.dem', use_cache = False, verbose = True) """ Include the process-specific quantities when creating the domain """ evolved_quantities = ['stage', 'xmomentum', 'ymomentum', 'concentration'] other_quantities=['elevation', 'friction', 'height', 'xvelocity', \ 'yvelocity', 'x', 'y', 'vegetation', 'diffusivity'] # import bounding polygon text file, set boundary tags bounding_polygon = anuga.read_polygon('outline.csv') boundary_tags = {'bottom':[0], 'side1':[1],
def build_elevation(): """Create combined elevation data. Combine all raw elevation data and clip to bounding polygon. """ # if no elevation to combine, we *must* have a combined elevation file if not project.point_filenames: if not project.combined_elevation_file: abort('No raw elevation data and no combined elevation data!?') return # user wants us to create combined elevation, make output filename project.combined_elevation_file = os.path.join(project.topographies_folder, 'combined_elevation.pts') # # Create Geospatial data from ASCII files # geospatial_data = {} # if not project.ascii_grid_filenames == []: # for filename in project.ascii_grid_filenames: # absolute_filename = join(project.topographies_folder, filename) # # anuga.asc2dem(absolute_filename+'.asc', # use_cache=False, # verbose=True) # # anuga.dem2pts(absolute_filename+'.dem', use_cache=False, verbose=True) # # G_grid = anuga.geospatial_data.Geospatial_data(file_name=absolute_filename+'.pts',verbose=True) # # print 'Clip geospatial object' # geospatial_data[filename] = G_grid.clip(project.bounding_polygon) # Create Geospatial data from TXT files geospatial_data = {} for filename in project.point_filenames: log.info('Reading elevation file %s' % filename) absolute_filename = os.path.join(project.raw_elevation_directory, filename) name_stem = absolute_filename[:-4] # remove 'asc' log.info('name_stem=%s' % name_stem) anuga.asc2dem(absolute_filename, use_cache=False, verbose=True) anuga.dem2pts(name_stem+'.dem', use_cache=False, verbose=True) pts_filename = name_stem + '.pts' G_points = anuga.geospatial_data.\ Geospatial_data(file_name=pts_filename, verbose=False) geospatial_data[filename] = G_points.clip(project.bounding_polygon) ##### # Combine, clip and export dataset ##### G = None for key in geospatial_data: G += geospatial_data[key] G.export_points_file(project.combined_elevation_file) # Use for comparision in ARC # DO WE NEED THIS? try: (stem, _) = project.combined_elevation_file.rsplit('.', 1) except ValueError: stem = project.combined_elevation_file G.export_points_file(stem + '.txt')