本文整理汇总了Python中scipy.interpolate.splev方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.splev方法的具体用法?Python interpolate.splev怎么用?Python interpolate.splev使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.splev方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: curve_length
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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
示例2: residual
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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
示例3: residual
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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
示例4: get_velocities
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [as 别名]
def get_velocities(positions, times, tol):
positions = np.atleast_2d(positions)
n = len(positions)
deg = min(3, n - 1)
good_inds = np.r_[True, (abs(times[1:] - times[:-1]) >= 1e-6)]
good_positions = positions[good_inds]
good_times = times[good_inds]
if len(good_inds) == 1:
return np.zeros(positions[0:1].shape)
(tck, _) = si.splprep(good_positions.T, s=tol ** 2 * (n + 1), u=good_times, k=deg)
# smooth_positions = np.r_[si.splev(times,tck,der=0)].T
velocities = np.r_[si.splev(times, tck, der=1)].T
return velocities
示例5: test_Taitel_Dukler_splines
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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.
示例6: pla
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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):
示例7: interpolate
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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
示例8: interpolate
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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
示例9: sample_613
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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()
示例10: __call__
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [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])
示例11: _evalfr
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [as 别名]
def _evalfr(self, omega):
"""Evaluate a transfer function at a single angular frequency."""
# Preallocate the output.
if getattr(omega, '__iter__', False):
out = empty((self.outputs, self.inputs, len(omega)), dtype=complex)
else:
out = empty((self.outputs, self.inputs), dtype=complex)
if self.ifunc is None:
try:
out = self.fresp[:, :, where(self.omega == omega)[0][0]]
except Exception:
raise ValueError(
"Frequency %f not in frequency list, try an interpolating"
" FRD if you want additional points" % omega)
else:
if getattr(omega, '__iter__', False):
for i in range(self.outputs):
for j in range(self.inputs):
for k, w in enumerate(omega):
frraw = splev(w, self.ifunc[i, j], der=0)
out[i, j, k] = frraw[0] + 1.0j * frraw[1]
else:
for i in range(self.outputs):
for j in range(self.inputs):
frraw = splev(omega, self.ifunc[i, j], der=0)
out[i, j] = frraw[0] + 1.0j * frraw[1]
return out
# Method for generating the frequency response of the system
示例12: _interpolate
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [as 别名]
def _interpolate(xy, num_points):
tck,u = splprep([
xy[:,0],
xy[:,1]],
s=0
)
unew = linspace(0, 1, num_points)
out = splev(unew, tck)
return column_stack(out)
示例13: _rnd_interpolate
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [as 别名]
def _rnd_interpolate(xy, num_points, ordered=False):
tck,u = splprep([
xy[:,0],
xy[:,1]],
s=0
)
unew = random(num_points)
if ordered:
unew = sort(unew)
out = splev(unew, tck)
return column_stack(out)
示例14: bspline
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [as 别名]
def bspline(x, y, x_new):
tck = interpolate.splrep(x, y, s=0)
ynew = interpolate.splev(x_new, tck, der=0)
return ynew
示例15: field_map2field_func
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import splev [as 别名]
def field_map2field_func(z, By):
tck = interpolate.splrep(z, By, k=3)
func = lambda x, y, z: (0, interpolate.splev(z, tck, der=0), 0)
return func