# Use the output of the calculator filter in pvpython

**URL:** https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400
**Category:** ParaView Support
**Created:** [September 23, 2022, 3:02pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400 "2022-09-23T15:02:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![phismith](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@phismith](https://discourse.paraview.org/u/phismith)
#### Post date: [September 23, 2022, 3:02pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/1 "2022-09-23T15:02:57Z")

</div>

Hi All,  
I have been trying to use the output of the Python Calculator for the clip value within pvpython. I would like it to be a variable that can be added to the script, so when I change the formula, the new value will be automatically calculated when the script is run. For example, here is a simple pvpython script I have been working on. Notice the clip1.value is hardcoded in. I would like this value to come from the result of the python calculator. This could also be derived form the python annotation as well.

```auto
from paraview.simple import *

disk_out_refexo = IOSSReader(registrationName='disk_out_ref.exo', FileName=['/.../disk_out_ref/disk_out_ref.exo'])

renderView1 = GetActiveViewOrCreate('RenderView')

disk_out_refexoDisplay = Show(disk_out_refexo, renderView1, 'UnstructuredGridRepresentation')

renderView1.ResetCamera(False)

renderView1.CameraPosition = [0.0, 50.0, 0.0]
renderView1.CameraViewUp = [0.0, 0.0, 1.0]

SetActiveSource(disk_out_refexo)

pythonCalculator1 = PythonCalculator(registrationName='PythonCalculator1', Input=disk_out_refexo)

pythonCalculator1.Expression = 'mean(Temp)'
pythonCalculator1.ArrayName = 'mean_temp'

pythonCalculator1Display = GetDisplayProperties(pythonCalculator1, view=renderView1)

ColorBy(pythonCalculator1Display, ('POINTS', 'Temp'))

pythonCalculator1Display.RescaleTransferFunctionToDataRange(True, False)

pythonCalculator1Display.SetScalarBarVisibility(renderView1, True)

pythonAnnotation1 = PythonAnnotation(registrationName='PythonAnnotation1', Input=disk_out_refexo)

pythonAnnotation1.ArrayAssociation = 'Point Data'
pythonAnnotation1.Expression = 'mean(Temp)'

pythonAnnotation1Display = Show(pythonAnnotation1, renderView1, 'TextSourceRepresentation')

SetActiveSource(pythonAnnotation1)

clip1 = Clip(registrationName='Clip1', Input=pythonCalculator1)

clip1.ClipType = 'Scalar'
clip1.Scalars = ['POINTS', 'Temp']
**clip1.Value = 425**
clip1.Invert = 0

clip1Display = Show(clip1, renderView1, 'UnstructuredGridRepresentation')

clip1Display.Representation = 'Surface'

Hide(disk_out_refexo)
Hide(pythonCalculator1)

```

---

<div class="post-metadata">

### Author: ![Kenichiro-Yoshimi](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/k/ecc23a/32.png) [@Kenichiro-Yoshimi](https://discourse.paraview.org/u/Kenichiro-Yoshimi)
#### Post date: [September 26, 2022, 10:20am UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/2 "2022-09-26T10:20:38Z")

</div>

Hi,

In such cases, `servermanager.Fetch` is available. For example, it could be as follows:

```python
calc_vtk = servermanager.Fetch(pythonCalculator1)
mean_temp = calc_vtk.GetPointData().GetArray('mean_temp').GetTuple1(0)

clip1 = Clip(registrationName=‘Clip1’, Input=pythonCalculator1)

clip1.ClipType = ‘Scalar’
clip1.Scalars = [‘POINTS’, ‘Temp’]
clip1.Value = mean_temp
clip1.Invert = 0

```

---

<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 26, 2022, 1:28pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/3 "2022-09-26T13:28:13Z")

</div>

Phil,

There isn’t a direct way to plug a value computed by a **Calculator** into a property of a filter. Since you are scripting, it is a little bit easier. **Python Annotation** is actually nice here, because it produces what is expected to be a single string value.

First, you’ll need to update the pipeline up to PythonAnnotation1:

```python
pythonAnnotation1.UpdatePipeline()

```

Then, you’ll need to fetch the data value from it:

```python
stringValue = FetchData(pythonAnnotation1)[0].GetRowData().GetAbstractArray(0).GetValue(0)

```

Use `GetRowData()` because the dataset output of the **Python Annotation** filter is a `vtkTable`. Use `GetAbstractArray()` because a `vtkStringArray` is an abstract array and not a simple `vtkDataArray`. Use `GetValue(0)` to get the one string in the `vtkStringArray`.

