Access data arrays in a python code with paraview.simple

Hello,

I’d like my python code to access data arrays from a multiblock dataset I read into Paraview (Ensight) via paraview.simple

I want to run some math on these arrays using my python code and save the output back into the dataset. At this point am not sure if I need raw data or not but one of the math operation is an eigenvalue solving so I guess it needs the data on my client to work on…

I could use the programmable filter but would like to switch to scripting to automate. Besides it is far easier to import paraview.simple into my python code and do what I need to do rather than bring the whole code into a programmable filter.

Your help is most appreciated!

Sandeep.

1 Like

servermanager.Fetch should help you here : https://kitware.github.io/paraview-docs/latest/python/paraview.servermanager.html#paraview.servermanager.Fetch

servermanager.Fetch will return you the VTK object.

You can wrap this with the NumPy dataset adapter to get NumPy-friendly arrays:

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

...

vtk_data = sm.Fetch(pv_object)
vtk_data = dsa.WrapDataObject(vtk_data)
data = vtk_data.PointData[0]
1 Like

Thank you very much Mathieu and Phillip! I was able to follow your directions.

I had gotten as far as the servermanager’s Fetch before I posted but didn’t know how to convert the result to a numpy array.

Following Phillip’s post, I still ended up with an object that didn’t display the numeric data in the array. I experimented a little and the numpy array becomes possible after issuing a ‘MergeBlocks’ right after reading the dataset in. I guess it is a multiblock thing…so for larger datasets it might be best to only do the Fetch on a slice or something.

Cheers,

Sandeep.

1 Like

Yes, multiblocks can be tricky to navigate, using MergeBlocks is fine.

I’ll add one other reference for anyone else trying to figure things out:

As usual, it is in the manual… :man_facepalming:

1 Like