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


Python interpolate.splprep方法代码示例

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


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

示例1: set_params

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def set_params(self, params, start=None, goal=None):

        points = params.reshape((-1, self.d)).T

        if start is not None:
            points = np.hstack((start[:, None], points))

        if goal is not None:
            points = np.hstack((points, goal[:, None]))

        self.tck, u = si.splprep(points, k=3)

        if start is not None:
            for a, sv in izip(self.tck[1], start):
                a[0] = sv

        if goal is not None:
            for a, gv in izip(self.tck[1], goal):
                a[-1] = gv 
开发者ID:zi-w,项目名称:Ensemble-Bayesian-Optimization,代码行数:21,代码来源:rover_utils.py

示例2: get_velocities

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def get_velocities(positions, times, tol):
    positions = np.atleast_2d(positions)
    n = len(positions)
    deg = min(3, n - 1)

    good_inds = np.r_[True, (abs(times[1:] - times[:-1]) >= 1e-6)]
    good_positions = positions[good_inds]
    good_times = times[good_inds]

    if len(good_inds) == 1:
        return np.zeros(positions[0:1].shape)

    (tck, _) = si.splprep(good_positions.T, s=tol ** 2 * (n + 1), u=good_times, k=deg)
    # smooth_positions = np.r_[si.splev(times,tck,der=0)].T
    velocities = np.r_[si.splev(times, tck, der=1)].T
    return velocities 
开发者ID:alexlee-gk,项目名称:visual_dynamics,代码行数:18,代码来源:resampling.py

示例3: _interpolate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def _interpolate(xy, num_points):
  tck,u = splprep([
    xy[:,0],
    xy[:,1]],
    s=0
  )
  unew = linspace(0, 1, num_points)
  out = splev(unew, tck)
  return column_stack(out) 
开发者ID:inconvergent,项目名称:sand-glyphs,代码行数:11,代码来源:utils.py

示例4: _rnd_interpolate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def _rnd_interpolate(xy, num_points, ordered=False):
  tck,u = splprep([
    xy[:,0],
    xy[:,1]],
    s=0
  )
  unew = random(num_points)
  if ordered:
    unew = sort(unew)
  out = splev(unew, tck)
  return column_stack(out) 
开发者ID:inconvergent,项目名称:sand-glyphs,代码行数:13,代码来源:utils.py

示例5: distribute

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def distribute(self, direction='u', number=0, type='constant'):

        if direction == 'u':
            line = np.array(self.getULines()[number])
        elif direction == 'v':
            line = np.array(self.getVLines()[number])

        # interpolate B-spline through data points
        # here, a linear interpolant is derived "k=1"
        # splprep returns:
        # tck ... tuple (t,c,k) containing the vector of knots,
        #         the B-spline coefficients, and the degree of the spline.
        #   u ... array of the parameters for each given point (knot)
        tck, u = interpolate.splprep(line.T, s=0, k=1)

        if type == 'constant':
            t = np.linspace(0.0, 1.0, num=len(line))
        if type == 'transition':
            first = np.array(self.getULines()[0])
            last = np.array(self.getULines()[-1])
            tck_first, u_first = interpolate.splprep(first.T, s=0, k=1)
            tck_last, u_last = interpolate.splprep(last.T, s=0, k=1)
            if number < 0.0:
                number = len(self.getVLines())
            v = float(number) / float(len(self.getVLines()))
            t = (1.0 - v) * u_first + v * u_last

        # evaluate function at any parameter "0<=t<=1"
        line = interpolate.splev(t, tck, der=0)
        line = list(zip(line[0].tolist(), line[1].tolist()))

        if direction == 'u':
            self.getULines()[number] = line
        elif direction == 'v':
            for i, uline in enumerate(self.getULines()):
                self.getULines()[i][number] = line[i] 
开发者ID:chiefenne,项目名称:PyAero,代码行数:38,代码来源:Meshing.py

