Exemplo n.º 1
0
 def fromspline(cls, xk, cvals, order, fill=0.0):
     N = len(xk)-1
     sivals = np.empty((order+1,N), dtype=float)
     for m in xrange(order,-1,-1):
         fact = spec.gamma(m+1)
         res = _fitpack._bspleval(xk[:-1], xk, cvals, order, m)
         res /= fact
         sivals[order-m,:] = res
     return cls(sivals, xk, fill=fill)
Exemplo n.º 2
0
    region is xj[0] to xj[-1].  If N+1 is the length of xj, then cvals should
    have length N+k where k is the order of the spline.

    Internally, an additional k-1 knot points are added on either side of
    the spline.

    If cvals represents more than one curve (cvals.ndim > 1) and/or xnew is
    N-d, then the result is xnew.shape + cvals.shape[1:] providing the
    interpolation of multiple curves.
    """
    oldshape = np.shape(xnew)
    xx = np.ravel(xnew)
    sh = cvals.shape[1:]
    res = np.empty(xx.shape + sh)
    for index in np.ndindex(*sh):
        sl = (slice(None),)+index
        res[sl] = _fitpack._bspleval(xx,xj,cvals[sl],k,deriv)
    res.shape = oldshape + sh
    return res
                    
def spltopp(xk,cvals,k):
    """Return a piece-wise polynomial object from a fixed-spline tuple.
    """
    return ppform.fromspline(xk, cvals, k)

def spline(xk,yk,xnew,order=3,kind='smoothest',conds=None):
    """Interpolate a curve (xk,yk) at points xnew using a spline fit.
    """
    return spleval(splmake(xk,yk,order=order,kind=kind,conds=conds),xnew)

Exemplo n.º 3
0
    Internally, an additional k-1 knot points are added on either side of
    the spline.

    If cvals represents more than one curve (cvals.ndim > 1) and/or xnew is
    N-d, then the result is xnew.shape + cvals.shape[1:] providing the
    interpolation of multiple curves.
    """
    oldshape = np.shape(xnew)
    xx = np.ravel(xnew)
    sh = cvals.shape[1:]
    res = np.empty(xx.shape + sh, dtype=cvals.dtype)
    for index in np.ndindex(*sh):
        sl = (slice(None),)+index
        if issubclass(cvals.dtype.type, np.complexfloating):
            res[sl].real = _fitpack._bspleval(xx,xj,cvals.real[sl],k,deriv)
            res[sl].imag = _fitpack._bspleval(xx,xj,cvals.imag[sl],k,deriv)
        else:
            res[sl] = _fitpack._bspleval(xx,xj,cvals[sl],k,deriv)
    res.shape = oldshape + sh
    return res

def spltopp(xk,cvals,k):
    """Return a piece-wise polynomial object from a fixed-spline tuple.
    """
    return ppform.fromspline(xk, cvals, k)

def spline(xk,yk,xnew,order=3,kind='smoothest',conds=None):
    """Interpolate a curve (xk,yk) at points xnew using a spline fit.
    """
    return spleval(splmake(xk,yk,order=order,kind=kind,conds=conds),xnew)