Paraview and Python
ParaView offers a rich and powerful Python interface. This allows users to automate processing of their data, and gives access to powerful tools in the Visualization Tool Kit (VTK). This tutorial will describe ParaView and Python. It shows a user how to drive ParaView using Python commands, and how to automate the creation and use of these commands.
ParaView is a client/ server architecture. The client includes the ParaView GUI and display. The server reads the user's data, processes the data, and passes these images to the client. We can use Python to control ParaView either in the GUI, at the client level, or directly on the server.
A simple Python example within ParaView
Start the Python Interpreter Tools → Python Shell
You can copy commands from elsewhere and paste them into the Python Shell.
Python is case sensitive. Be sure to use correct capitalization as shown below.
Python is indent sensitive. Be sure to not indent, as shown below.
Lets create and display a sphere.
(Type the following into the Python Shell)
We have now created a sphere in the pipeline, turned on it's visibility, and re-rendered.
Next, lets add a shrink filter. We hide the sphere, add the shrink filter, and re-render.
ParaView will allow us to use either the GUI controls or Python. For instance:
Select the Sphere in the pipeline browser.
In the Python Shell, type the following:
Or, we could continue in the Python as follows:
Hide the Plane widget:
Help! (How do we find out what commands are available?)
To see all commands available in ParaView:
To see all of the options for the Clip creator:
To see all of the options for the instance of the clip we created above:
A better tool to see the available commands for an item in the pipeline is ListProperties, such as:
Note that this doesn't work on instantiated controls, such as the camera. Use dir() for controls such as camera.
And, to see the different properties of the ClipType variable, use
To see lots of detail on an instance of a command, create the instance and ask for help on that instance..
Change! (Lets look at, and change, something)
Print the Theta Resolution
Change it to 64
Lets change the selected filter in the Pipeline Browser:
Lets delete the clip
Lets add a filter to the sphere, without selecting it first
ParaView includes a tool to automatically generate Python scripts for us. It is called the Trace Recorder. An example is as follows.
Read in can.exo, clip can, paint by EQPS, change the camera to +Y, write out a screenshot and write out a movie
Tools → Start Trace Select Show Incremental Trace.
File → Open. Open can.exo. OK.
Turn all variables on.
Clip. Y Normal. Unselect Show Plane. Apply.
Color by EQPS.
Rescale to Data Range
File → Save Screenshot. Save as .png.
File → Save Animation. Save as .avi.
Tools → Stop Trace
File → Save. Save to a known location.
Another way to find Python for ParaView is through Save State. This should be a last resort, but it may include commands that the Trace Recorder missed. File → Save State → Python State File.