示例6: spline

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def spline(self, x, y, points=200, degree=2, evaluate=False):
        """Interpolate spline through given points

        Args:
            spline (int, optional): Number of points on the spline
            degree (int, optional): Degree of the spline
            evaluate (bool, optional): If True, evaluate spline just at
                                       the coordinates of the knots
        """

        # interpolate B-spline through data points
        # returns knots of control polygon
        # tck ... tuple (t,c,k) containing the vector of knots,
        # the B-spline coefficients, and the degree of the spline.
        # u ... array of the parameters for each knot
        # NOTE: s=0.0 is important as no smoothing should be done on the spline
        # after interpolating it
        tck, u = interpolate.splprep([x, y], s=0.0, k=degree)

        # number of points on interpolated B-spline (parameter t)
        t = np.linspace(0.0, 1.0, points)

        # if True, evaluate spline just at the coordinates of the knots
        if evaluate:
            t = u

        # evaluate B-spline at given parameters
        # der=0: returns point coordinates
        coo = interpolate.splev(t, tck, der=0)

        # evaluate 1st derivative at given parameters
        der1 = interpolate.splev(t, tck, der=1)

        # evaluate 2nd derivative at given parameters
        der2 = interpolate.splev(t, tck, der=2)

        spline_data = [coo, u, t, der1, der2, tck]

        return spline_data 
开发者ID:chiefenne,项目名称:PyAero,代码行数:41,代码来源:SplineRefine.py

示例7: get_boundary_points

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def get_boundary_points(x, y):
    tck, u = interpolate.splprep([x, y], s=0, per=1)
    unew = np.linspace(u.min(), u.max(), 1000)
    xnew, ynew = interpolate.splev(unew, tck, der=0)
    tup = c_[xnew.astype(int), ynew.astype(int)].tolist()
    coord = list(set(tuple(map(tuple, tup))))
    coord = np.array([list(elem) for elem in coord])
    return np.array(coord[:, 0], dtype=np.int32), np.array(coord[:, 1], dtype=np.int32) 
开发者ID:srivatsan-ramesh,项目名称:Virtual-Makeup,代码行数:10,代码来源:nail.py

示例8: getBoundaryPoints

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def getBoundaryPoints(x = [], y = []):
	tck,u = interpolate.splprep([x, y], s=0, per=1)
	unew = np.linspace(u.min(), u.max(), 1000)
	xnew,ynew = interpolate.splev(unew, tck, der=0)
	tup = c_[xnew.astype(int),ynew.astype(int)].tolist()
	coord = list(set(tuple(map(tuple, tup))))
	coord = np.array([list(elem) for elem in coord])
	return coord[:,0],coord[:,1] 
开发者ID:badarsh2,项目名称:Virtual-Makeup,代码行数:10,代码来源:nail.py

示例9: getBoundaryPoints

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def getBoundaryPoints(x , y):
    tck,u = interpolate.splprep([x, y], s=0, per=1)
    unew = np.linspace(u.min(), u.max(), 10000)
    xnew,ynew = interpolate.splev(unew, tck, der=0)
    tup = c_[xnew.astype(int),ynew.astype(int)].tolist()
    coord = list(set(tuple(map(tuple, tup))))
    coord = np.array([list(elem) for elem in coord])
    return coord[:,0],coord[:,1] 
开发者ID:badarsh2,项目名称:Virtual-Makeup,代码行数:10,代码来源:foundation.py

