示例#1
0
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)
示例#2
0
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')
示例#3
0
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
#------------------------------------------------------------------------------

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],
示例#5
0
asc_name = 'topography1.asc'
meshname = 'merewether.msh'
dem_name = 'topography1.dem'

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]]
asc_name = 'topography1.asc' 
meshname = 'merewether.msh'
dem_name = 'topography1.dem'

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]]
示例#7
0
def VegCreate(name_in, quantity_name):
    easting_min = None
    easting_max = None
    northing_min = None
    northing_max = None

    anuga.asc2dem(name_in + '.asc', use_cache=False, verbose=True)

    infile = NetCDFFile(name_in + '.dem', netcdf_mode_r)

    ncols = int(infile.ncols)
    nrows = int(infile.nrows)
    xllcorner = float(infile.xllcorner)  # Easting of lower left corner
    yllcorner = float(infile.yllcorner)  # Northing of lower left corner
    cellsize = float(infile.cellsize)
    NODATA_value = float(infile.NODATA_value)

    dem_elevation = infile.variables['elevation']

    # Assign default values
    if easting_min is None: easting_min = xllcorner
    if easting_max is None: easting_max = xllcorner + ncols * cellsize
    if northing_min is None: northing_min = yllcorner
    if northing_max is None: northing_max = yllcorner + nrows * cellsize

    y = np.arange(nrows, dtype=np.float)
    y = yllcorner + (nrows - 1) * cellsize - y * cellsize

    x = np.arange(ncols, dtype=np.float)
    x = xllcorner + x * cellsize

    xx, yy = np.meshgrid(x, y)
    xx = xx.flatten()
    yy = yy.flatten()

    flag = np.logical_and(
        np.logical_and((xx <= easting_max), (xx >= easting_min)),
        np.logical_and((yy <= northing_max), (yy >= northing_min)))

    dem = dem_elevation[:].flatten()

    id = np.where(flag)[0]
    xx = xx[id]
    yy = yy[id]
    dem = dem[id]

    data_flag = dem != NODATA_value
    data_id = np.where(data_flag)

    points = np.zeros((len(data_id[0]), 3))
    points[:, 0] = xx[data_id] - easting_min
    points[:, 1] = yy[data_id] - northing_min
    points[:, 2] = dem[data_id]

    x_ = np.arange(0, np.ceil(points[:, 0].max() + 1))
    y_ = np.arange(0, np.ceil(points[:, 1].max() + 1))

    grid_x, grid_y = np.meshgrid(x_, y_)
    grid_z = np.zeros_like(grid_x)

    dem = dem_elevation[:]
    dem = dem.data
    grid_z = dem

    points = np.vstack(
        (grid_x.flatten() + easting_min, grid_y.flatten() + northing_min,
         grid_z.flatten())).T

    infile.close()

    interp = NearestNDInterpolator(points[:, 0:2], points[:, 2])

    coord = domain.get_centroid_coordinates(absolute=True)
    z_ = interp(coord)

    print 'Veg Load: saving interpolated file: ', name_in + '_interp.npy'
    np.save(name_in + '_interp.npy', z_)
    dem_asc_file = 'data/dem.asc'
    dem_cdf_file = 'data/dem.dem'
    dem_pts_file = 'data/dem.pts'
    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,
示例#9
0
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')
示例#10
0
for i in np.arange(0, 9):
    Parameters[i] = str(Parameter_names[i]) + " " + str(Parameter_vals[i])

#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,
示例#11
0
time00 = time.time()
#------------------------------------------------------------------------------
# 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],
#------------------------------------------------------------------------------
# Do the domain creation on processor 0
#------------------------------------------------------------------------------
if myid == 0:

    #------------------------------------------------------------------------------
    # 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]},
示例#13
0
# Data for Tides
#------------------------------------------------------------------------------
v_tide = ${tide}


####### 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],
示例#14
0
# coding: utf-8

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('.')
示例#15
0
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
示例#16
0
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 anuga.culvert_flows.culvert_class import Culvert_flow
#from anuga.culvert_flows.culvert_routines import boyd_generalised_culvert_model

# Application specific imports
#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'
Import operator-specific version of domain function
"""
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],
示例#19
0
#------------------------------------------------------------------------------
print 'project.bounding_polygon', project.bounding_polygon
print 'project.combined_elevation_basename', project.combined_elevation_basename
# 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)
        # 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:
nx=len(mat['xh'][0,4][0])
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')
示例#21
0
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
示例#22
0
#------------------------------------------------------------------------------
# Preparation of topographic data
# Convert ASC 2 DEM 2 PTS using source data and store result in source data
#------------------------------------------------------------------------------
# unzip .asc file from zip file
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={
示例#23
0
import project
import anuga

# Application specific imports
#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()
"""
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],
示例#25
0
# In[1]:

import os
import time
import sys

import anuga

from math import sin, pi, exp

# In[2]:

# Create DEM from asc data
anuga.asc2dem('C://Users//ps29626//Desktop//NewAnugaRun//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)

# Create roughness raster from asc data
#anuga.asc2dem('11_man_c.asc', use_cache=False, verbose=True)

# Create roughness raster from asc data
#anuga.dem2pts('11_man_c.dem', use_cache=False,
#              verbose=True)

# In[3]:

bounding_polygon = anuga.read_polygon('extent.csv')