# Extracting a selection based on conditions

**URL:** https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344
**Category:** ParaView Support
**Tags:** python
**Created:** [August 1, 2019, 10:07pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344 "2019-08-01T22:07:28Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![AlD](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ald/32/5962_2.png) [@AlD](https://discourse.paraview.org/u/AlD)
#### Post date: [August 1, 2019, 10:07pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/1 "2019-08-01T22:07:28Z")

</div>

Hello I’d like to know how to select and extract a set of points based on a condition (ie y \> 5 && y \< 9) for instance. I’d like to know how to do this both manually and how to add it to my python script.

The data is in a ‘table to points’ format, with the xyz in a single blob which makes it difficult to select by a position.

 ![parashot](https://discourse.paraview.org/uploads/default/original/2X/5/58561463b6e0d704fd22eef94eec7d4dd0c8075c.png)

---

<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: [August 1, 2019, 10:39pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/2 "2019-08-01T22:39:13Z")

</div>

You can use the _Find Data_ dialog (Edit -\> Find Data) to query points. Set it up with

Find “Point(s)” from “TableToPoints1”  
“Query” “is” “np.logical\_and(y \> 5, y \< 9)”

Then click “Run Selection Query”.

Change the “Show:” field to “Point(s)”.

There currently isn’t a way to set this up with a Python script, but we will be working on adding such a capability for ParaView 5.8.

---

<div class="post-metadata">

### Author: ![AlD](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ald/32/5962_2.png) [@AlD](https://discourse.paraview.org/u/AlD)
#### Post date: [August 1, 2019, 11:01pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/3 "2019-08-01T23:01:07Z")

</div>

It says

failed to evaluate expression ‘np.logical\_and(y \> 5, y \< 9)’

---

<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: [August 1, 2019, 11:06pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/4 "2019-08-01T23:06:11Z")

</div>

Oops, right, you don’t have an array available named ‘y’.

This expression should work:

`np.logical_and(points[:,1] > 5, points[:,1] < 9)`

---

<div class="post-metadata">

### Author: ![AlD](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ald/32/5962_2.png) [@AlD](https://discourse.paraview.org/u/AlD)
#### Post date: [August 1, 2019, 11:12pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/5 "2019-08-01T23:12:07Z")

</div>

Great is there a way to extract out and visualize the subset? Pressing extract selection gives an empty spreadsheet.

---

<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: [August 1, 2019, 11:21pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/6 "2019-08-01T23:21:15Z")

</div>

If the spreadsheet is empty, it means no points satisfied the selection criteria. You may need to adjust the ranges of inclusion in the query.

Once you have some points selected, you can choose Filters -\> Extract Selection and click Apply. That will extract the points and you will see them in the Render View.

---

<div class="post-metadata">

### Author: ![AlD](https://discourse.paraview.org/user_avatar/discourse.paraview.org/ald/32/5962_2.png) [@AlD](https://discourse.paraview.org/u/AlD)
#### Post date: [August 2, 2019, 12:26am UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/7 "2019-08-02T00:26:21Z")

</div>

Thanks for your help so far. Is there a simple way to extract all points a certain distance range from another point? like from 0,0,0. The closest seems to be a manually used ruler but theres no relevant examples of use I can find. Doing it with simple python code doesn’t seem to work either.

---

<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: [August 5, 2019, 2:33pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/8 "2019-08-05T14:33:32Z")

</div>

You can use this expression the Find Data dialog:

```auto
mag(points - [.2, -.3, -.3]) < 0.3

```

where [0.2, -0.3, -0.3] is the query point and 0.3 is the query radius.

---

<div class="post-metadata">

### Author: ![opengeostat](https://discourse.paraview.org/user_avatar/discourse.paraview.org/opengeostat/32/3413_2.png) [@opengeostat](https://discourse.paraview.org/u/opengeostat)
#### Post date: [June 19, 2020, 6:33pm UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/9 "2020-06-19T18:33:28Z")

</div>

Is there a way of using fields of type string? I get an error if I try queries like `VARIAB =='ASTRING'`

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 22, 2020, 3:06am UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/10 "2020-06-22T03:06:35Z")

</div>

Please open your own thread.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.paraview.org/user_avatar/discourse.paraview.org/mwestphal/32/17_2.png) [@mwestphal](https://discourse.paraview.org/u/mwestphal)
#### Post date: [June 22, 2020, 3:06am UTC](https://discourse.paraview.org/t/extracting-a-selection-based-on-conditions/2344/11 "2020-06-22T03:06:38Z")

</div>


