当前位置: 首页>>代码示例>>Python>>正文


Python Delaunay.find_simplex方法代码示例

本文整理汇总了Python中scipy.spatial.Delaunay.find_simplex方法的典型用法代码示例。如果您正苦于以下问题:Python Delaunay.find_simplex方法的具体用法?Python Delaunay.find_simplex怎么用?Python Delaunay.find_simplex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.spatial.Delaunay的用法示例。


在下文中一共展示了Delaunay.find_simplex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show_hull

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def show_hull(cname, ccol):
    ccoords = coords[names==cname]

    hull = ConvexHull(ccoords)

    xs = ccoords.ix[:,0]
    ys = ccoords.ix[:,1]
    zs = ccoords.ix[:,2]
    #ax.scatter(xs, ys, zs, c=ccol, marker='o')

    for simplex in hull.simplices:
        s = ccoords.irow(simplex)
        #print s
        sx = list(s.ix[:,0])
        sy = list(s.ix[:,1])
        sz = list(s.ix[:,2])
        sx.append(sx[0])
        sy.append(sy[0])
        sz.append(sz[0])
        ax.plot(sx, sy, sz, ccol, alpha=0.2)

    hulld = Delaunay(ccoords.irow(hull.vertices))
    hulld.find_simplex(coords)
    hcol = ['grey' if x<0 else 'green' for x in hulld.find_simplex(coords)]
    hxs = coords.ix[:,0]
    hys = coords.ix[:,1]
    hzs = coords.ix[:,2]
    ax.scatter(hxs, hys, hzs, c=hcol, marker='o', alpha=0.2)
开发者ID:coreyabshire,项目名称:color-names,代码行数:30,代码来源:diagnostics.py

示例2: draw_dimension

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
    def draw_dimension(self, dimNumber):
        '''
        Method to draw the points on the axes using the current dimension number
        '''

        self.ax.cla()

        dim0 = self.combinations[self.dimNumber][0]
        dim1 = self.combinations[self.dimNumber][1]

        self.ax.plot(self.points[:,dim0][self.inCluster], self.points[:, dim1][self.inCluster], 'g.')
        
        self.ax.plot(self.points[:, dim0][self.outsideCluster], self.points[:,dim1][self.outsideCluster], marker='.', color='0.8', linestyle='None')

        self.ax.set_xlabel('Dimension {}'.format(dim0))
        self.ax.set_ylabel('Dimension {}'.format(dim1))

        
        plt.title('press c to cut, < or > to switch dimensions')
        self.fig.canvas.draw()
        
    
        ''' Method to take the current points from mouse input, 
        convert them to a convex hull, and then update the inCluster and 
outsideCluster attributes based on the points that fall within the hull'''

        if not isinstance(hull, Delaunay):
            hull=Delaunay(hull)

        self.inCluster = hull.find_simplex(points)>=0
        self.outsideCluster=np.logical_not(self.inCluster)
开发者ID:nickponvert,项目名称:python-testing,代码行数:33,代码来源:clusterCutting.py

示例3: _simplex_interp

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
    def _simplex_interp(self, teff, logg, fe, model_indecies):
        """
        Perform barycentric interpolation on simplecies

        Args:
            teff (float): effective temperature
            logg (float): surface gravity
            fe (float): metalicity
            model_indecies (array): models to use in the interpolation

        Returns:
            array: spectrum at teff, logg, fe

        """

        ndim = 3
        model_table = np.array(self.model_table['teff logg fe'.split()])
        points = model_table[model_indecies]
        tri = Delaunay(points) # Delaunay triangulation
        p = np.array([teff, logg, fe]) # cartesian coordinates

        simplex = tri.find_simplex(p)
        r = tri.transform[simplex,ndim,:]
        Tinv = tri.transform[simplex,:ndim,:ndim]
        c = Tinv.dot(p - r)
        c = np.hstack([c,1.0-c.sum()]) # barycentric coordinates

        # (3,many array)
        model_indecies_interp = model_indecies[tri.simplices[simplex]]
        model_spectra = self.model_spectra[model_indecies_interp,:]
        flux = np.dot(c,model_spectra)
        if simplex==-1:
            return np.ones_like(flux)
        return flux
