How to set custom timestep values for a series of legacy VTK files in ParaView?
Asked Answered
M

2

6

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.

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
...

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.

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.

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)

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.

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

Mincey answered 18/11, 2015 at 4:2 Comment(0)
B
6

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

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

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. 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. load the .pvd file in paraview. You can now use the Annotate Time filter with the good timestep values.

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

Booted answered 6/12, 2015 at 18:4 Comment(0)
M
0

IF you have data in .vtk formats, besides the indirect method that has been written by Bertrand Gazanion, there is another updated solution which is a direct method and is explained below the title: JSON based new meta file format for series added for newer versions of ParaView (~ >= 5.5). In this method a JSON file must be created as below and placed besides the .vtk files, in their folder:

{
  "file-series-version" : "1.0",
  "files" : [
    { "name" : "file_0.vtk", "time" : 0.0 },
    { "name" : "file_1.vtk", "time" : 0.022608 },
    { "name" : "file_2.vtk", "time" : 0.73781 }
  ]
}

This JSON file is easy to be created by Python to specify timesteps corresponding to each file and could be named as SOMENAME.vtk.series:

import json

files_list = [{"name": "file_0.vtk", "time": 0.0}, ...]  # could be achieved by looping
address = "vtk_files_folder/"
file_name = "vtkFileSeriesReader"  # arbitrary

json_dict = {"file-series-version": "1.0", "files": files_list}
with open(''.join([address, file_name, ".vtu.series"]), 'w') as f:
    json.dump(json_dict, f)

The specified timesteps in the JSON file will apply as they are wanted for animating; not index-like.
This method can be more efficient than the indirect one, by reducing time and hard disk storage consumption relating to exporting another file formats i.e. .pvd in previous indirect method. Furthermore, using indirect method, .pvd file will be created outside the OF exported .vtt files' folder (which will be created once .pvd export) and needs to be modified for adjusting timesteps as the Bertrand Gazanion answer. This modifying is a little complicated comparing to JSON file creation in the direct method, and perhaps needs to export your .vtk files as .pvd file in Ascii format.

Note: there need another additional step when using indirect method, and that is need to adjust the Table to Points filter after importing .pvd file.

Micamicaela answered 8/11, 2021 at 20:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.