示例10: getCircularBounds

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def getCircularBounds(fitCloud=None,width=64,height=64,smoothing=0.01):
    circumference = 2*(width+height)
    
    if not fitCloud is None:
        cx = np.mean(fitCloud[:,0])
        cy = np.mean(fitCloud[:,1])
        r = 0.5* max( np.max(fitCloud[:,0])- np.min(fitCloud[:,0]),np.max(fitCloud[:,1])- np.min(fitCloud[:,1]))
    else:
        r = circumference /(2.0*math.pi)
        cx = cy = r
    perimeterPoints = np.zeros((circumference,2),dtype=float)
    for i in range(circumference):
        angle = (2.0*math.pi)*float(i) / circumference - math.pi * 0.5 
        perimeterPoints[i][0] = cx + r * math.cos(angle)
        perimeterPoints[i][1] = cy + r * math.sin(angle)
        
        
    bounds = {'top':perimeterPoints[0:width],
              'right':perimeterPoints[width-1:width+height-1],
              'bottom':perimeterPoints[width+height-2:2*width+height-2],
              'left':perimeterPoints[2*width+height-3:]}
    
    bounds['s_top'],u = interpolate.splprep([bounds['top'][:,0], bounds['top'][:,1]],s=smoothing)
    bounds['s_right'],u = interpolate.splprep([bounds['right'][:,0],bounds['right'][:,1]],s=smoothing)
    bounds['s_bottom'],u = interpolate.splprep([bounds['bottom'][:,0],bounds['bottom'][:,1]],s=smoothing)
    bounds['s_left'],u = interpolate.splprep([bounds['left'][:,0],bounds['left'][:,1]],s=smoothing)
   
    
    return bounds 
开发者ID:Quasimondo,项目名称:RasterFairy,代码行数:31,代码来源:coonswarp.py

示例11: _rnd_interpolate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def _rnd_interpolate(xy, num_points, ordered=False):
  tck,u = splprep([
    xy[:,0],
    xy[:,1]],
    s=0
  )
  unew = random(num_points)
  if sort:
    unew = sort(unew)
  out = splev(unew, tck)
  return column_stack(out) 
开发者ID:inconvergent,项目名称:sand-spline,代码行数:13,代码来源:helpers.py

示例12: fitSpline

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def fitSpline(points):
    pts = np.array(points)
    #print("points",pts.T)
    #pts = np.delete(pts,-1)
    #print("x = ",pts.T[:][0])
    x1 = pts.T[:][0]
    y1 = pts.T[:][1]
    #print("x1 = ",x1.T)
    #print("shape x:- ",np.shape(x1))
    #print("shape y:- ",np.shape(y1))
    x1 = x1[::-1]
    y1 = y1[::-1]    
    #tck, u = splprep(pts.T, u=None, s=0.0, per=1, k=3)
    tck = splrep(x1,y1, s=1,  k=2)
    #tck,u = splprep(pts.T[:][0],pts.T[:][1], s=1, k=3)
    #tck,u = splprep(pts.T, s=0.0, k=3,per = 0)
    #u_new = np.linspace(u.min(), u.max(), 1000)
    u_new = np.arange(x1[0], x1[len(x1)-1]+1,0.1)
    #print(x1[0])
    #print(x1[len(x1)-1] +1 )
    #print(u_new)
    #u_new = np.arange(pts.T[0][0], pts.T[len[pts]-1][0],0.001)
    #x_new, y_new = splev(u_new, tck, der=0)
    y_new = splev(u_new, tck, der=0)
    #return list(zip(x_new,y_new))
    return list(zip(u_new,y_new)) 
开发者ID:realkushagrakhare,项目名称:3D_Path_Planning,代码行数:28,代码来源:rrt-star_SplineFitting_NodePruning_2PhaseSampling.py

