使用 Python 和具有多个向量场的 tvtk 将数据保存到 VTK [英] Save data to VTK using Python and tvtk with more than one vector field

查看:49
本文介绍了使用 Python 和具有多个向量场的 tvtk 将数据保存到 VTK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试保存对应于相同结构网格的三组矢量(速度、湍流强度和速度波动的标准偏差).理想情况下,我希望它们成为同一个 vtk 文件的一部分,但到目前为止我只能像这样将其中一个放入文件中:

I'm trying to save three sets of vector quantities corresponding to the same structured grid (velocity, turbulence intensity and standard deviation of velocity fluctuations). Ideally, I'd like them to be a part of the same vtk file but so far I have only been able to get one of them into the file like so:

sg = tvtk.StructuredGrid(dimensions=x.shape, points=pts)
sg.point_data.vectors = U
sg.point_data.vectors.name = 'U'
write_data(sg, 'vtktestWake.vtk')

我花了几个小时寻找如何添加多个向量或标量场的示例,但失败了,所以我想在这里问一下.任何指导将不胜感激.

I've spent past few hours searching for an example of how to add more then one vector or scalar field but failed and so thought I'd ask here. Any guidance will be most appreciated.

谢谢,

阿图尔

推荐答案

经过一番挖掘,我找到了基于 this这个 例子.您必须使用 add_array 方法添加附加数据字段,请参阅:

After some digging around I found the following solution based on this and this example. You have to add the additional data field using the add_array method see:

from tvtk.api import tvtk, write_data
import numpy as np

data = np.random.random((3,3,3))
data2 = np.random.random((3,3,3))

i = tvtk.ImageData(spacing=(1, 1, 1), origin=(0, 0, 0))
i.point_data.scalars = data.ravel()
i.point_data.scalars.name = 'scalars'
i.dimensions = data.shape
# add second point data field
i.point_data.add_array(data2.ravel())
i.point_data.get_array(1).name = 'field2'
i.point_data.update()

write_data(i, 'vtktest.vtk')

这篇关于使用 Python 和具有多个向量场的 tvtk 将数据保存到 VTK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