我有来自数值模拟的vtk
文件,我通常用ParaView
可视化。我想在LaTeX
文档中绘制一些结果。为此,我喜欢使用CSV
文件。好处是Paraview
可以将数据导出到CSV
文件中。因此,我能够将变量密度的完整时间序列导出到CSV
文件序列中。在
但是,我想把这个职位包括在这些CSV
文件中。在
我现在可以做的是:
#### import the simple module from the paraview
from paraview.simple import *
import os
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
### MY VARIABLES
Folder_output='E:\\My Documents\\VTKfiles'
FileNames_list=[os.path.join(Folder_output, f) for f in os.listdir(Folder_output) if os.path.isfile(os.path.join(Folder_output, f))]
nb_tStep=len(FileNames_list)
Arrays_out_list=[ 'Structured Coordinates:0', 'Structured Coordinates:1' ,' Structured Coordinates:2', 'density',]
CSV_File_Names='E:/My Documents/Results'
for t in range(0,nb_tStep):
output_LBM_ = LegacyVTKReader(FileNames=FileNames_list[t] )
####
PassArrays1 = PassArrays()
PassArrays1.PointDataArrays = Arrays_out_list
source = PassArrays1
writer = CreateWriter(CSV_File_Names+"{}.csv".format(t), source)
writer.FieldAssociation = "Points" # or "Cells"
writer.UpdatePipeline()
del writer
有(至少)三个选项可以使用Paraview或/和vtkapi从VTK遗留文件中检索点和变量。在
使用Paraview API
并使用
^{pr2}$pvpython
运行它:您将得到一个与此类似的CSV文件:
稍后可以在脚本(Python或其他任何工具)上使用它来执行一些后处理或绘图操作。在
使用Paraview和vtkapi
虽然第一个选项非常简洁,但您必须将数据写入硬盘,以后可能需要重新加载。如果您只想在一个python脚本中执行后处理或打印操作,那么您将在硬盘上免费写入临时数据。在
下面的代码利用了numpy integration with VTK。它使您能够将坐标和点数据加载到numpy数组中,并在最后将它们导出到CSV文件中(或其他文件):
仅使用VTK API
最后一个与第二个非常相似,但它只使用VTK API:
这个解决方案可能很有趣,因为它只将VTK作为依赖项,而且还可以使用Paraview附带的
pvpython
,因为VTK是Paraview的依赖项。在相关问题 更多 >
编程相关推荐