Forge Analytics

Accessing Data in ParaView

Instructions for accessing data through ParaView's Python API.

Overview

In order to perform operations on data in ParaView, we first need programmatic access to that data.

Many function calls in the ParaView Python API will return an object reference to the data or filter that’s been created or loaded.

However, at times, it will be necessary to establish a variable reference to a Source in the Proxy Manager by name. Below are instructions for doing so.

Notes

For the purposes of this article, we will be using Paraview 5.4.1.

For installation instructions, please see the guide for CPU-based rendering or GPU-based rendering.

For help running ParaView scripts, please see the batch-execution instructions.

Instructions

Data in ParaView’s Python API is represented primarily through two types:

Sources contain data, or filter outputs and representations are how sources are displayed in a given view.

As always, first make sure the paraview.simple module has been imported to any Python script for ParaView:

import paraview.simple

Sources

Source variables are generally established as return values from a given function. Usually this is either a data loader, or a filter.

For example, we can establish a Source variable from the OpenFOAM reader:

case = paraview.simple.OpenFOAMReader(FileName='/path/to/motorbike/run.foam')

However, there may be some instances where we lose access to the case variable or it goes out-of-scope in our Python script.

When this happens, we have some options for re-establishing the reference.

First, if we know the name used in the proxy manager / pipeline browser, we can get the Source object by name:

source = paraview.simple.FindSource(name)

Alternatively, if we know the Source object of interest is active (the equivalent of the highlighted Source in the Pipeline Browser), we can get a variable for the active Source:

source = paraview.simple.GetActiveSource()

In our scripts, we can also set and clear the active Source, as needed:

paraview.simple.SetActiveSource(source)
paraview.simple.ClearSelection()

Finally, we can get a dictionary containing all Sources for the session with:

all_sources = paraview.simple.GetSources()

Representations

Like Sources, we can also collect all Representations for the session:

all_representations = paraview.simple.GetRepresentations()

or identify a specific Representation by its Source proxy and View:

representation = paraview.simple.GetRepresentation(proxy=source, view=my_view)

Have a Question?

Contact Us