Python scipy.signal.cspline1d() Examples
The following are 6
code examples of scipy.signal.cspline1d().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.signal
, or try the search function
.
Example #1
Source File: test_signaltools.py From GraphicDesignPatternByPython with MIT License | 6 votes |
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)
Example #2
Source File: test_signaltools.py From Computable with MIT License | 5 votes |
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)
Example #3
Source File: test_signaltools.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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)
Example #4
Source File: vawt.py From pyGeoPressure with MIT License | 5 votes |
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)
Example #5
Source File: resample.py From rapidtide with Apache License 2.0 | 4 votes |
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
Example #6
Source File: LineScan.py From SimpleCV2 with BSD 3-Clause "New" or "Revised" License | 4 votes |
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