# Programmable source - Threshold Unstructured Grid update when changing time step

**URL:** https://discourse.paraview.org/t/programmable-source-threshold-unstructured-grid-update-when-changing-time-step/862
**Category:** ParaView Support
**Created:** [November 7, 2018, 2:46pm UTC](https://discourse.paraview.org/t/programmable-source-threshold-unstructured-grid-update-when-changing-time-step/862 "2018-11-07T14:46:56Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Jimbles](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jimbles/32/474_2.png) [@Jimbles](https://discourse.paraview.org/u/Jimbles)
#### Post date: [November 7, 2018, 2:46pm UTC](https://discourse.paraview.org/t/programmable-source-threshold-unstructured-grid-update-when-changing-time-step/862/1 "2018-11-07T14:46:56Z")

</div>

Hi All,

I am trying to write a programmable source which will update the range of a threshold when changing timesteps. Essentially what I want to do is plot the FWHM as an animation. I was looking back at a script I wrote for Paraview 4, but I thought I would give it a go for the latest version, and try using the paraview.simple module. However, I am getting stuck at the last line, where I need to shallow copy the data from the threshold to the sources output, as I get the error **object has no attribute ‘GetOutput’** which I can see is the case from the paraview.simple documentation. However I am unsure which method I need to use instead!

Here is my script - there is a source called `recon_*` which I references specifically, which might not be the most portable way of doing it.

```
import paraview.simple

s=paraview.simple.FindSource('recon_*')

t=paraview.simple.Threshold(Input=s)

output=self.GetOutputDataObject(0)

cd=s.CellData[0]

DataRange=cd.GetRange(0)

minthres= -10

maxval = -500

#maxval = DataRange[0]

fwhm=DataRange[0] * 0.5

print &quot;fhwm : &quot; + str(fwhm)

if fwhm &lt; minthres:

current_min_thres = minthres

else:

current_min_thres=fwhm

t.ThresholdRange=[maxval, current_min_thres]

print &quot;current thres : &quot; + str(current_min_thres)

output.ShallowCopy(t.GetOutput())

```

Thanks for any help you can offer 🙂

---

<div class="post-metadata">

### Author: ![Kenneth\_Moreland](https://discourse.paraview.org/user_avatar/discourse.paraview.org/kenneth_moreland/32/15033_2.png) [@Kenneth\_Moreland](https://discourse.paraview.org/u/Kenneth_Moreland)
#### Post date: [November 8, 2018, 5:04pm UTC](https://discourse.paraview.org/t/programmable-source-threshold-unstructured-grid-update-when-changing-time-step/862/2 "2018-11-08T17:04:25Z")

</div>

The script you are trying to build does not go in a `Programmable Source` (or `Programmable Filter`). ParaView UI scripts (those that use the `paraview.simple` bindings) are run from the Python Shell (`View` -\> `Python Shell`) or bound to a macro.

These scripts do not have direct access to the data (unless you explicitly download it to the client, which is not a good idea). That is why `GetOutput` is not available. However, when a ParaView UI script creates a filter (like `Threshold`), it will be available in the `Pipeline Browser`, so its data will be available just like any other filter.

---

<div class="post-metadata">

### Author: ![Jimbles](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jimbles/32/474_2.png) [@Jimbles](https://discourse.paraview.org/u/Jimbles)
#### Post date: [November 13, 2018, 3:28pm UTC](https://discourse.paraview.org/t/programmable-source-threshold-unstructured-grid-update-when-changing-time-step/862/3 "2018-11-13T15:28:39Z")

</div>

Oh I see! Rookie error. Thanks for that. I got it working as a programmable filter with the following code  
from vtk import vtkThreshold

```
inp = self.GetInputDataObject(0, 0)
outp = self.GetOutputDataObject(0)

#Get min/max values
aa = inputs[0].CellData
ai = aa[0]
Range = ai.GetRange(0)

#Define threshold filter
thresh = vtkThreshold()
thresh.SetInputData(inp)

minthres= -1
maxval = -500
#maxval = Range[0]
fwhm=Range[0] * 0.5
print "fhwm : " + str(fwhm)

if abs(fwhm) < abs(minthres):
    current_min_thres = minthres

else:
    current_min_thres=fwhm

#Set threshold to half min
thresh.ThresholdBetween(maxval,current_min_thres)
thresh.Update()

outp.ShallowCopy(thresh.GetOutput())
print "current thres : " + str(current_min_thres)

```

It seems like paraview doesnt like the min function?
