def interpolation_alphas(self, points, *args, **kwargs):
'''
Returns a pair of values. The 1st value is an array of the depth indices of all the particles.
The 2nd value is an array of the interpolation alphas for the particles between their depth
index and depth_index+1. If both values are None, then all particles are on the surface layer.
'''
points = np.asarray(points, dtype=np.float64)
points = points.reshape(-1, 3)
underwater = points[:, 2] > 0
if len(np.where(underwater)[0]) == 0:
return None, None
indices = -np.ones((len(points)), dtype=np.int64)
alphas = -np.ones((len(points)), dtype=np.float64)
pts = points[underwater]
und_ind = -np.ones((len(np.where(underwater)[0])))
und_alph = und_ind.copy()
und_ind = np.digitize(pts[:,2], self.depth_levels) - 1
for i,n in enumerate(und_ind):
if n == len(self.depth_levels) -1:
und_ind[i] = -1
if und_ind[i] != -1:
und_alph[i] = (pts[i,2] - self.depth_levels[und_ind[i]]) / (self.depth_levels[und_ind[i]+1] - self.depth_levels[und_ind[i]])
indices[underwater] = und_ind
alphas[underwater] = und_alph
return indices, alphas
评论列表
文章目录