|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
from __future__ import absolute_import, division
|
|
|
|
|
import numpy as np
|
|
|
|
|
import scipy.signal
|
|
|
|
|
# import scipy.sparse.linalg # @UnusedImport
|
|
|
|
|
import scipy.sparse as sparse
|
|
|
|
|
from numpy import ones, zeros, prod, sin, diff, pi, inf, vstack, linspace
|
|
|
|
@ -106,12 +105,15 @@ def _get_turnpoint(xvals):
|
|
|
|
|
turnpoint = 0
|
|
|
|
|
last = len(xvals)
|
|
|
|
|
if xvals[0] < xvals[1]: # x is increasing?
|
|
|
|
|
compare = lambda a, b: a < b
|
|
|
|
|
def compare(a, b):
|
|
|
|
|
return a < b
|
|
|
|
|
else: # no, x is decreasing
|
|
|
|
|
compare = lambda a, b: a > b
|
|
|
|
|
def compare(a, b):
|
|
|
|
|
return a > b
|
|
|
|
|
|
|
|
|
|
for i in range(1, last): # yes
|
|
|
|
|
if compare(xvals[i], xvals[i - 1]): # search where x starts to fall or rise
|
|
|
|
|
# search where x starts to fall or rise
|
|
|
|
|
if compare(xvals[i], xvals[i - 1]):
|
|
|
|
|
turnpoint = i
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
@ -245,36 +247,44 @@ def sgolay2d(z, window_size, order, derivative=None):
|
|
|
|
|
Z = np.zeros((new_shape))
|
|
|
|
|
# top band
|
|
|
|
|
band = z[0, :]
|
|
|
|
|
Z[:half_size, half_size:-half_size] = band - np.abs(np.flipud(z[1:half_size + 1, :]) - band)
|
|
|
|
|
Z[:half_size, half_size:-half_size] = band - \
|
|
|
|
|
np.abs(np.flipud(z[1:half_size + 1, :]) - band)
|
|
|
|
|
# bottom band
|
|
|
|
|
band = z[-1, :]
|
|
|
|
|
Z[-half_size:, half_size:-half_size] = band + np.abs(np.flipud(z[-half_size - 1:-1, :]) - band)
|
|
|
|
|
Z[-half_size:, half_size:-half_size] = band + \
|
|
|
|
|
np.abs(np.flipud(z[-half_size - 1:-1, :]) - band)
|
|
|
|
|
# left band
|
|
|
|
|
band = np.tile(z[:, 0].reshape(-1, 1), [1, half_size])
|
|
|
|
|
Z[half_size:-half_size, :half_size] = band - np.abs(np.fliplr(z[:, 1:half_size + 1]) - band)
|
|
|
|
|
Z[half_size:-half_size, :half_size] = band - \
|
|
|
|
|
np.abs(np.fliplr(z[:, 1:half_size + 1]) - band)
|
|
|
|
|
# right band
|
|
|
|
|
band = np.tile(z[:, -1].reshape(-1, 1), [1, half_size])
|
|
|
|
|
Z[half_size:-half_size, -half_size:] = band + np.abs(np.fliplr(z[:, -half_size - 1:-1]) - band)
|
|
|
|
|
Z[half_size:-half_size, -half_size:] = band + \
|
|
|
|
|
np.abs(np.fliplr(z[:, -half_size - 1:-1]) - band)
|
|
|
|
|
# central band
|
|
|
|
|
Z[half_size:-half_size, half_size:-half_size] = z
|
|
|
|
|
|
|
|
|
|
# top left corner
|
|
|
|
|
band = z[0, 0]
|
|
|
|
|
Z[:half_size, :half_size] = band - \
|
|
|
|
|
np.abs(np.flipud(np.fliplr(z[1:half_size + 1, 1:half_size + 1])) - band)
|
|
|
|
|
np.abs(
|
|
|
|
|
np.flipud(np.fliplr(z[1:half_size + 1, 1:half_size + 1])) - band)
|
|
|
|
|
# bottom right corner
|
|
|
|
|
band = z[-1, -1]
|
|
|
|
|
Z[-half_size:, -half_size:] = band + \
|
|
|
|
|
np.abs(np.flipud(np.fliplr(z[-half_size - 1:-1, -half_size - 1:-1])) - band)
|
|
|
|
|
np.abs(
|
|
|
|
|
np.flipud(np.fliplr(z[-half_size - 1:-1, -half_size - 1:-1])) - band)
|
|
|
|
|
|
|
|
|
|
# top right corner
|
|
|
|
|
band = Z[half_size, -half_size:]
|
|
|
|
|
Z[:half_size, -half_size:] = band - \
|
|
|
|
|
np.abs(np.flipud(Z[half_size + 1:2 * half_size + 1, -half_size:]) - band)
|
|
|
|
|
np.abs(
|
|
|
|
|
np.flipud(Z[half_size + 1:2 * half_size + 1, -half_size:]) - band)
|
|
|
|
|
# bottom left corner
|
|
|
|
|
band = Z[-half_size:, half_size].reshape(-1, 1)
|
|
|
|
|
Z[-half_size:, :half_size] = band - \
|
|
|
|
|
np.abs(np.fliplr(Z[-half_size:, half_size + 1:2 * half_size + 1]) - band)
|
|
|
|
|
np.abs(
|
|
|
|
|
np.fliplr(Z[-half_size:, half_size + 1:2 * half_size + 1]) - band)
|
|
|
|
|
|
|
|
|
|
# solve system and convolve
|
|
|
|
|
sgn = {None: 1}.get(derivative, -1)
|
|
|
|
@ -597,7 +607,8 @@ class SmoothSpline(PPform):
|
|
|
|
|
di = di.T
|
|
|
|
|
ci = ci.T
|
|
|
|
|
ai = ai.T
|
|
|
|
|
coefs = vstack([val.ravel() for val in [di, ci, bi, ai] if val.size>0])
|
|
|
|
|
coefs = vstack([val.ravel()
|
|
|
|
|
for val in [di, ci, bi, ai] if val.size > 0])
|
|
|
|
|
return coefs
|
|
|
|
|
|
|
|
|
|
def _compute_coefs(self, xx, yy, p=None, var=1):
|
|
|
|
@ -978,6 +989,7 @@ class StinemanInterp(object):
|
|
|
|
|
--------
|
|
|
|
|
slopes, Pchip
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
def __init__(self, x, y, yp=None, method='parabola', monotone=False):
|
|
|
|
|
if yp is None:
|
|
|
|
|
yp = slopes(x, y, method, monotone=monotone)
|
|
|
|
@ -1214,7 +1226,6 @@ def test_smoothing_spline():
|
|
|
|
|
|
|
|
|
|
plt.plot(x, y, x1, y1, '.', x1, dy1, 'ro', x1, y01, 'r-')
|
|
|
|
|
plt.show('hold')
|
|
|
|
|
pass
|
|
|
|
|
# tck = interpolate.splrep(x, y, s=len(x))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|