开发者ID:petigura,项目名称:specmatch-syn,代码行数:36,代码来源:library.py

示例4: triangulate

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
	def triangulate(self, size):
		shape = self.mImg.shape
		spacing = max(shape) / size
		sigma = spacing / 4
		coords = self._get_distributed_points(spacing, sigma, include_corners = True)
		
		tri = Delaunay(coords)
		im_pts = self.get_xy_features()
		# pt_tri_membership becomes a map which is the same size as the
		# original image (first two dimensions only). each element contains
		# the triangle ID of that point in the source image
		pt_tri_membership = tri.find_simplex(im_pts.astype(dtype = np.double))
		pt_tri_membership.resize(shape[0], shape[1])
		num_tri = np.max(pt_tri_membership)

		tri_map = np.copy(self.mImg) 
		# replace elements of each triangle with the mean value of the color
		# channels from the original image
		for tri in range(num_tri + 1):
			this_tri = pt_tri_membership == tri
			if not np.any(this_tri):
				continue
			for col in range(shape[2]):
				tri_map[this_tri, col] = np.mean(self.mImg[this_tri, col])
		return tri_map
开发者ID:nmiodice,项目名称:PyImageProcessing,代码行数:27,代码来源:imageutils.py

示例5: __init__

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
    def __init__(self, target_image_dimensions, target_vertices=None):
        self.target_image_dimensions = target_image_dimensions
        # if target vertices are not set, assume we want to fill the entire targetImage
        if not target_vertices:
            rows, columns = target_image_dimensions[:2]
            self.target_vertices = np.array([[0, 0],
                                             [0, columns],
                                             [rows, 0],
                                             [rows, columns]])
        else:
            self.target_vertices = target_vertices

        r0, c0 = np.round(np.mean(self.target_vertices, axis=0)).astype(np.int32)
        self.target_vertices = np.array(sorted(self.target_vertices, key=lambda (r, c): np.arctan2(r0 - r, c0 - c)))
        # get barycentric coordinates and corresponding points in target (new) image
        nys = np.arange(self.target_image_dimensions[0])
        nxs = np.arange(self.target_image_dimensions[1])
        image_pixels = np.transpose([np.repeat(nys, len(nxs)), np.tile(nxs, len(nys))])

        triangles = Delaunay(self.target_vertices)
        memberships = triangles.find_simplex(image_pixels)  # returns the triangle that each pixel is a member of
        Ts = triangles.transform[memberships, :2]  # transformation matrices
        prs = image_pixels - triangles.transform[memberships, 2]  # intermediate transformation

        barycentric_coordinates = np.array([Ts[i].dot(pr) for i, pr in enumerate(prs)])
        barycentric_coordinates = np.hstack((barycentric_coordinates,
                                            1 - np.sum(barycentric_coordinates, axis=1, keepdims=True)))

        target_vertices_indices = triangles.simplices[memberships]

        self.targetRow = image_pixels[:, 0]
        self.targetCol = image_pixels[:, 1]
        self.barycentric = barycentric_coordinates
        self.indices = target_vertices_indices
开发者ID:Billtholomew,项目名称:FaceNormalizer,代码行数:36,代码来源:transformation.py

示例6: zonotope_quadrature_rule

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def zonotope_quadrature_rule(avmap, N, NX=10000):
    """
    Description of zonotope_quadrature_rule

    Arguments:
        vert:
        W1:
        N:
        NX: (default=10000)
    Outputs:
        points:
        weights:
    """
    
    vert = avmap.domain.vertY
    W1 = avmap.domain.subspaces.W1    
    
    # number of dimensions
    m, n = W1.shape

    # points
    y = np.vstack((vert, maximin_design(vert, N)))
    T = Delaunay(y)
    c = []
    for t in T.simplices:
        c.append(np.mean(T.points[t], axis=0))
    points = np.array(c)

    # approximate weights
    Y_samples = np.dot(np.random.uniform(-1.0, 1.0, size=(NX,m)), W1)
    I = T.find_simplex(Y_samples)
    weights = np.zeros((T.nsimplex, 1))
    for i in range(T.nsimplex):
        weights[i] = np.sum(I==i) / float(NX)
    return points.reshape((T.nsimplex,n)), weights.reshape((T.nsimplex,1))
