Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 550
Mike T Avatar asked Nov 18 '15 04:11

Mike T


1 Answers

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.

like image 152
Bertrand Gazanion Avatar answered Oct 15 '22 19:10

Bertrand Gazanion