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


Python interpolate.splrep方法代码示例

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


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

示例1: splrep

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def splrep(coordinates, t, order, weights, smoothing, periodic):
        from scipy import interpolate
        (x,y) = coordinates
        # we need to skip anything where t[i] and t[i+1] are too close
        wh = np.where(np.isclose(np.diff(t), 0))[0]
        if len(wh) > 0:
            (t,x,y) = [np.array(u) for u in (t,x,y)]
            ii = np.arange(len(t))
            for i in reversed(wh):
                ii[i+1:-1] = ii[i+2:]
                for u in (t,x,y):
                    u[i] = np.mean(u[i:i+2])
            ii = ii[:-len(wh)]
            (t,x,y) = [u[ii] for u in (t,x,y)]
        xtck = interpolate.splrep(t, x, k=order, s=smoothing, w=weights, per=periodic)
        ytck = interpolate.splrep(t, y, k=order, s=smoothing, w=weights, per=periodic)
        return tuple([tuple([pimms.imm_array(u) for u in tck])
                      for tck in (xtck,ytck)]) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:20,代码来源:core.py

示例2: curve_length

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def curve_length(self, start=None, end=None, precision=0.01):
        '''
        Calculates the length of the curve by dividing the curve up
        into pieces of parameterized-length <precision>.
        '''
        if start is None: start = self.t[0]
        if end is None: end = self.t[-1]
        from scipy import interpolate
        if self.order == 1:
            # we just want to add up along the steps...
            ii = [ii for (ii,t) in enumerate(self.t) if start < t and t < end]
            ts = np.concatenate([[start], self.t[ii], [end]])
            xy = np.vstack([[self(start)], self.coordinates[:,ii].T, [self(end)]])
            return np.sum(np.sqrt(np.sum((xy[1:] - xy[:-1])**2, axis=1)))
        else:
            t = np.linspace(start, end, int(np.ceil((end-start)/precision)))
            dt = t[1] - t[0]
            dx = interpolate.splev(t, self.splrep[0], der=1)
            dy = interpolate.splev(t, self.splrep[1], der=1)
            return np.sum(np.sqrt(dx**2 + dy**2)) * dt 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:22,代码来源:core.py

示例3: residual

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def residual(pars, spforcorr, sptarget=None):
        # unpack parameters:
        #  extract .value attribute for each parameter
        xs = pars['xshift'].value
        yx = pars['yshift'].value
        yx2 = pars['yshiftcarr'].value
        spcorr = np.zeros((shape(spforcorr)))
    
        # we need to resample the spectra to compare them
        tck = interpolate.splrep(spforcorr[:,0]-xs,spforcorr[:,1]*yx+spforcorr[:,1]**2*yx2,s=0)
        spcorr[:,0] = spforcorr[:,0]    
        spcorr[:,1] = interpolate.splev(spforcorr[:,0],tck,der=0)
        
        if sptarget is None: #in such case we return the corrected spectrum
            return spcorr
        return (spcorr[:,1] - sptarget[:,1])
    ###########################################################################        
        
    # Now we choose the portion of spectra to fit 
开发者ID:charlesll,项目名称:rampy,代码行数:21,代码来源:Remove_Ctx_MI.py

示例4: residual

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def residual(pars, spforcorr, sptarget=None):
            # unpack parameters:
            #  extract .value attribute for each parameter
            xs = pars['xshift'].value
            yx = pars['yshift'].value
            yx2 = pars['yshiftcarr'].value
            spcorr = np.zeros((shape(spforcorr)))
        
            # we need to resample the spectra to compare them
            tck = interpolate.splrep(spforcorr[:,0]-xs,spforcorr[:,1]*yx+spforcorr[:,1]**2*yx2,s=0)
            spcorr[:,0] = spforcorr[:,0]    
            spcorr[:,1] = interpolate.splev(spcorr[:,0],tck,der=0)
            
            if sptarget is None: #in such case we return the corrected spectrum
                return spcorr
            return (spcorr[:,1] - sptarget[:,1])
        #######################################################################        
        
        # Now we choose the portion of spectra to fit 
开发者ID:charlesll,项目名称:rampy,代码行数:21,代码来源:HF_Treatment_Auto.py

示例5: test_Taitel_Dukler_splines

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def test_Taitel_Dukler_splines():
    from scipy.interpolate import splrep, splev
    import numpy as np
    from fluids.two_phase import Dukler_XA_tck, Dukler_XC_tck, Dukler_XD_tck
    Dukler_XA_tck2 = splrep(np.log10(Dukler_XA_Xs), np.log10(Dukler_XA_As), s=5e-3, k=3)
    [assert_close(i, j) for i, j in zip(Dukler_XA_tck, Dukler_XA_tck2)]
