I’m trying to compute area average distributions of flow quantities with a pvpython script. To perform the computations I need to get in my python script some quantities that are present in a spreadsheet that I managed to create. The problem is that the only way I figured out to get the quantities I need is to export the spreadsheet content in a csv file and then read it in my python script, which is definitely not an effective strategy…
Once created the spreadsheet with the commands:
spreadSheetView1 = CreateView(‘SpreadSheetView’)
extractBlock1Display_1 = Show(extractBlock1, spreadSheetView1, ‘SpreadSheetRepresentation’)
spreadSheetView1.FieldAssociation = ‘Point Data’
What should I do to get its content in a python list?
Thanks in advance!!
You can’t recover the spreadsheet content directly, and in any case, that’s not what you want to do as the spreadsheet does not contain all your data but only what is currently visible.
But, this is of course a solution :
- Simple but costly solution : Fetch
data = servermanager.Fetch(extractBlock1) give you access to the vtk object containing your data. You can then work with it as if you were in vtkPython. It is costly as it requires to transmit the dataset from the server to the client, which is a non-issue if you are working with a built-in server.
- Complex but more paraview-style solution : ProgrammableFilter
You can write your average distribution computation in a Programmable Filter, trigger the computation and then do what you want with the results. It is more efficient as the data stays on the server. Also, you may want to make sure that the computation you are looking to do can’t be done with already existing filters in ParaView.
I tried with the Fetch option but still couldn’t manage to totally solve the problem. I used as example case the output of an extractBlock filter. This is the way I managed to get the points coordinates in a list of tuples:
data = paraview.servermanager.Fetch(extractBlock1,0)
blockData = data.GetBlock(0)
npoints = blockData.GetNumberOfPoints()
points = 
for i in range(npoints):
blockData is a vtkUnstructuredGrid object, I could not find a way to assign directly these coordinates to a list without adopting the shown for loop. Furthermore, I was not able to get the data stored in this grid file (e.g. the Pressure stored in “Array 0 name” in Point Data within the Unstructured grid). I had a look at “vtkUnstructuredGrid Class Reference”, but did not find examples of the case I’m dealing with.
Then use the numpy interface.