예제 #1
0
    def calc_grid_values(nrows, ncols, cellsize, NODATA_value, x, y, norms,
                         volumes, result, grid_values):

        grid_points = num.zeros((ncols * nrows, 2), num.float)
        vertex_points = num.concatenate((x[:, num.newaxis], y[:, num.newaxis]),
                                        axis=1)
        assert len(vertex_points.shape) == 2

        for i in xrange(nrows):
            yg = i * cellsize
            #            if out_ext == '.asc':
            #                yg = i * cellsize
            #            else:
            #                # this will flip the order of the y values for ers
            #                yg = (nrows-i) * cellsize

            for j in xrange(ncols):
                xg = j * cellsize
                k = i * ncols + j

                grid_points[k, 0] = xg
                grid_points[k, 1] = yg

        # Interpolate
        from anuga.fit_interpolate.interpolate import Interpolate

        # Remove loners from vertex_points, volumes here
        vertex_points, volumes = remove_lone_verts(vertex_points, volumes)
        # export_mesh_file('monkey.tsh',{'vertices':vertex_points, 'triangles':volumes})

        interp = Interpolate(vertex_points, volumes, verbose=verbose)

        # Interpolate using quantity values
        if verbose: log.critical('Interpolating')
        grid_values[:] = interp.interpolate(result,
                                            grid_points,
                                            NODATA_value=NODATA_value,
                                            verbose=verbose).flatten()
        #print grid_values.shape

        return
예제 #2
0
    def calc_grid_values_old(vertex_points, volumes, result):

        grid_points = num.zeros ((ncols*nrows, 2), num.float)

        for i in xrange(nrows):
            if out_ext == '.asc':
                yg = i * cellsize
            else:
                # this will flip the order of the y values for ers
                yg = (nrows-i) * cellsize

            for j in xrange(ncols):
                xg = j * cellsize
                k = i*ncols + j

                grid_points[k, 0] = xg
                grid_points[k, 1] = yg

        # Interpolate
        from anuga.fit_interpolate.interpolate import Interpolate

        # Remove loners from vertex_points, volumes here
        vertex_points, volumes = remove_lone_verts(vertex_points, volumes)
        # export_mesh_file('monkey.tsh',{'vertices':vertex_points, 'triangles':volumes})


        interp = Interpolate(vertex_points, volumes, verbose = verbose)

        bprint = 0

        # Interpolate using quantity values
        if verbose: log.critical('Interpolating')
        grid_values = interp.interpolate(bprint, result, grid_points).flatten()
        outside_indices = interp.get_outside_poly_indices()

        for i in outside_indices:
            #print 'change grid_value',NODATA_value
            grid_values[i] = NODATA_value
	
        return grid_values
예제 #3
0
    def calc_grid_values(nrows, ncols, cellsize, NODATA_value,
                         x,y, norms, volumes, result, grid_values):

        grid_points = num.zeros ((ncols*nrows, 2), num.float)
        vertex_points = num.concatenate ((x[:,num.newaxis], y[:,num.newaxis]), axis=1)
        assert len(vertex_points.shape) == 2

        for i in xrange(nrows):
            yg = i * cellsize
#            if out_ext == '.asc':
#                yg = i * cellsize
#            else:
#                # this will flip the order of the y values for ers
#                yg = (nrows-i) * cellsize

            for j in xrange(ncols):
                xg = j * cellsize
                k = i*ncols + j

                grid_points[k, 0] = xg
                grid_points[k, 1] = yg

        # Interpolate
        from anuga.fit_interpolate.interpolate import Interpolate

        # Remove loners from vertex_points, volumes here
        vertex_points, volumes = remove_lone_verts(vertex_points, volumes)
        # export_mesh_file('monkey.tsh',{'vertices':vertex_points, 'triangles':volumes})


        interp = Interpolate(vertex_points, volumes, verbose = verbose)

        # Interpolate using quantity values
        if verbose: log.critical('Interpolating')
        grid_values[:] = interp.interpolate(result, grid_points,
                                         NODATA_value= NODATA_value,
                                         verbose=verbose).flatten()
        #print grid_values.shape

        return
    def calc_grid_values_old(vertex_points, volumes, result):

        grid_points = num.zeros((ncols * nrows, 2), num.float)

        for i in range(nrows):
            if out_ext == '.asc':
                yg = i * cellsize
            else:
                # this will flip the order of the y values for ers
                yg = (nrows - i) * cellsize

            for j in range(ncols):
                xg = j * cellsize
                k = i * ncols + j

                grid_points[k, 0] = xg
                grid_points[k, 1] = yg

        # Interpolate
        from anuga.fit_interpolate.interpolate import Interpolate

        # Remove loners from vertex_points, volumes here
        vertex_points, volumes = remove_lone_verts(vertex_points, volumes)
        # export_mesh_file('monkey.tsh',{'vertices':vertex_points, 'triangles':volumes})

        interp = Interpolate(vertex_points, volumes, verbose=verbose)

        bprint = 0

        # Interpolate using quantity values
        if verbose: log.critical('Interpolating')
        grid_values = interp.interpolate(bprint, result, grid_points).flatten()
        outside_indices = interp.get_outside_poly_indices()

        for i in outside_indices:
            #print 'change grid_value',NODATA_value
            grid_values[i] = NODATA_value

        return grid_values
예제 #5
0
    for i in xrange(nrows):
        if out_ext == '.asc':
            yg = i * cellsize
        else:
            # this will flip the order of the y values for ers
            yg = (nrows-i) * cellsize

        for j in xrange(ncols):
            xg = j * cellsize
            k = i*ncols + j

            grid_points[k, 0] = xg
            grid_points[k, 1] = yg

    # Remove loners from vertex_points, volumes here
    vertex_points, volumes = remove_lone_verts(vertex_points, volumes)
    # export_mesh_file('monkey.tsh',{'vertices':vertex_points, 'triangles':volumes})
    interp = Interpolate(vertex_points, volumes, verbose=verbose)

    log.debug('Interpolating')

    # Interpolate using quantity values
    grid_values = interp.interpolate(result, grid_points).flatten()

    log.debug('Interpolated values are in [%f, %f]'
              % (num.min(grid_values), num.max(grid_values)))

    # Assign NODATA_value to all points outside bounding polygon (from interpolation mesh)
    P = interp.mesh.get_boundary_polygon()
    outside_indices = outside_polygon(grid_points, P, closed=True)