Esempio n. 1
0
def splev(x,tck,der=0):
    """
    Evaluate a B-spline and its derivatives.

    Given the knots and coefficients of a B-spline representation, evaluate
    the value of the smoothing polynomial and it's derivatives.
    This is a wrapper around the FORTRAN routines splev and splder of FITPACK.

    Parameters
    ----------
    x (u) -- a 1-D array of points at which to return the value of the
             smoothed spline or its derivatives.  If tck was returned from
             splprep, then the parameter values, u should be given.
    tck -- A sequence of length 3 returned by splrep or splprep containg the
           knots, coefficients, and degree of the spline.
    der -- The order of derivative of the spline to compute (must be less than
           or equal to k).

    Returns
    -------
    y -- an array of values representing the spline function or curve.
         If tck was returned from splrep, then this is a list of arrays
         representing the curve in N-dimensional space.

    See Also
    --------
    splprep, splrep, sproot, spalde, splint : evaluation, roots, integral
    bisplrep, bisplev : bivariate splines
    UnivariateSpline, BivariateSpline :
        An alternative wrapping of the FITPACK functions.

    References
    ----------
    .. [1] C. de Boor, "On calculating with b-splines", J. Approximation
        Theory, 6, p.50-62, 1972.
    .. [2] M.G. Cox, "The numerical evaluation of b-splines", J. Inst. Maths
        Applics, 10, p.134-149, 1972.
    .. [3] P. Dierckx, "Curve and surface fitting with splines", Monographs
        on Numerical Analysis, Oxford University Press, 1993.

    """
    t,c,k=tck
    try:
        c[0][0]
        parametric = True
    except:
        parametric = False
    if parametric:
        return map(lambda c,x=x,t=t,k=k,der=der:splev(x,[t,c,k],der),c)
    else:
        if not (0<=der<=k):
            raise ValueError,"0<=der=%d<=k=%d must hold"%(der,k)
        x=myasarray(x)
        y,ier=_fitpack._spl_(x,der,t,c,k)
        if ier==10: raise ValueError,"Invalid input data"
        if ier: raise TypeError,"An error occurred"
        if len(y)>1: return y
        return y[0]
Esempio n. 2
0
def splev(x,tck,der=0):
    """Evaulate a B-spline and its derivatives.

    Description:

      Given the knots and coefficients of a B-spline representation, evaluate
      the value of the smoothing polynomial and it's derivatives.
      This is a wrapper around the FORTRAN routines splev and splder of FITPACK.

    Inputs:

      x (u) -- a 1-D array of points at which to return the value of the
               smoothed spline or its derivatives.  If tck was returned from
               splprep, then the parameter values, u should be given.
      tck -- A sequence of length 3 returned by splrep or splprep containg the
             knots, coefficients, and degree of the spline.
      der -- The order of derivative of the spline to compute (must be less than
             or equal to k).

    Outputs: (y, )

      y -- an array of values representing the spline function or curve.
           If tck was returned from splrep, then this is a list of arrays
           representing the curve in N-dimensional space.

    See also:
      splprep, splrep, sproot, spalde, splint - evaluation, roots, integral
      bisplrep, bisplev - bivariate splines
      UnivariateSpline, BivariateSpline - an alternative wrapping 
              of the FITPACK functions
    """
    t,c,k=tck
    try:
        c[0][0]
        parametric = True
    except:
        parametric = False
    if parametric:
        return map(lambda c,x=x,t=t,k=k,der=der:splev(x,[t,c,k],der),c)
    else:
      if not (0<=der<=k):
          raise ValueError,"0<=der=%d<=k=%d must hold"%(der,k)
      x=myasarray(x)
      y,ier=_fitpack._spl_(x,der,t,c,k)
      if ier==10: raise ValueError,"Invalid input data"
      if ier: raise TypeError,"An error occurred"
      if len(y)>1: return y
      return y[0]
