如何为 ParaView 中的一系列旧 VTK 文件设置自定义时间步长值?

2022-01-11 00:00:00 python time-series paraview vtk

问题描述

我有一系列 旧 VTK 文件,例如:file_0.vtkfile_1.vtkfile_2.vtk,我可以在 ParaView 中将其作为时间序列打开(这里描述)为file_..vtk,文件的顺序可以使用时间控件查看和制作动画.我目前使用的是 ParaView 4.4.0.

I have a sequence of legacy VTK files, e.g.: file_0.vtk, file_1.vtk, file_2.vtk, which I can open in ParaView as a time series (described here) as file_..vtk, and the sequence of files can be viewed and animated using the time controls. I'm currently using ParaView 4.4.0.

传统的 VTK 文件如下所示,其中时间步长值存储在标题中(第二行):

The legacy VTK files look like this, where the timestep value is stored in the header (second line):

# vtk DataFile Version 3.0
vtk output: file at time       0.0    
ASCII
...

但是,在 ParaView 中,时间步长值假定与索引相同,即索引 0 是时间 0.0,索引 1 是时间 1.0,索引 2 是时间 2.0.添加 AnnotateTime 过滤器还会为时间步长索引显示这些时间步长.

However, in ParaView the timestep values have assumed the same as the index, i.e. index 0 is time 0.0, index 1 is time 1.0, and index 2 is time 2.0. And adding an AnnotateTime filter also shows these timesteps for the timestep indexes.

但是,我的文件使用可变时间步长,如每个文件的标题中所述.(我认为传统的 VTK 格式没有办法指定这些值).我查看了 ParaView 的应用程序,看看是否有办法导入或修改这些值,但我找不到.

However, my files use variable timesteps, as described in the header of each file. (I don't think that the legacy VTK format has a way to specify these values). I've looked around ParaView's application to see if there is a way to import or modify these values, but I cannot find it.

使用内置的 Python Shell,这是我用 LegacyVTKReader:

Using the built-in Python Shell, here is my sad attempt to create the object with LegacyVTKReader:

files = ['file_0.vtk', 'file_1.vtk', 'file_2.vtk']
times = [0.0, 0.022608, 0.73781]
# First attempt
r = LegacyVTKReader(FileNames=files, TimestepValues=times)
print(r.TimestepValues)  # [0.0, 1.0, 2.0]

# Second attempt to try and fix it
r.TimestepValues = times
print(r.TimestepValues)  # [0.0, 0.022608, 0.73781]

Show(r)

在对象信息"对话框中正确显示,直到我添加一个 AnnotateTimeFilter,它将 0 重置为 0、1 重置为 1 和 2 重置为 2.

Which shows the correctly in the objects "Information" dialog, until I add an AnnotateTimeFilter, which resets 0 to 0, 1 to 1, and 2 to 2.

有没有任何方法,使用点击或 Python 来更新 ParaView 中旧 VTK 对象的每个索引的时间步长值?

Is there any way, using point-click or Python, to update the timestep values for each index of a legacy VTK object in ParaView?


解决方案

我调查了你的答案,发现没有直接的方法来做你问的事情.

I investigated your answer and found no direct way to do what you ask.

但是,这是一个间接的解决方案(取自 paraview 邮件列表):

However, here is an indirect solution (taken from the paraview mailing list) :

1.将您的 vtk 文件转换为 xml paraview 文件(例如 VTU 或 VTM 文件):使用 paraview 打开您的 vtk 文件,然后使用 File > Save Data 写入新文件.您需要检查将所有时间步长写入文件系列".

1. convert your vtk files to xml paraview files (e.g. VTU or VTM files) : open your vtk files with paraview, and write the new files with File > Save Data. You needd to check the "write all timesteps as file-series".

<强>2.创建 ParaView 数据文件 (.pvd).在此文件中,您可以为每个文件指定时间步长值.这是一个例子:

2. create a ParaView Data File (.pvd). In this file you can specify the timestep value for each file. Here is an example :

    <VTKFile type="Collection" version="0.1" byte_order="LittleEndian">
        <Collection>
            <DataSet timestep="0"         file='file_0.vtu'/>
            <DataSet timestep="0.022608"  file='file_1.vtu'/>
            <DataSet timestep="0.73781"   file='file_2.vtu'/>
        </Collection>
    </VTKFile>

3.在 paraview 中加载 .pvd 文件.您现在可以使用具有良好时间步长值的 Annotate Time 过滤器.

3. load the .pvd file in paraview. You can now use the Annotate Time filter with the good timestep values.

第 1 步是必需的,因为上述解决方案不适用于 .vtk 文件,如 中所述paraview wiki.

Step 1 is required because the above solution doesn't work with .vtk files, as explained in the paraview wiki.

相关文章