using "find data" aka "extract selection" with python scripting

Hi there,
I am trying to script some data processing in paraview. Specifically, importing a vti file and using “find data matching various criteria” to find the points which meet my criteria (eg: propertyX <= 0). When I using “Find Data” and run a python trace however, what I see is the following:

# create a new 'Extract Selection'
extractSelection1 = ExtractSelection(Input=dataVTI,

# show data in view
extractSelection1Display = Show(extractSelection1, renderView1)

# trace defaults for the display properties.
extractSelection1Display.Representation = 'Surface'
extractSelection1Display.ColorArrayName = [None, '']
extractSelection1Display.OSPRayScaleArray = 'geometry'
extractSelection1Display.OSPRayScaleFunction = 'PiecewiseFunction'
extractSelection1Display.SelectOrientationVectors = 'None'
extractSelection1Display.ScaleFactor = 0.21600012183189393
extractSelection1Display.SelectScaleArray = 'None'
extractSelection1Display.GlyphType = 'Arrow'
extractSelection1Display.GlyphTableIndexArray = 'None'
extractSelection1Display.DataAxesGrid = 'GridAxesRepresentation'
extractSelection1Display.PolarAxes = 'PolarAxesRepresentation'
extractSelection1Display.ScalarOpacityUnitDistance = 0.6655801979167395
extractSelection1Display.GaussianRadius = 0.10800006091594697
extractSelection1Display.SetScaleArray = ['POINTS', 'geometry']
extractSelection1Display.ScaleTransferFunction = 'PiecewiseFunction'
extractSelection1Display.OpacityArray = ['POINTS', 'geometry']
extractSelection1Display.OpacityTransferFunction = 'PiecewiseFunction'

# init the 'GridAxesRepresentation' selected for 'DataAxesGrid'
extractSelection1Display.DataAxesGrid.XTitleColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.DataAxesGrid.YTitleColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.DataAxesGrid.ZTitleColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.DataAxesGrid.XLabelColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.DataAxesGrid.YLabelColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.DataAxesGrid.ZLabelColor = [0.3333333333333333, 0.0, 1.0]

# init the 'PolarAxesRepresentation' selected for 'PolarAxes'
extractSelection1Display.PolarAxes.PolarAxisTitleColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.PolarAxes.PolarAxisLabelColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.PolarAxes.LastRadialAxisTextColor = [0.3333333333333333, 0.0, 1.0]
extractSelection1Display.PolarAxes.SecondaryRadialAxesTextColor = [0.3333333333333333, 0.0, 1.0]

# hide data in view
Hide(dataVTI, renderView1)

# update the view to ensure updated data information

I do not see anywhere in the python code where propertyX <= 0 is set. However, in the Properties of the ‘ExtractSelection1’ I see the following:

Type: Query
propertyX <= 0
Elements: Points

The points are correctly extracted. However I can only do this manually, I have not been able to automate this.

Can someone please explain how to create this extractSelection filter to specify the selection from python?

many thanks in advance

Kitware folk? Am I correct that the trace recorder doesn’t trace find data currently?

That is correct:

I found a way to ‘find data’ using the following python code and get access to the arrays:

import vtk
import numpy as np
from vtk.numpy_interface import dataset_adapter as dsa

filename = 'file.vti'

# Read the file
reader = vtk.vtkXMLImageDataReader()

reader.PointArrayStatus = ['geometry', 'propertyX', 'propertyY']

usg = dsa.WrapDataObject(reader.GetOutput())
X = usg.PointData['propertyX'] 
Y = usg.PointData['propertyY']

then by using np.where(X > 0.0) I can filter the data I want.

However, I am missing the coordinate data.

In paraview I have access to ‘Point ID’, ‘Structured Coordinates’[tuple], ‘geometry’, ‘propertyX’, ‘propertyY’.

After running find data in paraview I have:
’Point ID’, ‘vtkOriginalPointIds’, ‘Points’[tuple], ‘geometry’, ‘propertyX’, ‘propertyY’.

Could someone please help to access the coordinate data in python and convert these to physical coordinates?

1 Like

In case someone needs this in the future: (this works with the above code)

polyData = vtk.vtkPolyData()
polyData = reader.GetOutput()

coordinates = []
for i in range(polyData.GetNumberOfPoints()):

will create a list of coordinates for each point

based on:

the python recipe for your question would be:

reader = GetActiveSource() # make sure you define your active reader.

selection.QueryString=“propertyX <= 0”
selection.FieldType = ‘POINT’

mySelection = ExtractSelection(Input=reader, Selection=selection)


This seems relevant to the issue I was having with python state files.

I posted about this recently myself (I searched but did find this thread):

But I was able to figure out the code needed because I found out that the query selection is caught by an incremental trace.

I was using 5.9.0 RC3.