# Creating a programmable filter that slices and then averages over this slice

**URL:** https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955
**Category:** ParaView Support
**Created:** [December 10, 2022, 10:30am UTC](https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955 "2022-12-10T10:30:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Michael\_Henzinger](https://discourse.paraview.org/user_avatar/discourse.paraview.org/michael_henzinger/32/10552_2.png) [@Michael\_Henzinger](https://discourse.paraview.org/u/Michael_Henzinger)
#### Post date: [December 10, 2022, 10:30am UTC](https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955/1 "2022-12-10T10:30:18Z")

</div>

Greetings!  
I want to create a programmable filter that slices my unstructured dataset and then applies a weighted average on this slice. The output would be a table with the value of this weighted average and the x-coordinate of the cut.

I succeeded with the second part when I used a slice as an input. But I struggle to find a way to manually slice an unstructured dataset. Did anybody accomplish this already and can nod me in the right direction? Below is the code I used for the averaging.

Thanks,  
Michael

```auto
data = inputs[0]
#print(data.Points[0,0])

totpressure = data.PointData['Total_Pressure']
density = data.PointData['Density']
xcoords = data.Points[0, 0]
massavgtotpressure = sum(totpressure*density)/sum(density)
xcoords = sum(xcoords)

output.RowData.append(massavgtotpressure, 'P_tot')
output.RowData.append(xcoords, 'x')

```

---

<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: [December 12, 2022, 8:24am UTC](https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955/2 "2022-12-12T08:24:09Z")

</div>

Hi @Michael_Henzinger

Why reimplement the slice when you can just use the slice filter ?

Best,

---

<div class="post-metadata">

### Author: ![Michael\_Henzinger](https://discourse.paraview.org/user_avatar/discourse.paraview.org/michael_henzinger/32/10552_2.png) [@Michael\_Henzinger](https://discourse.paraview.org/u/Michael_Henzinger)
#### Post date: [December 13, 2022, 10:20am UTC](https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955/3 "2022-12-13T10:20:06Z")

</div>

Hello, @mwestphal.

I was thinking of slicing in multiple locations and then generating a table with the averaged values. I guess I did not want to do this manually for every location so I want to automate that process.

Kind Regards,  
Michael

---

<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: [December 13, 2022, 10:34am UTC](https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955/4 "2022-12-13T10:34:07Z")

</div>

The slice is a complicated filter, I’d suggest to use python scripting to do that instead of using prog filter for this part.

---

<div class="post-metadata">

### Author: ![Michael\_Henzinger](https://discourse.paraview.org/user_avatar/discourse.paraview.org/michael_henzinger/32/10552_2.png) [@Michael\_Henzinger](https://discourse.paraview.org/u/Michael_Henzinger)
#### Post date: [December 13, 2022, 10:45am UTC](https://discourse.paraview.org/t/creating-a-programmable-filter-that-slices-and-then-averages-over-this-slice/10955/5 "2022-12-13T10:45:11Z")

</div>

Thank you for your quick response. I will make use of scripting then.

I have to say it’s not the most satisfying answer to my question but it is a practical one. 😁
