问题描述
我有像这里的 .dem 文件: http://ddfe.curtin.edu.au/models/ERTM2160/data/dem/
在 python pyvista 中,我有:
import pyvista as pv
file = 'pick_one_from_the_link_above.dem'
mesh = pv.read(file)
输出说:
mesh.dimensions
[-2147483648,-2147483648,1]
除减号外,mesh.n_points 的平方根
尝试使用 mesh.points 绘制或提取点时,我收到一条消息,指出不允许使用负尺寸。尝试以下:
mesh.dimensions = [int(numpy.sqrt(mesh.n_points)),int(numpy.sqrt(mesh.n_points)),1]
导致错误消息:
溢出错误:SetDimensions 参数 1:值超出整数范围
谁能告诉我我做错了什么,我不知道?或者可能知道如何读取这些文件以制作曲面图?
非常感谢:)
解决方法
@larsks 在上面的评论中是正确的。这些“.dem”文件不是 PyVista 和它包装的 VTK 阅读器所期望的格式。您应该使用 np.fromfile
读取数据:arr = np.fromfile('N00E015.dem',dtype=np.int16)
。离the docs listed at your link更远:
由于其总大小为 44 GB,该模型被分区并分布在 每个函数的 881 个 5 度 x 5 度大小的二进制文件的术语。每 5 度 x 5 度图块在单元格中心表示中包含 2500 x 2500 个网格点 (网格点不在整数子午线和纬线上)
您只需创建一个该大小的 pv.UniformGrid
并添加数据。例如:
import numpy as np
import pyvista as pv
arr = np.fromfile('N00E015.dem',dtype=np.int16)
grid = pv.UniformGrid()
grid.dimensions = (2500,2500,1)
grid.origin = (0,0) # you need to figure this out
grid['dem'] = arr
grid.plot()
为了获得网格的正确空间参考,您需要设置每个子集/网格的 origin
点。
此外,PyVista 社区在 PyVista 支持论坛上比 Stack Overflow 上更活跃:https://github.com/pyvista/pyvista-support