[Paraview] extract time-series structured data to numpy 3D array

Ben Orr benjamincorr at gmail.com
Tue May 23 14:25:13 EDT 2017


Paraview Developers,

I have timeseries, structured multiblock, density data in the ensight
format. For example purposes, say 1000 timesteps and 40 blocks. I would
like to export all timesteps for only block#=12, IJK_index=(12,14,1). A
common example of doing this is when treating a cell as a virtual
pressure-tap. The problem I'm having is verifying that time is actually
incrementing, and that the reshape from the 1D vtk array to a 3D numpy
array is correct. The following is the core of the script I am using to
perform this analysis.

#####################################################################
import paraview.simple as pv
pv._DisableFirstRenderCameraReset()
import paraview.servermanager as pvs
import paraview.numpy_support as pvn
import numpy as np

# hard-coded path to ensight case file
ensight_case_path = '/path/to/ensight.case' # obviously my script has a
valid path

# Read in the ensight data
ensightcase = pv.EnSightReader(CaseFileName=ensight_case_path)
ensightcase.PointArrays = ['Density']

# loop over each timestep
for t in ensightcase.TimestepValues:
    ensightcase.UpdatePipeline(time=t) # TODO: verify that this indeed
updates time

    # bring the data to the client
    ensightcase_data = pvs.Fetch(ensightcase)

    # get the 12th index block (zero-based index, so actually the 13th
block)
    block = ensightcase_data.GetBlock(12)

    # get the i,j,k dimensions (used next to reshape the numpy array)
    shape = block.GetDimensions()

    # "convert" the vtkFloatArray to numpy. comes in 1D, so reshape
according to i,j,k
    # TODO: verify that passing vtk's `GetDimensions` to numpy's `reshape`
has the desired effect
    block12_array3d =
pvn.vtk_to_numpy(block.GetPointData().GetArray('Density')).reshape(shape)

    # my real script does stuff with the data. for this example, just print
it
    print("time = ", t, "\tdensity = ", block12_array3d[12,14,1])
#####################################################################

This is a simple problem, but I'm not finding any documentation to backup
my two assumptions. Given the importance of this script to my analysis, I
wanted to request conformation from the community before going forward. I
have quite a lot of data to analysis, so any performance suggestions are
also welcome.

Thank you,

Ben Orr
benjamincorr at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20170523/5e993670/attachment.html>


More information about the ParaView mailing list