示例13: fitSpline

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def fitSpline(points):
    pts = np.array(points)
    #print("points",pts.T)
    #pts = np.delete(pts,-1)
    #print("x = ",pts.T[:][0])
    x1 = pts.T[:][0]
    y1 = pts.T[:][1]
    #print("x1 = ",x1.T)
    #print("shape x:- ",np.shape(x1))
    #print("shape y:- ",np.shape(y1))
    x1 = x1[::-1]
    y1 = y1[::-1]    
    #tck, u = splprep(pts.T, u=None, s=0.0, per=1, k=3)
    tck = splrep(x1,y1, s=1,  k=3)
    #tck,u = splprep(pts.T[:][0],pts.T[:][1], s=1, k=3)
    #tck,u = splprep(pts.T, s=0.0, k=3,per = 0)
    #u_new = np.linspace(u.min(), u.max(), 1000)
    u_new = np.arange(x1[0], x1[len(x1)-1]+1,0.1)
    #print(x1[0])
    #print(x1[len(x1)-1] +1 )
    #print(u_new)
    #u_new = np.arange(pts.T[0][0], pts.T[len[pts]-1][0],0.001)
    #x_new, y_new = splev(u_new, tck, der=0)
    y_new = splev(u_new, tck, der=0)
    #return list(zip(x_new,y_new))
    return list(zip(u_new,y_new)) 
开发者ID:realkushagrakhare,项目名称:3D_Path_Planning,代码行数:28,代码来源:rrt-star_SplineFitting.py

示例14: fitSpline

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def fitSpline(points):
	pts = np.array(points)
	tck, u = splprep(pts.T, u=None, s=0.0, per=1)
	u_new = np.linspace(u.min(), u.max(), 1000)
	x_new, y_new = splev(u_new, tck, der=0)
	return list(zip(x_new,y_new)) 
开发者ID:realkushagrakhare,项目名称:3D_Path_Planning,代码行数:8,代码来源:SplineInterpolation-test-3.py

示例15: transfinite

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splprep [as 别名]
def transfinite(north, south, west, east):
        """Make a transfinite interpolation.
        http://en.wikipedia.org/wiki/Transfinite_interpolation
        """

        south = np.array(south)
        north = np.array(north)
        west = np.array(west)
        east = np.array(east)

        # convert the block boundary curves into parametric form
        # as curves need to be between 0 and 1
        # interpolate B-spline through data points
        # here, a linear interpolant is derived "k=1"
        # splprep returns:
        # tck ... tuple (t,c,k) containing the vector of knots,
        #         the B-spline coefficients, and the degree of the spline.
        #   u ... array of the parameters for each given point (knot)
        tck_lower, u_lower = interpolate.splprep(south.T, s=0, k=1)
        tck_upper, u_upper = interpolate.splprep(north.T, s=0, k=1)
        tck_left, u_left = interpolate.splprep(west.T, s=0, k=1)
        tck_right, u_right = interpolate.splprep(east.T, s=0, k=1)

        # evaluate function at any parameter "0<=t<=1"
        def eta_left(t):
            return np.array(interpolate.splev(t, tck_left, der=0))

        def eta_right(t):
            return np.array(interpolate.splev(t, tck_right, der=0))

        def xi_bottom(t):
            return np.array(interpolate.splev(t, tck_lower, der=0))

        def xi_top(t):
            return np.array(interpolate.splev(t, tck_upper, der=0))

        nodes = np.zeros((len(west) * len(south), 2))

        # corner points
        c1 = xi_bottom(0.0)
        c2 = xi_top(0.0)
        c3 = xi_bottom(1.0)
        c4 = xi_top(1.0)

        for i, xi in enumerate(u_lower):
            xi_t = u_upper[i]
            for j, eta in enumerate(u_left):
                eta_r = u_right[j]

                node = i * len(u_left) + j

                # formula for the transinite interpolation
                point = (1.0 - xi) * eta_left(eta) + xi * eta_right(eta_r) + \
                    (1.0 - eta) * xi_bottom(xi) + eta * xi_top(xi_t) - \
                    ((1.0 - xi) * (1.0 - eta) * c1 + (1.0 - xi) * eta * c2 +
                     xi * (1.0 - eta) * c3 + xi * eta * c4)

                nodes[node, 0] = point[0]
                nodes[node, 1] = point[1]

        return nodes 
开发者ID:chiefenne,项目名称:PyAero,代码行数:63,代码来源:Orthogonal.py


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