# vtk filter for OpenFOAM

**URL:** https://discourse.vtk.org/t/vtk-filter-for-openfoam/3141
**Category:** Support
**Tags:** proposal
**Created:** [April 24, 2020, 5:59am UTC](https://discourse.vtk.org/t/vtk-filter-for-openfoam/3141 "2020-04-24T05:59:46Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![matsubaraDaisuke](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matsubaradaisuke/32/1688_2.png) [@matsubaraDaisuke](https://discourse.vtk.org/u/matsubaraDaisuke)
#### Post date: [April 24, 2020, 5:59am UTC](https://discourse.vtk.org/t/vtk-filter-for-openfoam/3141/1 "2020-04-24T05:59:46Z")

</div>

I want to filter a pressure by thresholding using python-vtk

```
import vtk
filename = "a.foam"

reader = vtk.vtkOpenFOAMReader()
reader.SetFileName(filename)
reader.CreateCellToPointOn()
reader.DecomposePolyhedraOn()
reader.EnableAllCellArrays()
reader.Update()

tArray = vtk_to_numpy(reader.GetTimeValues())
reader.UpdateTimeStep(tArray[-1]) 
reader.Update()

filter_threshold = vtk.vtkThreshold()
filter_threshold.SetInputConnection(reader.GetOutputPort()) 

```

how should I select “pressure” on filter class ?

---

<div class="post-metadata">

### Author: ![matsubaraDaisuke](https://discourse.vtk.org/user_avatar/discourse.vtk.org/matsubaradaisuke/32/1688_2.png) [@matsubaraDaisuke](https://discourse.vtk.org/u/matsubaraDaisuke)
#### Post date: [April 27, 2020, 6:11am UTC](https://discourse.vtk.org/t/vtk-filter-for-openfoam/3141/2 "2020-04-27T06:11:22Z")

</div>

I may resolved

```
import vtk

filename = "case1.foam"
reader = vtk.vtkOpenFOAMReader()
reader.SetFileName(filename)
reader.CreateCellToPointOn()
reader.DecomposePolyhedraOn()
reader.EnableAllCellArrays()
reader.Update()
n_step = reader.GetTimeValues().GetNumberOfValues()
latest_time = reader.GetTimeValues().GetValue(n_step-1)
reader.UpdateTimeStep(latest_time)
reader.Update()

filter_threshold = vtk.vtkThreshold()
filter_threshold.SetInputConnection(reader.GetOutputPort())

#filter_threshold.ThresholdByLower(1)
#filter_threshold.ThresholdByUpper(8700.0)
filter_threshold.ThresholdBetween(0,3600)

#enum FieldAssociations
# {
# FIELD_ASSOCIATION_POINTS,
# FIELD_ASSOCIATION_CELLS,
# FIELD_ASSOCIATION_NONE,
# FIELD_ASSOCIATION_POINTS_THEN_CELLS,
# FIELD_ASSOCIATION_VERTICES,
# FIELD_ASSOCIATION_EDGES,
# FIELD_ASSOCIATION_ROWS,
# NUMBER_OF_ASSOCIATIONS
# };
FIELD_ASSOCIATION_POINTS = 0
FIELD_ASSOCIATION_CELLS = 1
filter_threshold.SetInputArrayToProcess(0,0,0,FIELD_ASSOCIATION_CELLS ,"p")
filter_threshold.Update()
```
