本文整理汇总了Python中scipy.signal.cspline1d方法的典型用法代码示例。如果您正苦于以下问题:Python signal.cspline1d方法的具体用法?Python signal.cspline1d怎么用?Python signal.cspline1d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.signal
的用法示例。
在下文中一共展示了signal.cspline1d方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_complex
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import cspline1d [as 别名]
def test_complex(self):
# create some smoothly varying complex signal to interpolate
x = np.arange(2)
y = np.zeros(x.shape, dtype=np.complex64)
T = 10.0
f = 1.0 / T
y = np.exp(2.0J * np.pi * f * x)
# get the cspline transform
cy = signal.cspline1d(y)
# determine new test x value and interpolate
xnew = np.array([0.5])
ynew = signal.cspline1d_eval(cy, xnew)
assert_equal(ynew.dtype, y.dtype)
示例2: test_basic
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import cspline1d [as 别名]
def test_basic(self):
y = array([1,2,3,4,3,2,1,2,3.0])
x = arange(len(y))
dx = x[1]-x[0]
cj = signal.cspline1d(y)
x2 = arange(len(y)*10.0)/10.0
y2 = signal.cspline1d_eval(cj, x2, dx=dx,x0=x[0])
# make sure interpolated values are on knot points
assert_array_almost_equal(y2[::10], y, decimal=5)
示例3: test_basic
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import cspline1d [as 别名]
def test_basic(self):
y = array([1, 2, 3, 4, 3, 2, 1, 2, 3.0])
x = arange(len(y))
dx = x[1] - x[0]
cj = signal.cspline1d(y)
x2 = arange(len(y) * 10.0) / 10.0
y2 = signal.cspline1d_eval(cj, x2, dx=dx, x0=x[0])
# make sure interpolated values are on knot points
assert_array_almost_equal(y2[::10], y, decimal=5)
示例4: wiggle
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import cspline1d [as 别名]
def wiggle(self, values):
"""
Plot a trace in VAWT(Variable Area Wiggle Trace)
"""
if self.zmax is None:
self.zmax = values.size
# Rescale so that values ranges from -1 to 1
if self.rescale:
values = values.astype(np.float)
values -= values.min()
values /= values.ptp()
values *= 2
values -= 1
# Interpolate at resampleRatio x the previous density
resample_z = np.linspace(0, values.size, values.size * self.resampleRatio)
# cubic spline interpolation
cj = cspline1d(values)
resample_v = cspline1d_eval(cj, resample_z)
print(resample_v)
newz = resample_z
if self.origin is None:
self.origin = resample_v.mean()
# Plot
if self.posFill is not None:
self.ax.fill_betweenx(newz, resample_v, self.origin,
where=resample_v > self.origin,
facecolor=self.posFill)
if self.negFill is not None:
self.ax.fill_betweenx(newz, resample_v, self.origin,
where=resample_v < self.origin,
facecolor=self.negFill)
if self.lineColor is not None:
self.ax.plot(resample_v, newz, color=self.lineColor, linewidth=.1)
示例5: doresample
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import cspline1d [as 别名]
def doresample(orig_x, orig_y, new_x, method='cubic', padlen=0, antialias=False):
"""
Resample data from one spacing to another. By default, does not apply any antialiasing filter.
Parameters
----------
orig_x
orig_y
new_x
method
padlen
Returns
-------
"""
pad_y = tide_filt.padvec(orig_y, padlen=padlen)
tstep = orig_x[1] - orig_x[0]
if padlen > 0:
pad_x = np.concatenate((np.arange(orig_x[0] - padlen * tstep, orig_x[0], tstep),
orig_x,
np.arange(orig_x[-1] + tstep, orig_x[-1] + tstep * (padlen + 1), tstep)))
else:
pad_x = orig_x
if padlen > 0:
print('padlen=', padlen)
print('tstep=', tstep)
print(pad_x)
# antialias and ringstop filter
init_freq = len(pad_x) / (pad_x[-1] - pad_x[0])
final_freq = len(new_x) / (new_x[-1] - new_x[0])
if antialias and (init_freq > final_freq):
aafilterfreq = final_freq / 2.0
aafilter = tide_filt.noncausalfilter(filtertype='arb', usebutterworth=False)
aafilter.setfreqs(0.0, 0.0, 0.95 * aafilterfreq, aafilterfreq)
pad_y = aafilter.apply(init_freq, pad_y)
if method == 'cubic':
cj = signal.cspline1d(pad_y)
return tide_filt.unpadvec(
np.float64(signal.cspline1d_eval(cj, new_x, dx=(orig_x[1] - orig_x[0]), x0=orig_x[0])), padlen=padlen)
elif method == 'quadratic':
qj = signal.qspline1d(pad_y)
return tide_filt.unpadvec(
np.float64(signal.qspline1d_eval(qj, new_x, dx=(orig_x[1] - orig_x[0]), x0=orig_x[0])), padlen=padlen)
elif method == 'univariate':
interpolator = sp.interpolate.UnivariateSpline(pad_x, pad_y, k=3, s=0) # s=0 interpolates
return tide_filt.unpadvec(np.float64(interpolator(new_x)), padlen=padlen)
else:
print('invalid interpolation method')
return None
示例6: fitSpline
# 需要导入模块: from scipy import signal [as 别名]
# 或者: from scipy.signal import cspline1d [as 别名]
def fitSpline(self,degree=2):
"""
**SUMMARY**
A function to generate a spline curve fitting over the points in LineScan with
order of precision given by the parameter degree
**PARAMETERS**
* *degree* - the precision of the generated spline
**RETURNS**
The spline as a LineScan fitting over the initial values of LineScan
**EXAMPLE**
>>> import matplotlib.pyplot as plt
>>> img = Image("lenna")
>>> ls = img.getLineScan(pt1=(10,10)),pt2=(20,20)).normalize()
>>> spline = ls.fitSpline()
>>> plt.plot(ls)
>>> plt.show()
>>> plt.plot(spline)
>>> plt.show()
**NOTES**
Implementation taken from http://www.scipy.org/Cookbook/Interpolation
"""
if degree > 4:
degree = 4 # No significant improvement with respect to time usage
if degree < 1:
warnings.warn('LineScan.fitSpline - degree needs to be >= 1')
return None
retVal = None
y = np.array(self)
x = np.arange(0,len(y),1)
dx = 1
newx = np.arange(0,len(y)-1,pow(0.1,degree))
cj = sps.cspline1d(y)
retVal = sps.cspline1d_eval(cj,newx,dx=dx,x0=x[0])
return retVal