示例#1
0
文件: akima.py 项目: Haider-BA/akima
def akima_interp(xpt, ypt, x):
    """convenience method for those who don't want derivatives
    and don't want to evaluate the same spline multiple times"""

    p0, p1, p2, p3 = _akima.setup(xpt, ypt, delta_x=0.0)

    npt = len(xpt)
    zeros = np.zeros((npt-1, npt))

    y, dydx, dydxpt, dydypt = _akima.interp(x, xpt, p0, p1, p2, p3,
        zeros, zeros, zeros, zeros, zeros, zeros, zeros, zeros)

    return y
示例#2
0
文件: akima.py 项目: WISDEM/akima
    def interp(self, x):
        """interpolate at new values

        Parameters
        ----------
        x : array_like
            x values to sample spline at

        Returns
        -------
        y : nd_array
            interpolated values y = fspline(x)
        dydx : nd_array
            the derivative of y w.r.t. x at each point
        dydxpt : 2D nd_array (only returned if delta_x != 0.0)
            dydxpt[i, j] the derivative of y[i] w.r.t. xpt[j]
        dydypt : 2D nd_array (only returned if delta_x != 0.0)
            dydypt[i, j] the derivative of y[i] w.r.t. ypt[j]

        """

        x = np.asarray(x)

        try:
            len(x)
            isFloat = False
        except TypeError:  # if x is just a float
            x = np.array([x])
            isFloat = True

        if x.size == 0:  # error check for empty array
            y = np.array([])
            dydx = np.array([])
            dydxpt = np.array([])
            dydypt = np.array([])
        else:
            y, dydx, dydxpt, dydypt = _akima.interp(
                x, self.xpt, self.p0, self.p1, self.p2, self.p3, self.dp0_dxpt,
                self.dp1_dxpt, self.dp2_dxpt, self.dp3_dxpt, self.dp0_dypt,
                self.dp1_dypt, self.dp2_dypt, self.dp3_dypt)

        if isFloat:
            y = y[0]
            dydx = dydx[0]
            dydxpt = dydxpt[0, :]
            dydypt = dydypt[0, :]

        if self.delta_x == 0.0:
            return y, dydx
        else:
            return y, dydx, dydxpt, dydypt
示例#3
0
文件: akima.py 项目: Haider-BA/akima
    def interp(self, x):
        """interpolate at new values

        Parameters
        ----------
        x : array_like
            x values to sample spline at

        Returns
        -------
        y : nd_array
            interpolated values y = fspline(x)
        dydx : nd_array
            the derivative of y w.r.t. x at each point
        dydxpt : 2D nd_array (only returned if delta_x != 0.0)
            dydxpt[i, j] the derivative of y[i] w.r.t. xpt[j]
        dydypt : 2D nd_array (only returned if delta_x != 0.0)
            dydypt[i, j] the derivative of y[i] w.r.t. ypt[j]

        """

        x = np.asarray(x)

        try:
            len(x)
            isFloat = False
        except TypeError:  # if x is just a float
            x = np.array([x])
            isFloat = True

        if x.size == 0:  # error check for empty array
            y = np.array([])
            dydx = np.array([])
            dydxpt = np.array([])
            dydypt = np.array([])
        else:
            y, dydx, dydxpt, dydypt = _akima.interp(x,
                self.xpt, self.p0, self.p1, self.p2, self.p3,
                self.dp0_dxpt, self.dp1_dxpt, self.dp2_dxpt, self.dp3_dxpt,
                self.dp0_dypt, self.dp1_dypt, self.dp2_dypt, self.dp3_dypt)

        if isFloat:
            y = y[0]
            dydx = dydx[0]
            dydxpt = dydxpt[0, :]
            dydypt = dydypt[0, :]

        if self.delta_x == 0.0:
            return y, dydx
        else:
            return y, dydx, dydxpt, dydypt
示例#4
0
文件: akima.py 项目: WISDEM/akima
def akima_interp(xpt, ypt, x):
    """convenience method for those who don't want derivatives
    and don't want to evaluate the same spline multiple times"""

    p0, p1, p2, p3 = _akima.setup(xpt, ypt, delta_x=0.0)

    npt = len(xpt)
    zeros = np.zeros((npt - 1, npt))

    y, dydx, dydxpt, dydypt = _akima.interp(x, xpt, p0, p1, p2, p3, zeros,
                                            zeros, zeros, zeros, zeros, zeros,
                                            zeros, zeros)

    return y