#     XA_interp = UnivariateSpline(np.log10(Dukler_XA_Xs), np.log10(Dukler_XA_As), s=5e-3, k=3) # , ext='const'
#    XA_interp_obj = lambda x: 10**float(splev(log10(x), Dukler_XA_tck))
    
    Dukler_XD_tck2 = splrep(np.log10(Dukler_XD_Xs), np.log10(Dukler_XD_Ds), s=1e-2, k=3)
    [assert_close(i, j) for i, j in zip(Dukler_XD_tck, Dukler_XD_tck)]
#     XD_interp = UnivariateSpline(np.log10(Dukler_XD_Xs), np.log10(Dukler_XD_Ds), s=1e-2, k=3) # , ext='const'
#    XD_interp_obj = lambda x: 10**float(splev(log10(x), Dukler_XD_tck))
    
    Dukler_XC_tck2 = splrep(np.log10(Dukler_XC_Xs), np.log10(Dukler_XC_Cs), s=1e-3, k=3)
    [assert_close(i, j) for i, j in zip(Dukler_XC_tck, Dukler_XC_tck2)]
#     XC_interp = UnivariateSpline(np.log10(Dukler_XC_Xs), np.log10(Dukler_XC_Cs), s=1e-3, k=3) # ext='const'
#    XC_interp_obj = lambda x: 10**float(splev(log10(x), Dukler_XC_tck))
    
    # Curves look great to 1E-4! Also to 1E4. 
开发者ID:CalebBell,项目名称:fluids,代码行数:22,代码来源:test_two_phase.py

示例6: pla

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def pla(data, period=15):
    N = int(len(data)/period)
    orig_x = range(0,len(data))
    tck = splrep(orig_x, data,s=0)
    test_xs = np.linspace(0,len(data),N)
    spline_ys = splev(test_xs, tck)
    spline_yps = splev(test_xs, tck, der=1)
    xi = np.unique(tck[0])
    yi = [[splev(x, tck, der=j) for j in xrange(3)] for x in xi]
    P = interpolate.PiecewisePolynomial(xi,yi,orders=1)
    test_ys = P(test_xs)
    #inter_y = interp0(test_xs, test_ys, orig_x)
    inter_y = interp1(test_xs, test_ys, orig_x)
    
    mae = sqrt(mean_absolute_error(inter_y, data))
    #       mae = np.var(inter_y-data)
    return mae

#def paa(data, period=15): 
开发者ID:plastering,项目名称:plastering,代码行数:21,代码来源:feature_extractor.py

示例7: interpolate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def interpolate(x, x_arr, y_arr, type='interp', order=3, left=None,
                right=None):
    """Perform interpolation on value x using arrays x_arr
       and y_arr.  The type of interpolate is defined by interp

       type:
       interp--use numpy.interp
       spline--use scipy.splrep and splev

       return
    """
    if type == 'interp':
        y = np.interp(x, x_arr, y_arr, left=left, right=right)
    if type == 'spline':
        if left is None:
            y_arr[0] = left
        if right is None:
            y_arr[-1] = right

        tk = scint.splrep(x_arr, y_arr, k=order)
        y = scint.splev(x, tk, der=0)

    return y 
开发者ID:crawfordsm,项目名称:specidentify,代码行数:25,代码来源:spectools.py

示例8: fit

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def fit(self, task=0, s=None, t=None, full_output=1, warn=False):
        """Fit the function to the data"""
        if self.function == 'spline':
            self.set_weight(self.yerr)
            self.results = interpolate.splrep(self.x, self.y, w=self.weight,
                                              task=0, s=None, t=None,
                                              k=self.order,
                                              full_output=full_output)
            # w=None, k=self.order, s=s, t=t, task=task,
            # full_output=full_output)
            self.set_coef(self.results[0])

        else:
            self.results = optimize.leastsq(self.erf, self.coef,
                                            args=(self.x, self.y, self.yerr),
                                            full_output=full_output)
            self.set_coef(self.results[0]) 
开发者ID:crawfordsm,项目名称:specidentify,代码行数:19,代码来源:iterfit.py

