[英]Interpolate values at 3D coordinates
我在特定的 3D 坐标xyz
处给出了值v
。 数据存储为 pandas dataframe:
x y z v
0 -68.5 68.50 -10.00 0.297845
1 -68.5 -23.29 61.10 0.148683
2 -68.5 -23.29 63.47 0.142325
3 -68.5 -23.29 65.84 0.135908
4 -68.5 -23.29 68.21 0.129365
... ... ... ...
91804 68.5 23.29 151.16 0.118460
91805 68.5 23.29 153.53 0.119462
91806 68.5 23.29 155.90 0.120386
91807 68.5 23.29 139.31 0.112257
91808 68.5 -68.50 227.00 0.127948
我想在不属于 dataframe 的新坐标处找到值,因此我正在研究如何有效地插入数据。
我正在使用来自 scipy 的插值 function,名为interpn :
from scipy.interpolate import interpn
# Put data into shape that is accepted by interpn
# I guess the error is somewhere here...
xs = np.array(df["x"].to_list())
ys = np.array(df["y"].to_list())
zs = np.array(df["z"].to_list())
vs = np.array(df["v"].to_list())
original_points = (xs, ys, zs)
original_values = vs.reshape(len(np.unique(xs)), len(np.unique(ys)), len(np.unique(zs)))
# Point at which I would like to retrive the interpolated value
new_point = np.array([0,0,0])
# perform interpolation
new_value = interpn(original_points, original_values, new_point)
但我收到以下错误:
ValueError:维度 0 中的点必须严格升序
非常感谢您帮助解决此问题。 谢谢你。
假设您的数据位于常规网格上,则 xs、ys 和 zs 必须是唯一的。 尝试类似的东西 -
xs, ind = np.unique(xs, return_index=True)
xs = xs[np.argsort(ind)]
作为替代方案,您可以对非结构化数据使用插值器 - https://docs.scipy.org/doc/scipy/reference/interpolate.html#multivariate-interpolation 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.