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


Python BPoly.from_derivatives方法代码示例

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


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

示例1: _create_from_control_points

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def _create_from_control_points(self, control_points, tangents, scale):
        """
        Creates the FiberSource instance from control points, and a specified 
        mode to compute the tangents.

        Parameters
        ----------
        control_points : ndarray shape (N, 3)
        tangents : 'incoming', 'outgoing', 'symmetric'
        scale : multiplication factor. 
            This is useful when the coodinates are given dimensionless, and we 
            want a specific size for the phantom.
        """
        # Compute instant points ts, from 0. to 1. 
        # (time interval proportional to distance between control points)
        nb_points = control_points.shape[0]
        dists = np.zeros(nb_points)
        dists[1:] = np.sqrt((np.diff(control_points, axis=0) ** 2).sum(1))
        ts = dists.cumsum()
        length = ts[-1]
        ts = ts / np.max(ts)

        # Create interpolation functions (piecewise polynomials) for x, y and z
        derivatives = np.zeros((nb_points, 3))

        # The derivatives at starting and ending points are normal
        # to the surface of a sphere.
        derivatives[0, :] = -control_points[0]
        derivatives[-1, :] = control_points[-1]
 
        # As for other derivatives, we use discrete approx
        if tangents == 'incoming':
            derivatives[1:-1, :] = (control_points[1:-1] - control_points[:-2])
        elif tangents == 'outgoing':
            derivatives[1:-1, :] = (control_points[2:] - control_points[1:-1])
        elif tangents == 'symmetric':
            derivatives[1:-1, :] = (control_points[2:] - control_points[:-2])
        else:
            raise Error('tangents should be one of the following: incoming, ' 
                        'outgoing, symmetric')
 
        derivatives = (derivatives.T / np.sqrt((derivatives ** 2).sum(1))).T \
                    * length
               
        self.x_poly = BPoly.from_derivatives(ts, 
               scale * np.vstack((control_points[:, 0], derivatives[:, 0])).T)
        self.y_poly = BPoly.from_derivatives(ts, 
               scale * np.vstack((control_points[:, 1], derivatives[:, 1])).T)
        self.z_poly = BPoly.from_derivatives(ts, 
               scale * np.vstack((control_points[:, 2], derivatives[:, 2])).T)
开发者ID:ecaruyer,项目名称:phantomas,代码行数:52,代码来源:fiber.py

示例2: test_orders_too_high

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def test_orders_too_high(self):
        m, k = 5, 12
        xi, yi = self._make_random_mk(m, k)

        pp = BPoly.from_derivatives(xi, yi, orders=2*k-1)   # this is still ok
        assert_raises(ValueError, BPoly.from_derivatives,   # but this is not
                **dict(xi=xi, yi=yi, orders=2*k))
开发者ID:AGPeddle,项目名称:scipy,代码行数:9,代码来源:test_interpolate.py

示例3: test_random_12

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def test_random_12(self):
        m, k = 5, 12
        xi, yi = self._make_random_mk(m, k)
        pp = BPoly.from_derivatives(xi, yi)

        for order in range(k//2):
            assert_allclose(pp(xi), [yy[order]  for yy in yi])
            pp = pp.derivative()
开发者ID:AGPeddle,项目名称:scipy,代码行数:10,代码来源:test_interpolate.py

示例4: test_zeros

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def test_zeros(self):
        xi = [0, 1, 2, 3]
        yi = [[0, 0], [0], [0, 0], [0, 0]]  # NB: will have to raise the degree
        pp = BPoly.from_derivatives(xi, yi)
        assert_(pp.c.shape == (4, 3))

        ppd = pp.derivative()
        for xp in [0., 0.1, 1., 1.1, 1.9, 2., 2.5]:
            assert_allclose([pp(xp), ppd(xp)], [0., 0.])
开发者ID:AGPeddle,项目名称:scipy,代码行数:11,代码来源:test_interpolate.py

示例5: fonction

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def fonction(self):
        """Fonction wrapper vers la fonction de scipy BPoly.from_derivatives

        """
        pts = self.points_tries
        xl = [P.x for P in pts]
        yl = [P.y for P in pts]
        yl_cum = list(zip(yl, self._derivees()))
        return BPoly.from_derivatives(xl, yl_cum)
开发者ID:wxgeo,项目名称:geophar,代码行数:11,代码来源:interpolations.py

示例6: test_orders_local

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def test_orders_local(self):
        m, k = 7, 12
        xi, yi = self._make_random_mk(m, k)

        orders = [o + 1 for o in range(m)]
        for i, x in enumerate(xi[1:-1]):
            pp = BPoly.from_derivatives(xi, yi, orders=orders)
            for j in range(orders[i] // 2 + 1):
                assert_allclose(pp(x - 1e-12), pp(x + 1e-12))
                pp = pp.derivative()
            assert_(not np.allclose(pp(x - 1e-12), pp(x + 1e-12)))
开发者ID:AGPeddle,项目名称:scipy,代码行数:13,代码来源:test_interpolate.py

示例7: test_orders_global

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
    def test_orders_global(self):
        m, k = 5, 12
        xi, yi = self._make_random_mk(m, k)

        # ok, this is confusing. Local polynomials will be of the order 5
        # which means that up to the 2nd derivatives will be used at each point
        order = 5
        pp = BPoly.from_derivatives(xi, yi, orders=order)

        for j in range(order//2+1):
            assert_allclose(pp(xi[1:-1] - 1e-12), pp(xi[1:-1] + 1e-12))
            pp = pp.derivative()
        assert_(not np.allclose(pp(xi[1:-1] - 1e-12), pp(xi[1:-1] + 1e-12)))

        # now repeat with `order` being even: on each interval, it uses
        # order//2 'derivatives' @ the right-hand endpoint and
        # order//2+1 @ 'derivatives' the left-hand endpoint
        order = 6
        pp = BPoly.from_derivatives(xi, yi, orders=order)
        for j in range(order//2):
            assert_allclose(pp(xi[1:-1] - 1e-12), pp(xi[1:-1] + 1e-12))
            pp = pp.derivative()
        assert_(not np.allclose(pp(xi[1:-1] - 1e-12), pp(xi[1:-1] + 1e-12)))
开发者ID:AGPeddle,项目名称:scipy,代码行数:25,代码来源:test_interpolate.py

示例8: test_yi_trailing_dims

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
 def test_yi_trailing_dims(self):
     m, k = 7, 5
     xi = np.sort(np.random.random(m+1))
     yi = np.random.random((m+1, k, 6, 7, 8))
     pp = BPoly.from_derivatives(xi, yi)
     assert_equal(pp.c.shape, (2*k, m, 6, 7, 8))
开发者ID:AGPeddle,项目名称:scipy,代码行数:8,代码来源:test_interpolate.py

示例9: __init__

# 需要导入模块: from scipy.interpolate import BPoly [as 别名]
# 或者: from scipy.interpolate.BPoly import from_derivatives [as 别名]
 def __init__(self, x, y, yp=None, method='secant'):
     if yp is None:
         yp = slopes(x, y, method=method, monotone=True)
     yyp = [z for z in zip(y, yp)]
     bpoly = BPoly.from_derivatives(x, yyp, orders=3)
     super(Pchip, self).__init__(bpoly.c, x)
开发者ID:wafo-project,项目名称:pywafo,代码行数:8,代码来源:interpolate.py


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