def lambda_interp(lambdau, s):
# lambda is the index sequence that is produced by the model
# s is the new vector at which evaluations are required.
# the value is a vector of left and right indices, and a vector of fractions.
# the new values are interpolated bewteen the two using the fraction
# Note: lambda decreases. you take:
# sfrac*left+(1-sfrac*right)
if len(lambdau) == 1:
nums = len(s)
left = scipy.zeros([nums, 1], dtype = scipy.integer)
right = left
sfrac = scipy.zeros([nums, 1], dtype = scipy.float64)
else:
s[s > scipy.amax(lambdau)] = scipy.amax(lambdau)
s[s < scipy.amin(lambdau)] = scipy.amin(lambdau)
k = len(lambdau)
sfrac = (lambdau[0] - s)/(lambdau[0] - lambdau[k - 1])
lambdau = (lambdau[0] - lambdau)/(lambdau[0] - lambdau[k - 1])
coord = scipy.interpolate.interp1d(lambdau, range(k))(sfrac)
left = scipy.floor(coord).astype(scipy.integer, copy = False)
right = scipy.ceil(coord).astype(scipy.integer, copy = False)
#
tf = left != right
sfrac[tf] = (sfrac[tf] - lambdau[right[tf]])/(lambdau[left[tf]] - lambdau[right[tf]])
sfrac[~tf] = 1.0
#if left != right:
# sfrac = (sfrac - lambdau[right])/(lambdau[left] - lambdau[right])
#else:
# sfrac[left == right] = 1.0
result = dict()
result['left'] = left
result['right'] = right
result['frac'] = sfrac
return(result)
# end of lambda_interp
# =========================================
评论列表
文章目录