3

Using Python to interface with Paraview, I want to get the "Points" data from an integrate variable filter.

I tried the GetArray("Points") but it can't find it even though you can clearly see it in the GUI if you go to spreadsheet view.

My code is below. With the GUI approach I get for Point ID = 0 the array "Points" has three values (0.54475, -1.27142e-18, 4.23808e-19) which makes sense because the default arrow is symmetric in y and z.

Is there any way to get the value 0.54475 inside python?

MWE

#Import Paraview Libraries
#import sys
#sys.path.append('Path\\To\\Paraview\\bin\\Lib\\site-packages')
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
# create a new 'Arrow'
arrow1 = Arrow()
# create a new 'Integrate Variables'
integrateVariables1 = IntegrateVariables(Input=arrow1)
pdata = paraview.servermanager.Fetch(integrateVariables1).GetPointData()

print pdata.GetArray("Points") # prints None
Miguel
  • 1,293
  • 1
  • 13
  • 30

1 Answers1

4

You are very close. For all other arrays, you can access the value using the method you have written.

However VTK treats the point coordinates slightly differently, so the code you need for the point coordinates is:

arrow1 = Arrow()
integrateVariables1 = IntegrateVariables(Input=arrow1)
integrated_filter = paraview.servermanager.Fetch(integrateVariables1)
print integrated_filter.GetPoint(0)

This gives me: (0.5447500348091125, -1.2714243711743785e-18, 4.238081064918634e-19)

I would also suggest that you might want to do this in a Python Programmable Filter. Passing the filter from the server back to the client is not the best practice, and it is preferred to do all calculation on the server.

Stuart Buckingham
  • 1,574
  • 16
  • 25
  • 1
    This is a good answer, but I disagree with the last statement about using the programmable filter. Most of the time I would also argue that you should avoid using Fetch to pull data from server to client, but the result of Integrate Variables is an exception. The results of Integrate Variables is a single item (smaller than the range info automatically downloaded to the client), and it is a common use case in ParaView batch processing to do the heavy computation on the server side and then pull in an aggregated value (like the results of Integrate Variables) to the client. – Kenneth Moreland Jan 03 '18 at 13:41
  • Kenneth, I agree with you about fetching an integrate variables not being a significant amount of data. I was just trying to warn the OP about getting into the habit of using Fetch, as using it on filters with large amounts of data will be extremely detrimental. Obviously it depends on what the actual use case is, but because Programmable Filters have the same access to stdout, printing can be done on client or server. For more involved processing of the result, fetch is the best option. – Stuart Buckingham Jan 03 '18 at 14:47
  • 1
    Thank you, it worked very well. I actually want to use the result as the origin of a slice, which I will then use as the source of a streamline filter with a custom source. I'll keep in mind the recommendation of using Fetch carefully in the future. – Miguel Jan 03 '18 at 21:32