Issue with programmable filter in ParaView 5.9

Hi,

I was running in ParaView 5.9 RC2 this programmable filter which calculates averages of all cells along a given axis, within a defined domain.This works in ParaView 5.5, but not in 5.9:

error 1 : xrange is not defined

error 2 (if i change xrange to range)

Traceback (most recent call last):
File “”, line 22, in
File “”, line 24, in RequestData
TypeError: ‘numpy.float64’ object cannot be interpreted as an integer

programmable filter code:

import numpy as np 
import vtk
 
input=self.GetPolyDataInput()
numPoints =input.GetNumberOfPoints() 
cell_idx_x =np.zeros((numPoints,1),dtype='i') 
cell_idx_y =np.zeros((numPoints,1),dtype='i')
cell_idx_z =np.zeros((numPoints,1),dtype='i')
avg_V=np.zeros((numPoints,1),dtype='f')
cell_size = 0.001
y_min=0.0
z_min=0.0
seuil_epg = 0.001
for i in range(0, numPoints):
    coord =input.GetPoint(i) 
    x, y, z =coord[:3]
    cell_idx_y[i] =((y-y_min)-cell_size/2)/cell_size
    cell_idx_z[i] =((z-z_min)-cell_size/2)/cell_size 
output.PointData.append(cell_idx_y, "idx_Y") 
output.PointData.append(cell_idx_z, "idx_Z")
nb_cell_y=max(cell_idx_y)+1
nb_cell_z=max(cell_idx_z)+1
sum_V=np.zeros((nb_cell_y,nb_cell_z),dtype='f')
nb_vert_cell=np.zeros((nb_cell_y,nb_cell_z),dtype='f')
data =input.GetPointData()
Vel =data.GetArray('V_x')
EPG = data.GetArray('Scalar_2') 
for i in range(0,numPoints):
    phi = EPG.GetValue(i)
    if ( phi > seuil_epg ) :
        V =Vel.GetValue(i)
        nb_vert_cell[cell_idx_y[i],cell_idx_z[i]]=nb_vert_cell[cell_idx_y[i],cell_idx_z[i]]+1
        sum_V[cell_idx_y[i],cell_idx_z[i]]=sum_V[cell_idx_y[i],cell_idx_z[i]]+V
for i in range(0,numPoints):
    if ( sum_V[cell_idx_y[i],cell_idx_z[i]] > 0 ):
        avg_V[i]=sum_V[cell_idx_y[i],cell_idx_z[i]]/nb_vert_cell[cell_idx_y[i],cell_idx_z[i]]
    else:
        avg_V[i]=0
output.PointData.append(avg_V, "avg_V")

Could you let me know what should I change to make it work in the new versions of ParaView (5.8 also does not allow this filter to work…)

Thanks a lot for the help!

Eric

xrange is a Python2 method, we are using Python3 now.

np.zeros((nb_cell_y,nb_cell_z),dtype='f')

This method accepts int accoording to the doc
https://numpy.org/doc/stable/reference/generated/numpy.zeros.html

Unrelated to ParaView.

sum_V=np.zeros((int(nb_cell_y),int(nb_cell_z)),dtype=‘f’)

nb_vert_cell=np.zeros((int(nb_cell_y),int(nb_cell_z)),dtype=int)

solved it. Thanks