Esempio n. 3
0
def splev(x, tck, der=0, ext=0):
    """
    Evaluate a B-spline or its derivatives.

    Given the knots and coefficients of a B-spline representation, evaluate
    the value of the smoothing polynomial and its derivatives.  This is a
    wrapper around the FORTRAN routines splev and splder of FITPACK.

    Parameters
    ----------
    x : array_like
        A 1-D array of points at which to return the value of the smoothed
        spline or its derivatives.  If `tck` was returned from `splprep`,
        then the parameter values, u should be given.
    tck : tuple
        A sequence of length 3 returned by `splrep` or `splprep` containing
        the knots, coefficients, and degree of the spline.
    der : int
        The order of derivative of the spline to compute (must be less than
        or equal to k).
    ext : int
        Controls the value returned for elements of ``x`` not in the
        interval defined by the knot sequence.

        * if ext=0, return the extrapolated value.
        * if ext=1, return 0
        * if ext=2, raise a ValueError

        The default value is 0.

    Returns
    -------
    y : ndarray or list of ndarrays
        An array of values representing the spline function evaluated at
        the points in ``x``.  If `tck` was returned from splrep, then this
        is a list of arrays representing the curve in N-dimensional space.

    See Also
    --------
    splprep, splrep, sproot, spalde, splint
    bisplrep, bisplev

    References
    ----------
    .. [1] C. de Boor, "On calculating with b-splines", J. Approximation
        Theory, 6, p.50-62, 1972.
    .. [2] M.G. Cox, "The numerical evaluation of b-splines", J. Inst. Maths
        Applics, 10, p.134-149, 1972.
    .. [3] P. Dierckx, "Curve and surface fitting with splines", Monographs
        on Numerical Analysis, Oxford University Press, 1993.

    """
    t,c,k = tck
    try:
        c[0][0]
        parametric = True
    except:
        parametric = False
    if parametric:
        return map(lambda c, x=x, t=t, k=k, der=der : splev(x, [t,c,k], der), c)
    else:
        if not (0 <= der <= k):
            raise ValueError("0<=der=%d<=k=%d must hold"%(der,k))
        if not ext in (0,1,2):
            raise ValueError("ext not in (0, 1, 2)")

        x = myasarray(x)
        y, ier =_fitpack._spl_(x, der, t, c, k, ext)
        if ier == 10:
            raise ValueError("Invalid input data")
        if ier == 1:
            raise ValueError("Found x value not in the domain")
        if ier:
            raise TypeError("An error occurred")
        if len(y) > 1:
            return y
        return y[0]
Esempio n. 4
0
def splev(x, tck, der=0, ext=0):
    """
    Evaluate a B-spline or its derivatives.

    Given the knots and coefficients of a B-spline representation, evaluate
    the value of the smoothing polynomial and its derivatives.  This is a
    wrapper around the FORTRAN routines splev and splder of FITPACK.

    Parameters
    ----------
    x : array_like
        A 1-D array of points at which to return the value of the smoothed
        spline or its derivatives.  If `tck` was returned from `splprep`,
        then the parameter values, u should be given.
    tck : tuple
        A sequence of length 3 returned by `splrep` or `splprep` containing
        the knots, coefficients, and degree of the spline.
    der : int
        The order of derivative of the spline to compute (must be less than
        or equal to k).
    ext : int
        Controls the value returned for elements of ``x`` not in the
        interval defined by the knot sequence.

        * if ext=0, return the extrapolated value.
        * if ext=1, return 0
        * if ext=2, raise a ValueError

        The default value is 0.

    Returns
    -------
    y : ndarray or list of ndarrays
        An array of values representing the spline function evaluated at
        the points in ``x``.  If `tck` was returned from splrep, then this
        is a list of arrays representing the curve in N-dimensional space.

    See Also
    --------
    splprep, splrep, sproot, spalde, splint
    bisplrep, bisplev

    References
    ----------
    .. [1] C. de Boor, "On calculating with b-splines", J. Approximation
        Theory, 6, p.50-62, 1972.
    .. [2] M.G. Cox, "The numerical evaluation of b-splines", J. Inst. Maths
        Applics, 10, p.134-149, 1972.
    .. [3] P. Dierckx, "Curve and surface fitting with splines", Monographs
        on Numerical Analysis, Oxford University Press, 1993.

    """
    t, c, k = tck
    try:
        c[0][0]
        parametric = True
    except:
        parametric = False
    if parametric:
        return map(
            lambda c, x=x, t=t, k=k, der=der: splev(x, [t, c, k], der, ext), c)
    else:
        if not (0 <= der <= k):
            raise ValueError("0<=der=%d<=k=%d must hold" % (der, k))
        if not ext in (0, 1, 2):
            raise ValueError("ext not in (0, 1, 2)")

        x = asarray(x)
        shape = x.shape
        x = atleast_1d(x)
        y, ier = _fitpack._spl_(x, der, t, c, k, ext)

        if ier == 10:
            raise ValueError("Invalid input data")
        if ier == 1:
            raise ValueError("Found x value not in the domain")
        if ier:
            raise TypeError("An error occurred")

        return y.reshape(shape)