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

**URL:** https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562
**Category:** ParaView Support
**Tags:** python
**Created:** [September 12, 2018, 9:41am UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562 "2018-09-12T09:41:59Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![J\_R-J](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@J\_R-J](https://discourse.paraview.org/u/J_R-J)
#### Post date: [September 12, 2018, 9:41am UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/1 "2018-09-12T09:41:59Z")

</div>

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,
Selection=None)

# 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
renderView1.Update()

```

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  
Jesse

---

<div class="post-metadata">

### Author: ![wascott](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/w/8e8cbc/32.png) [@wascott](https://discourse.paraview.org/u/wascott)
#### Post date: [September 13, 2018, 8:38pm UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/2 "2018-09-13T20:38:46Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.paraview.org/user_avatar/discourse.paraview.org/cory.quammen/32/11193_2.png) [@cory.quammen](https://discourse.paraview.org/u/cory.quammen)
#### Post date: [September 13, 2018, 10:35pm UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/3 "2018-09-13T22:35:49Z")

</div>

> [@wascott](#):
>
> Am I correct that the trace recorder doesn’t trace find data currently?

That is correct: [https://gitlab.kitware.com/paraview/paraview/issues/16836](https://gitlab.kitware.com/paraview/paraview/issues/16836)

---

<div class="post-metadata">

### Author: ![J\_R-J](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@J\_R-J](https://discourse.paraview.org/u/J_R-J)
#### Post date: [October 1, 2018, 9:17am UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/4 "2018-10-01T09:17:07Z")

</div>

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.SetFileName(filename)
reader.Update()

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?

---

<div class="post-metadata">

### Author: ![J\_R-J](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/dc4da7/32.png) [@J\_R-J](https://discourse.paraview.org/u/J_R-J)
#### Post date: [October 1, 2018, 10:48am UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/5 "2018-10-01T10:48:54Z")

</div>

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()):
	coordinates.append(polyData.GetPoint(i))

```

will create a list of coordinates for each point

based on: [https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataGetPoint](https://www.vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataGetPoint)

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [October 1, 2018, 11:47am UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/6 "2018-10-01T11:47:31Z")

</div>

the python recipe for your question would be:

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

selection=SelectPoints()  
selection.QueryString=“propertyX \<= 0”  
selection.FieldType = ‘POINT’  
selection.UpdatePipelineInformation()

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

---

<div class="post-metadata">

### Author: ![woodscn](https://discourse.paraview.org/user_avatar/discourse.paraview.org/woodscn/32/3226_2.png) [@woodscn](https://discourse.paraview.org/u/woodscn)
#### Post date: [January 12, 2021, 9:04pm UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/7 "2021-01-12T21:04:18Z")

</div>

@cory.quammen

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

---

<div class="post-metadata">

### Author: ![theodorebaltis](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/t/e480ec/32.png) [@theodorebaltis](https://discourse.paraview.org/u/theodorebaltis)
#### Post date: [January 14, 2021, 3:33am UTC](https://discourse.paraview.org/t/using-find-data-aka-extract-selection-with-python-scripting/562/8 "2021-01-14T03:33:07Z")

</div>

I posted about this recently myself (I searched but did find this thread):  
[https://discourse.paraview.org/t/query-selection-not-captured-in-python-state-file/6182](https://discourse.paraview.org/t/query-selection-not-captured-in-python-state-file/6182)

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.
