Access transient data from Ensight files inside a script

Hi All,

I’m reading in an Ensight gold case file which consists of a single 2D slice with scalars for a number of time-steps.

I would like to do some eigenvalue work on the transient data but need to access the data at each time-step within a loop for a given scalar. In a sense this similar to what the “Temporal Statistics” filter is doing.

So the script I hope to have so far runs like this :

  1. Read in the Ensight file.
  2. Use the numpy-to-vtk adapter to access data.
  3. Loop over time-steps and store the data
  4. Apply temporal statistical analysis
  5. Write the result back by appending the output as a new array

My script:

from paraview.simple import *

from paraview import servermanager as sm
from paraview.vtk.numpy_interface import dataset_adapter as dsa
 

dat = EnSightReader(CaseFileName='C:/scratch/F1_.case')

mg=MergeBlocks(Input=dat,MergePoints=0)
vtk_data = sm.Fetch(mg)
vtk_data = dsa.WrapDataObject(vtk_data)
data = vtk_data.PointData 

So here am able to call data[0] to display the raw data for the first scalar.

How can I then “step through” the rest of the time-steps while appending data[0] to some array?

Many thanks for any direction here,

Sandeep

Just in case someone has the same question, my workaround is detailed below.

I finally wrote the ensight time-series using Paraview’s writer to a set of *.vtu (VTK Unstructured) or *.vtp (Polydata) as required and used the VTK modules in an external python script to extract the data I needed.

Some code below. Note that additional code should be written for error handling so follow standard I/O safe practice.

Naturally, the thing can be done faster via encapsulating the relevant lines in python multiprocessing code. Watch the RAM!

import vtk
import numpy as np
from vtk.util import numpy_support
from vtk.util.numpy_support import vtk_to_numpy

location='C:/scratch/'
          
scal = 'qprime'

scalar=[]
reader = vtk.vtkXMLUnstructuredGridReader() # Note change to PolyData if necessary. 

# Read the first ten files which are named as "f1_0.vtu" to "f1_10.vtu" 

for n in np.arange(0,10):
    vtk_file_name = 'f1_'+str(n)+'.vtu' 
    reader.SetFileName(location+vtk_file_name)
    reader.Update()
    
    #Modify the following lines as relevant to VTK data type

    data = reader.GetOutput()
    point_data = data.GetPointData()
    point_data.GetNumberOfArrays()  

    # Get the scalar and append as in the OP request

    scalar_data1 = point_data.GetAbstractArray(scal)
    scalar.append(np.array([scalar_data1.GetValue(i) for i in range(data.GetNumberOfPoints())]))

# 'scalar' is now a nice array of the time-series of the 2D slice.

Lines may need modification if legacy vtk files (e.g. ‘Update Scalars()’ etc) are used . Also, the above is NOT recommended for large data since the array scalar can become obese and more fancy arrays (DASK?) might be help. This workaround was enough for my purposes but perhaps someone else can suggest a better way to do things (e.g. within paraview itself).