示例9: _getWeights

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def _getWeights(self, a, b):
        """
        Computes weights using spline interpolation instead of Gaussian quadrature

        Args:
            a (float): left interval boundary
            b (float): right interval boundary

        Returns:
            np.ndarray: weights of the collocation formula given by the nodes
        """

        # get the defining tck's for each spline basis function
        circ_one = np.zeros(self.num_nodes)
        circ_one[0] = 1.0
        tcks = []
        for i in range(self.num_nodes):
            tcks.append(
                intpl.splrep(self.nodes, np.roll(circ_one, i), xb=self.tleft, xe=self.tright, k=self.order, s=0.0))

        weights = np.zeros(self.num_nodes)
        for i in range(self.num_nodes):
            weights[i] = intpl.splint(a, b, tcks[i])

        return weights 
开发者ID:Parallel-in-Time,项目名称:pySDC,代码行数:27,代码来源:equidistant_spline_right.py

示例10: interpolate

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def interpolate(self, s_freq=4, interp_method='cubic'):
        rri = self.rri
        irregular_time = self.time
        step = 1 / float(s_freq)
        regular_time = arange(0, irregular_time[-1] + step, step)
        
        if interp_method == 'cubic':
            tck = splrep(irregular_time, rri, s=0)
            rri_interp = splev(regular_time, tck, der=0)
            
        elif interp_method == 'linear':
            rri_interp = interp(regular_time, irregular_time, rri)
            
        self.time_interp = regular_time
        self.rri_interp = rri_interp
        self.s_freq = s_freq 
开发者ID:wonambi-python,项目名称:wonambi,代码行数:18,代码来源:lyonrri.py

示例11: test_baffle_correction_Bell_fit

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def test_baffle_correction_Bell_fit():
    from ht.conv_tube_bank import Bell_baffle_configuration_tck
    # 125 us to create.
    spl = splrep(Bell_baffle_configuration_Fcs, Bell_baffle_configuration_Jcs, s=8e-5)
    [assert_allclose(i, j) for (i, j) in zip(spl, Bell_baffle_configuration_tck)]
    
    Bell_baffle_configuration_obj = UnivariateSpline(Bell_baffle_configuration_Fcs, 
                                                     Bell_baffle_configuration_Jcs, 
                                                     s=8e-5)
#    import matplotlib.pyplot as plt
#    plt.plot(Bell_baffle_configuration_Fcs, Bell_baffle_configuration_Jcs)
#    pts = np.linspace(0, 1, 5000)
#    plt.plot(pts, [Bell_baffle_configuration_obj(i) for i in pts])
#    plt.plot(pts, [0.55 + 0.72*i for i in pts]) # Serth and HEDH 3.3.6g misses the tip
#    plt.show()
# 
开发者ID:CalebBell,项目名称:ht,代码行数:18,代码来源:test_conv_tube_bank.py

示例12: sample_613

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def sample_613():
    """
    6.1.3 插值
    :return:
    """
    from scipy.interpolate import interp1d, splrep, splev

    # 示例两种插值计算方式
    _, axs = plt.subplots(nrows=1, ncols=2, figsize=(14, 5))

    # 线性插值
    linear_interp = interp1d(x, y)
    # axs[0]左边的
    axs[0].set_title('interp1d')
    # 在相同坐标系下,同样的x,插值的y值使r.绘制(红色点)
    axs[0].plot(x, y, '', x, linear_interp(x), 'r.')

    # B-spline插值
    splrep_interp = splrep(x, y)
    # axs[1]右边的
    axs[1].set_title('splrep')
    # #在相同坐标系下,同样的x,插值的y值使g.绘制(绿色点)
    axs[1].plot(x, y, '', x, splev(x, splrep_interp), 'g.')
    plt.show() 
开发者ID:bbfamily,项目名称:abu,代码行数:26,代码来源:c6.py

示例13: smoothing

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def smoothing(s):
        'curve.smoothing is the amount of smoothing passed to splrep for the given curve.'
        if s is None: return None
        assert(pimms.is_number(s) and s >= 0)
        return s 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:7,代码来源:core.py

示例14: weights

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def weights(w):
        'curve.weights are the weights passed to splrep for a given curve.'
        if w is None: return None
        w = pimms.imm_array(w)
        assert(pimms.is_vector(w, 'number'))
        return w 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:8,代码来源:core.py

示例15: __call__

# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splrep [as 别名]
def __call__(self, t, derivative=0):
        from scipy import interpolate
        xint = interpolate.splev(t, self.splrep[0], der=derivative, ext=0)
        yint = interpolate.splev(t, self.splrep[1], der=derivative, ext=0)
        return np.asarray([xint,yint]) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:7,代码来源:core.py


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