【问题标题】:interpolate data to triangular mesh将数据插入三角形网格
【发布时间】:2019-05-15 00:22:34
【问题描述】:

有很多问题(和答案)可供人们将非结构化数据插入到结构化输出中。解决方案包括网格或双变量样条。但是我正在寻找相反的情况。如何将结构化数据内插到非结构化(delaulany)三角形(快速)?

我拥有的数据作为 pygmsh 的一部分使用 meshio 加载。

import meshio as mio
data = mio.read(fname)

data.cells['vertex'].shape
Out[128]: (2906, 1)
data.cells['triangle'].shape
Out[129]: (213898, 3)

plt.figure()
plt.tripcolor(data.points[:, 0], data.points[:, 1], -data.points[:, 2])
plt.triplot(data.points[:, 0], data.points[:, 1], 'k.', ms=2)

显示下图。我有新数据要在这个三角形网格上更新。我计划将规则结构化数据的值插入到空间中的相同点,然后更新三角形网格的值。

【问题讨论】:

    标签: python-3.x interpolation triangular spatial-interpolation


    【解决方案1】:

    我发现最接近这个的是Python: interpolating in a triangular mesh

    解决该答案并通过示例进行扩展。

    newBathy['lon'].shape
    Out[154]: (1040, 271)
    newBathy['lat'].shape
    Out[155]: (1040, 271)
    newBathy['elevation'].shape
    Out[156]: (1040, 271)
    #I have to flatten so i don't get a shape error 
    triObj = tri.Triangulation(newBathy['lon'].flatten(), newBathy['lat'].flatten()) 
    ftri = tri.LinearTriInterpolator(triObj, newBathy['elevation'].flatten())
    newZs = ftri(data.points[:, 0], data.points[:, 1])
    

    这让我只剩下一小部分已知域中的数据,但我可以从data.points([:,3]) 的那些更新newZs 中的非屏蔽值。还没有找到最好的方法,因为三次插值需要一段时间,让我的电脑听起来像一艘宇宙飞船。线性显然有效,但可能会更好看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 2017-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多