开发者ID:dasssj,项目名称:active_subspaces,代码行数:37,代码来源:as_integrals.py

示例7: inside_convex_poly

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def inside_convex_poly(pts):
    """Returns a function that checks if inputs are inside the convex hull of polyhedron defined by pts

    Alternative method to check is to get faces of the convex hull, then check if each normal is pointed away from each point.
    As it turns out, this is vastly slower than using qhull's find_simplex, even though the simplex is not needed.
    """
    tri = Delaunay(pts)
    return lambda x: tri.find_simplex(x) != -1
开发者ID:imclab,项目名称:pycortex,代码行数:10,代码来源:polyutils.py

示例8: chromaticity_diagram_visual

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def chromaticity_diagram_visual(
        samples=256,
        cmfs='CIE 1931 2 Degree Standard Observer',
        transformation='CIE 1931',
        parent=None):
    """
    Creates a chromaticity diagram visual based on
    :class:`colour_analysis.visuals.Primitive` class.

    Parameters
    ----------
    samples : int, optional
        Inner samples count used to construct the chromaticity diagram
        triangulation.
    cmfs : unicode, optional
        Standard observer colour matching functions used for the chromaticity
        diagram boundaries.
    transformation : unicode, optional
        {'CIE 1931', 'CIE 1960 UCS', 'CIE 1976 UCS'}

        Chromaticity diagram transformation.
    parent : Node, optional
        Parent of the chromaticity diagram in the `SceneGraph`.

    Returns
    -------
    Primitive
        Chromaticity diagram visual.
    """

    cmfs = get_cmfs(cmfs)

    illuminant = DEFAULT_PLOTTING_ILLUMINANT

    XYZ_to_ij = (
        CHROMATICITY_DIAGRAM_TRANSFORMATIONS[transformation]['XYZ_to_ij'])
    ij_to_XYZ = (
        CHROMATICITY_DIAGRAM_TRANSFORMATIONS[transformation]['ij_to_XYZ'])

    ij_c = XYZ_to_ij(cmfs.values, illuminant)

    triangulation = Delaunay(ij_c, qhull_options='QJ')
    samples = np.linspace(0, 1, samples)
    ii, jj = np.meshgrid(samples, samples)
    ij = tstack((ii, jj))
    ij = np.vstack((ij_c, ij[triangulation.find_simplex(ij) > 0]))

    ij_p = np.hstack((ij, np.full((ij.shape[0], 1), 0)))
    triangulation = Delaunay(ij, qhull_options='QJ')
    RGB = normalise(XYZ_to_sRGB(ij_to_XYZ(ij, illuminant), illuminant),
                    axis=-1)

    diagram = Primitive(vertices=ij_p,
                        faces=triangulation.simplices,
                        vertex_colours=RGB,
                        parent=parent)

    return diagram
开发者ID:lucienfostier,项目名称:colour-analysis,代码行数:60,代码来源:diagrams.py

示例9: interp_weights

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def interp_weights(xyz, uvw,d=3):

    tri = Delaunay(xyz)
    simplex = tri.find_simplex(uvw)
    vertices = np.take(tri.simplices, simplex, axis=0)
    temp = np.take(tri.transform, simplex, axis=0)
    delta = uvw - temp[:, d]
    bary = np.einsum('njk,nk->nj', temp[:, :d, :], delta)
    return vertices, np.hstack((bary, 1 - bary.sum(axis=1, keepdims=True)))
开发者ID:jswoboda,项目名称:GeoDataPython,代码行数:11,代码来源:GeoData.py

示例10: inside_hull

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
 def inside_hull(self, labels):
     """This method checks whether a requested set of labels is inside the
     convex hull of the training data.  Returns a bool.  This method relies
     on Delauynay Triangulation and is thus exceedlingly slow for large
     dimensionality.
     """
     L = flatten_struct(self.training_labels, use_labels=self.used_labels)
     l = flatten_struct(labels, use_labels=self.used_labels)
     hull = Delaunay(L.T)
     return hull.find_simplex(l.T) >= 0
开发者ID:bd-j,项目名称:psi,代码行数:12,代码来源:models.py

