本文整理汇总了Python中scipy.interpolate.pchip_interpolate方法的典型用法代码示例。如果您正苦于以下问题:Python interpolate.pchip_interpolate方法的具体用法?Python interpolate.pchip_interpolate怎么用?Python interpolate.pchip_interpolate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate
的用法示例。
在下文中一共展示了interpolate.pchip_interpolate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: stopPicking
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import pchip_interpolate [as 别名]
def stopPicking(self,proj,canvas):
filename = fd.asksaveasfilename()
if filename is not '':
self.picking = False
canvas.mpl_disconnect(self.pick_cid)
print("Picking mode off")
np.savetxt(filename+'_profile.txt',self.picked,delimiter='\t')
print('saved picked file as "%s"' %(filename+'_profile.txt'))
# If we have 3D info, also plot it as 3D points
if proj.threeD is not None:
# First calculate along-track points
topoVal = proj.threeD[:,2]
npos = proj.threeD.shape[0]
steplen = np.sqrt(
np.power( proj.threeD[1:npos,0]-proj.threeD[0:npos-1,0] ,2.0) +
np.power( proj.threeD[1:npos,1]-proj.threeD[0:npos-1,1] ,2.0) +
np.power( proj.threeD[1:npos,2]-proj.threeD[0:npos-1,2] ,2.0)
)
alongdist = np.cumsum(steplen)
topoPos = np.append(0,alongdist)
pick3D = np.zeros((self.picked.shape[0],3))
# If profile is adjusted, need to start the picked at zero.
pickProfileShifted = self.picked[:,0] - np.min(proj.profilePos)
#for i in range(0,3):
for i in range(0,2):
pick3D[:,i] = interp.pchip_interpolate(topoPos,
proj.threeD[:,i],
pickProfileShifted).squeeze()
#self.picked[:,0]).squeeze()
pick3D[:,2] = self.picked[:,1].squeeze()
np.savetxt(filename+'_3D.txt',pick3D,delimiter='\t')
print('saved picked file as "%s"' %(filename+'_3D.txt'))
示例2: _interpolate_scipy_wrapper
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import pchip_interpolate [as 别名]
def _interpolate_scipy_wrapper(x, y, new_x, method, fill_value=None,
bounds_error=False, order=None, **kwargs):
"""
passed off to scipy.interpolate.interp1d. method is scipy's kind.
Returns an array interpolated at new_x. Add any new methods to
the list in _clean_interp_method
"""
try:
from scipy import interpolate
from pandas import DatetimeIndex
except ImportError:
raise ImportError('{0} interpolation requires Scipy'.format(method))
new_x = np.asarray(new_x)
# ignores some kwargs that could be passed along.
alt_methods = {
'barycentric': interpolate.barycentric_interpolate,
'krogh': interpolate.krogh_interpolate,
'piecewise_polynomial': interpolate.piecewise_polynomial_interpolate,
}
if getattr(x, 'is_all_dates', False):
# GH 5975, scipy.interp1d can't hande datetime64s
x, new_x = x.values.astype('i8'), new_x.astype('i8')
try:
alt_methods['pchip'] = interpolate.pchip_interpolate
except AttributeError:
if method == 'pchip':
raise ImportError("Your version of scipy does not support "
"PCHIP interpolation.")
interp1d_methods = ['nearest', 'zero', 'slinear', 'quadratic', 'cubic',
'polynomial']
if method in interp1d_methods:
if method == 'polynomial':
method = order
terp = interpolate.interp1d(x, y, kind=method, fill_value=fill_value,
bounds_error=bounds_error)
new_y = terp(new_x)
elif method == 'spline':
terp = interpolate.UnivariateSpline(x, y, k=order)
new_y = terp(new_x)
else:
method = alt_methods[method]
new_y = method(x, y, new_x)
return new_y
示例3: correctTopo
# 需要导入模块: from scipy import interpolate [as 别名]
# 或者: from scipy.interpolate import pchip_interpolate [as 别名]
def correctTopo(data, velocity, profilePos, topoPos, topoVal, twtt):
'''
Corrects for topography along the profile by shifting each
Trace up or down depending on provided coordinates.
INPUT:
data data matrix whose columns contain the traces
velocity subsurface RMS velocity in m/ns
profilePos along-profile coordinates of the traces
topoPos along-profile coordinates for provided elevation
in meters
topoVal elevation values for provided along-profile
coordinates, in meters
twtt two-way travel time values for the samples, in ns
OUTPUT:
newdata data matrix with shifted traces, padded with NaN
newtwtt twtt for the shifted / padded data matrix
maxElev maximum elevation value
minElev minimum elevation value
'''
# We assume that the profilePos are the correct along-profile
# points of the measurements (they can be correted with adj profile)
# For some along-profile points, we have the elevation from prepTopo
# So we can just interpolate
if not ((all(np.diff(topoPos)>0)) or (all(np.diff(topoPos)<0))):
raise ValueError('\x1b[1;31;47m' + 'The profile vs topo file does not have purely increasing or decreasing along-profile positions' + '\x1b[0m')
else:
elev = interp.pchip_interpolate(topoPos,topoVal,profilePos)
elevdiff = elev-np.min(elev)
# Turn each elevation point into a two way travel-time shift.
# It's two-way travel time
etime = 2*elevdiff/velocity
timeStep=twtt[3]-twtt[2]
# Calculate the time shift for each trace
tshift = (np.round(etime/timeStep)).astype(int)
maxup = np.max(tshift)
# We want the highest elevation to be zero time.
# Need to shift by the greatest amount, where we are the lowest
tshift = np.max(tshift) - tshift
# Make new datamatrix
newdata = np.empty((data.shape[0]+maxup,data.shape[1]))
newdata[:] = np.nan
# Set new twtt
newtwtt = np.arange(0, twtt[-1] + maxup*timeStep, timeStep)
nsamples = len(twtt)
# Enter every trace at the right place into newdata
for pos in range(0,len(profilePos)):
#print(type(tshift[pos][0]))
newdata[tshift[pos][0]:tshift[pos][0]+nsamples ,pos] = np.squeeze(data[:,pos])
return newdata, newtwtt, np.max(elev), np.min(elev)