示例#1
0
    def init_1dcubic_c2(self, x=None, data=None, extrapolate=False, extrapolation_range=float('inf'),
                        extrapolation_type='nearest', tolerate_single_value=False):
        """Create the interpolating function and reference function."""

        if x is None:
            x = self.x

        if data is None:
            data = self.data

        # reference interpolated data:

        # C2 cubic interpolated data sampled on self.xsamples,
        # calculated from solving manually the linear system given by the
        # following constraints on the cubic splines:
        #
        # if P1, P2, ..., P9 are the 9 cubic polynomials defining the interpolation
        # on respectively ranges [x[0], x[1]], [x[1], x[2]], ..., [x[8], x[9]]
        # constraints are: Pi(x[i-1]) = data[i-1]            for i in [1, 9]
        #                  Pi(x[i]) = data[i]                for i in [1, 9]
        #                  dPi/dx(x[i]) = dPi+1/dx(x[i])     for i in [1, 8]
        #                  d2Pi/dx2(x[i]) = d2Pi+1/dx2(x[i]) for i in [1, 8]
        #                  d3P1/dx3(x[0]) = d3P9/dx3(x[9]) = 0
        self.interp_data = np.array([ 1.            ,  0.909386322736,  0.744935119692,  0.506646390868,  0.198359265243,
                                     -0.145597952285, -0.476357515   , -0.745969855864, -0.924576033965, -0.997965016288,
                                     -0.95270426186 , -0.791113531095, -0.539928651551, -0.227988632848,  0.113003806643,
                                      0.443108473075,  0.720913065294,  0.908991353712,  0.992221981868,  0.963237748147,
                                      0.816761597858,  0.571723930259,  0.262672856832, -0.075536667115, -0.406637953849,
                                     -0.692732204577, -0.895899188014, -0.989500940501, -0.970558387522, -0.839071529076],
                                    dtype=np.float64)

        # nearestly extrapolated data sampled on self.xsamples_extrapol,
        # calculated from nearest edge value
        self.extrap_data_nea = np.array([1., 1., -0.839071529076, -0.839071529076], dtype=np.float64)

        # linearly extrapolated data sampled on self.xsamples_extrapol,
        # calculated from P(x_nearest) + (x-x_nearest)*dP/dx(x_nearest)
        # where x_nearest (=x[0] or x[9]) is the nearest coordinate in the
        # interpolated range form x, and P (=P1 or P9) the nearest
        # interpolation polynomial.
        self.extrap_data_lin = np.array([1.1245722013484143, 1.0622861006742075, -0.62127107611011623, -0.40347062314376919], dtype=np.float64)

        # quadraticaly extrapolated data sampled on self.xsamples_extrapol,
        # calculated from P(x_nearest) + (x-x_nearest)*dP/dx(x_nearest)
        # + 0.5*(x-x_nearest)**2*d2P/dx2(x_nearest)
        # where x_nearest (=x[0] or x[9]) is the nearest coordinate in the
        # interpolated range form x, and P (=P1 or P9) the nearest
        # interpolation polynomial.
        self.extrap_data_qua = np.array([0.92586065196970724, 1.0126082133295307, -0.5455512673927978, -0.10059138827449526], dtype=np.float64)

        self.interp_func = interpolators1d.Interpolate1DCubic(x, data,
                                                               extrapolate=extrapolate,
                                                               extrapolation_range=extrapolation_range,
                                                               extrapolation_type=extrapolation_type,
                                                               tolerate_single_value=tolerate_single_value,
                                                               continuity_order=2)
示例#2
0
    def init_1dcubic_c1(self, x=None, data=None, extrapolate=False, extrapolation_range=float('inf'),
                        extrapolation_type='nearest', tolerate_single_value=False):
        """Create the interpolating function and reference function."""

        if x is None:
            x = self.x

        if data is None:
            data = self.data

        # reference interpolated data:

        # C1 cubic interpolated data sampled on self.xsamples,
        # calculated from from solving manually the linear system given by the
        # following constraints on the cubic splines:
        #
        # if P1, P2, ..., P9 are the 9 cubic polynomials defining the interpolation
        # on respectively ranges [x[0], x[1]], [x[1], x[2]], ..., [x[8], x[9]]
        # constraints are: Pi(x[i-1]) = data[i-1]            for i in [1, 9]
        #                  Pi(x[i]) = data[i]                for i in [1, 9]
        #                  dPi/dx(x[i]) = (data[i+1]-data[i-1])/(x[i+1]-x[i-1])     for i in [1, 8]
        #                  dPi/dx(x[i-1]) = (data[i]-data[i-2])/(x[i]-x[i-2])       for i in [2, 9]
        #                  d3P1/dx3(x[0]) = d3P9/dx3(x[9]) = 0
        self.interp_data = np.array([ 1.            ,  0.880173125546,  0.712800602783,  0.497882431711,  0.209599324944,
                                     -0.154300121054, -0.492023725037, -0.724305080592, -0.896927467157, -0.986541391474,
                                     -0.954335254748, -0.777457953678, -0.513924204518, -0.234128226514,  0.094607534444,
                                      0.447977457129,  0.725059163866,  0.885104972562,  0.967692230729,  0.955569808692,
                                      0.819830442329,  0.554735584499,  0.240589044126, -0.05646951848 , -0.390685969507,
                                     -0.698474405891, -0.889098560187, -0.964565305133, -0.947889628097, -0.839071529076],
                                    dtype=np.float64)

        # nearestly extrapolated data sampled on self.xsamples_extrapol,
        # calculated from nearest edge value
        self.extrap_data_nea = np.array([1., 1., -0.839071529076, -0.839071529076], dtype=np.float64)

        # linearly extrapolated data sampled on self.xsamples_extrapol,
        # calculated from P(x_nearest) + (x-x_nearest)*dP/dx(x_nearest)
        # where x_nearest (=x[0] or x[9]) is the nearest coordinate in the
        # interpolated range form x, and P (=P1 or P9) the nearest
        # interpolation polynomial.
        self.extrap_data_lin = np.array([ 1.222845396694,  1.111422698347, -0.659399929463, -0.479728329849], dtype=np.float64)

        # quadraticaly extrapolated data sampled on self.xsamples_extrapol,
        # calculated from P(x_nearest) + (x-x_nearest)*dP/dx(x_nearest)
        # + 0.5*(x-x_nearest)**2*d2P/dx2(x_nearest)
        # where x_nearest (=x[0] or x[9]) is the nearest coordinate in the
        # interpolated range form x, and P (=P1 or P9) the nearest
        # interpolation polynomial.
        self.extrap_data_qua = np.array([ 1.094890547964,  1.079433986165, -0.597406507952, -0.231754643808], dtype=np.float64)

        self.interp_func = interpolators1d.Interpolate1DCubic(x, data,
                                                               extrapolate=extrapolate,
                                                               extrapolation_range=extrapolation_range,
                                                               extrapolation_type=extrapolation_type,
                                                               tolerate_single_value=tolerate_single_value,
                                                               continuity_order=1)