示例11: cut_cluster

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
    def cut_cluster(self, points, hull):
        ''' Method to take the current points from mouse input, 
        convert them to a convex hull, and then update the inCluster and 
outsideCluster attributes based on the points that fall within the hull'''

        if not isinstance(hull, Delaunay):
            hull=Delaunay(hull)

        self.inCluster = hull.find_simplex(points)>=0
        self.outsideCluster=np.logical_not(self.inCluster)
开发者ID:nickponvert,项目名称:python-testing,代码行数:12,代码来源:clusterObj.py

示例12: check_polygon_membership

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def check_polygon_membership(cluster_boundary, points_to_check):
    cluster_boundary_points = [[x[0], x[1]] for x in cluster_boundary]
    hull = cluster_boundary_points
    if not isinstance(hull, Delaunay):
        hull = Delaunay(hull)
    gps_coords_to_check = [[x[0], x[1]] for x in points_to_check]
    point_in_cluster = []
    for coord in gps_coords_to_check:
        point_in_cluster.append(1 if hull.find_simplex(coord) >= 0 else 0)
    return point_in_cluster
开发者ID:syedshabihhasan,项目名称:gps_processing,代码行数:12,代码来源:gpsTools.py

示例13: zonotope_quadrature_rule

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def zonotope_quadrature_rule(avmap, N, NX=10000):
    """Quadrature rule on a zonotope.
    
    Quadrature when the dimension of the active subspace is greater than 1 and
    the simulation parameter space is bounded.

    Parameters
    ----------
    avmap : ActiveVariableMap 
        a domains.ActiveVariableMap
    N : int 
        the number of quadrature nodes in the active variables
    NX : int, optional 
        the number of samples to use to estimate the quadrature weights (default
        10000)

    Returns
    -------
    Yp : ndarray
        quadrature nodes on the active variables
    Yw : ndarray 
        quadrature weights on the active variables

    See Also
    --------
    integrals.quadrature_rule
    """

    vert = avmap.domain.vertY
    W1 = avmap.domain.subspaces.W1

    # number of dimensions
    m, n = W1.shape

    # points
    y = np.vstack((vert, maximin_design(vert, N)))
    T = Delaunay(y)
    c = []
    for t in T.simplices:
        c.append(np.mean(T.points[t], axis=0))
    points = np.array(c)

    # approximate weights
    Y_samples = np.dot(np.random.uniform(-1.0, 1.0, size=(NX,m)), W1)
    I = T.find_simplex(Y_samples)
    weights = np.zeros((T.nsimplex, 1))
    for i in range(T.nsimplex):
        weights[i] = np.sum(I==i) / float(NX)

    Yp, Yw = points.reshape((T.nsimplex,n)), weights.reshape((T.nsimplex,1))
    return Yp, Yw
开发者ID:mtezzele,项目名称:active_subspaces,代码行数:53,代码来源:integrals.py

示例14: test_find_nn_triangles_point

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def test_find_nn_triangles_point():
    r"""Test find natural neighbors for a point function."""
    x = list(range(10))
    y = list(range(10))
    gx, gy = np.meshgrid(x, y)
    pts = np.vstack([gx.ravel(), gy.ravel()]).T
    tri = Delaunay(pts)

    tri_match = tri.find_simplex([4.5, 4.5])

    truth = [62, 63]

    nn = find_nn_triangles_point(tri, tri_match, [4.5, 4.5])

    assert_array_almost_equal(truth, nn)
开发者ID:akrherz,项目名称:MetPy,代码行数:17,代码来源:test_geometry.py

示例15: inConvexHull

# 需要导入模块: from scipy.spatial import Delaunay [as 别名]
# 或者: from scipy.spatial.Delaunay import find_simplex [as 别名]
def inConvexHull(dictionary, mx, my):
    """
    Check if (mx,my) point is in the data dictionary.

    """
    import numpy
    from scipy.spatial import Delaunay

    pointlist = []
    for k in dictionary.keys():
        for ki in dictionary[k].keys():
            pointlist.append([k, ki])
    p = numpy.array(pointlist)
    dela = Delaunay(p)
    return dela.find_simplex((mx, my)) >= 0
开发者ID:restrepo,项目名称:DMLR-Toolbox,代码行数:17,代码来源:smsResults.py


注:本文中的scipy.spatial.Delaunay.find_simplex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。