# Programmable Filter, Integrate data along direction

**URL:** https://discourse.paraview.org/t/programmable-filter-integrate-data-along-direction/13002
**Category:** ParaView Support
**Created:** [October 6, 2023, 2:36pm UTC](https://discourse.paraview.org/t/programmable-filter-integrate-data-along-direction/13002 "2023-10-06T14:36:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Philip\_Moloney](https://discourse.paraview.org/user_avatar/discourse.paraview.org/philip_moloney/32/12559_2.png) [@Philip\_Moloney](https://discourse.paraview.org/u/Philip_Moloney)
#### Post date: [October 6, 2023, 2:36pm UTC](https://discourse.paraview.org/t/programmable-filter-integrate-data-along-direction/13002/1 "2023-10-06T14:36:05Z")

</div>

Hi!

I am trying to use paraview to integrate my structured cell data along a grid direction. I have a spherical grid and I want to display the radial integral somehow. I am trying to use the programmable filter to do this, but when I load in the cell data, the cells are stored as a 1D array rather than maintaining the grid structure (i.e., [radial slice, azimuthal slice, polar slice]). Is there a way to load in the data while mainting the grid structure to the filter, or transform the 1D data into 3D soo I can do the integration?

Also, is there an online list of the methods and attributes of the programmable filter input/output objects as I find the structure quite confusing!

Thanks in advance!

---

<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: [October 6, 2023, 2:38pm UTC](https://discourse.paraview.org/t/programmable-filter-integrate-data-along-direction/13002/2 "2023-10-06T14:38:44Z")

</div>

> spherical grid

There is no concept of spherical grid in VTK, afaik

> [@Philip\_Moloney](#):
>
> mainting the grid structure to the filter, or transform the 1D data into 3D soo I can do the integration?

No, but since the structure is implicit, you can compute the indices quite easily

---

<div class="post-metadata">

### Author: ![jfavre](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/j/b5ac83/32.png) [@jfavre](https://discourse.paraview.org/u/jfavre)
#### Post date: [October 7, 2023, 8:05am UTC](https://discourse.paraview.org/t/programmable-filter-integrate-data-along-direction/13002/3 "2023-10-07T08:05:42Z")

</div>

you might find some useful pointers in this older post. [https://www.kitware.com/paraviews-python-programmable-filters-in-geophysics/](https://www.kitware.com/paraviews-python-programmable-filters-in-geophysics/)  
numpy array reshape() will be your best ally.

---

<div class="post-metadata">

### Author: ![Philip\_Moloney](https://discourse.paraview.org/user_avatar/discourse.paraview.org/philip_moloney/32/12559_2.png) [@Philip\_Moloney](https://discourse.paraview.org/u/Philip_Moloney)
#### Post date: [October 11, 2023, 10:16am UTC](https://discourse.paraview.org/t/programmable-filter-integrate-data-along-direction/13002/4 "2023-10-11T10:16:27Z")

</div>

Thank you very much! I have managed to get the integration working by using reshape, setting output to be same as input and then setting each radial slice to be the radial integral, i.e.

```auto
import numpy as np

executive = self.GetExecutive()
outInfo = executive.GetOutputInformation(0)
exts = [executive.UPDATE_EXTENT().Get(outInfo, i) for i in range(6)]

nx = exts[1]-exts[0]
ny = exts[3]-exts[2]
nz = exts[5]-exts[4]

dat_str = inputs[0].CellData.keys()[0]
data_1d = inputs[0].CellData[dat_str]
data_3d = np.reshape(data_1d,[nz,ny,nx])

data_integr_3d = np.zeros_like(data_3d)
for ix in range(nx):
    data_integr_3d[:,:,ix] = np.sum(data_3d,axis=2)

data_integr_1d = np.reshape(data_integr_3d,nx*ny*nz)
output.CellData.append(data_integr_1d,"integ_x")

```