You can convert the string value to float with

```python
float(stringValue)

```

and plug the result into `clip1.Value`.

Hope that helps!

---

<div class="post-metadata">

### Author: ![phismith](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@phismith](https://discourse.paraview.org/u/phismith)
#### Post date: [September 27, 2022, 12:54pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/4 "2022-09-27T12:54:04Z")

</div>

Hi Cory,  
Yes this worked for builtin, but when using a remote server, it crashes ParaView. Is there a way for us to get that value using remote server?

@cory.quammen

Thanks as always,  
-Phil

---

<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 27, 2022, 5:14pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/5 "2022-09-27T17:14:57Z")

</div>

Hmmm, `FetchData` should handle both built-in and remote servers. Testing locally, I that seems to be the case.

I suggest trying @Kenichiro-Yoshimi’s solution, which is a similar approach. Note that `Fetch` (different from the `FetchData` I mentioned) is defined in `paraview.servermanager.Fetch`.

---

<div class="post-metadata">

### Author: ![phismith](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@phismith](https://discourse.paraview.org/u/phismith)
#### Post date: [September 27, 2022, 5:24pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/6 "2022-09-27T17:24:03Z")

</div>

Hi Cory… Yes that was may mistake your solution appears to work for both now. I just made a stupid mistake and now all works.

Thanks again!

---

<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 27, 2022, 6:41pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/7 "2022-09-27T18:41:01Z")

</div>

@vgweirs Greg, I know you were having issues with fetches a while back. Sounds like it now works.  
Alan

---

<div class="post-metadata">

### Author: ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)
#### Post date: [September 7, 2023, 3:05pm UTC](https://discourse.paraview.org/t/use-the-output-of-the-calculator-filter-in-pvpython/10400/8 "2023-09-07T15:05:20Z")

</div>

Hello,  
I am little bit lost with this, from what I understand we extract the data and transform it to vtk, and then transform it into the values.  
I was trying to get for example, the resulting values of a slice with different offset.  
the slice I defined as it follows:

```auto
slice1 = Slice(registrationName='Slice1', Input=inlet)
slice1.SliceType = 'Plane'
slice1.HyperTreeGridSlicer = 'Plane'
slice1.SliceType.Origin = [0.0, 0.0, 0.0]
slice1.HyperTreeGridSlicer.Origin = [0.0, 0.0, 0.0]
slice1.SliceOffsetValues = [-0.03534826681814725, -0.03390548041740654, -0.03246269401666584, -0.031019907615925137, -0.02957712121518443, -0.028134334814443728, -0.026691548413703026, -0.02524876201296232, -0.023805975612221614, -0.02236318921148091, -0.02092040281074021, -0.019477616409999503, -0.0180348300092588, -0.016592043608518094, -0.015149257207777392, -0.013706470807036686, -0.012263684406295983, -0.01082089800555528, -0.009378111604814575, -0.007935325204073872, -0.0064925388033331664, -0.005049752402592464, -0.003606966001851758, -0.002164179601111052, -0.000721393200370353, 0.000721393200370353, 0.002164179601111059, 0.003606966001851758, 0.005049752402592464, 0.00649253880333317, 0.007935325204073876, 0.009378111604814575, 0.01082089800555528, 0.012263684406295987, 0.013706470807036686, 0.015149257207777392, 0.016592043608518098, 0.018034830009258804, 0.019477616409999503, 0.02092040281074021, 0.022363189211480915, 0.023805975612221614, 0.02524876201296232, 0.026691548413703026, 0.02813433481444373, 0.029577121215184438, 0.031019907615925144, 0.032462694016665836, 0.03390548041740654, 0.03534826681814725]
slice1.SliceType.Normal = [0.0, 1.0, 0.0]

```

slice1 has point and cell data, then in my script I use the following lines:

```auto
calc_vtk = servermanager.Fetch(slice1)
values= calc_vtk.GetPointData().GetArray('k').GetTuple1(0)

```

and I am getting the error on ‘GetPointData’ already  
I read it around the forum that there is problems with multiblocks so in any case I tried to merge blocks filter so:

```auto
calc_vtk = servermanager.Fetch(MergeBlocks(registrationName='MergeBlocks2', Input=slice1))
calc_vtk.GetPointData().GetArray('k').GetTuplel()

```

and now I am getting an error over the GetTuplel()  
thanks in advance
