Paraview and Python

Introduction

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.

Overview

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.

Instructions

A simple Python example within ParaView

  • Start ParaView.

  • Start the Python Interpreter Tools → Python Shell

Notes

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)

sphere=Sphere()

Show()

Render()

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.

Hide()

Render()

shrink=Shrink()

Show()

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:

clip=Clip()

Show()

Render()

Or, we could continue in the Python as follows:

clip=Clip()

Hide(shrink)

Show(clip)

Render()

Hide the Plane widget:

Hide3DWidgets(proxy=clip)


Help! (How do we find out what commands are available?)

To see all commands available in ParaView:

dir()

To see all of the options for the Clip creator:

dir(Clip)

To see all of the options for the instance of the clip we created above:

dir(clip)

A better tool to see the available commands for an item in the pipeline is ListProperties, such as:

clip.ListProperties()

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

clip.ClipType.ListProperties()

To see lots of detail on an instance of a command, create the instance and ask for help on that instance..

help(clip)


Change! (Lets look at, and change, something)

Print the Theta Resolution

print(sphere.ThetaResolution)

Change it to 64

sphere.ThetaResolution=64

Show()

Render()


Control input

Lets change the selected filter in the Pipeline Browser:

SetActiveSource(sphere)

Lets delete the clip

Delete(clip)

Lets add a filter to the sphere, without selecting it first

wireframe=ExtractEdges(Input=sphere)

Show()

Render()


Trace Recorder

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.

  • Apply.

  • +Y

  • Clip. Y Normal. Unselect Show Plane. Apply.

  • Color by EQPS.

  • Last timestep.

  • Rescale to Data Range

  • First timestep.

  • 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.