[Paraview] Bug with PV 5.2 with python max / min
Cory Quammen
cory.quammen at kitware.com
Thu Nov 17 09:49:17 EST 2016
> As a workaround, you can still use the builtin min() function with
>
> from __builtin__ import min as min, max as max
Actually, you should be able to just use
from __builtin__ import min, max
Also, I filed a bug report here:
https://gitlab.kitware.com/paraview/paraview/issues/17024
Cory
> HTH,
> Cory
>
> On Thu, Nov 17, 2016 at 6:22 AM, Guillaume Jacquenot
> <guillaume.jacquenot at gmail.com> wrote:
>> Dear all,
>>
>> I have just tested the new paraview 5.2 with a python script.
>>
>> With versions 4.4.0 and 5.1.2, this script worked fine.
>>
>> In this script, I have a ProgrammableSource where I compute the maximum
>> values of two scalars with max function.
>>
>> The code looks like this in the Script of the ProgrammableSource
>>
>> maxValue = max(1,2)
>>
>> This instruction creates an error: instead of using built-in max function,
>> ParaView5.2 uses a max function defined with vtk and numpy:
>>
>> ParaView-5.2.0-Qt4-OpenGL2-Windows-64bit\bin\Lib\site-packages\vtk\numpy_interface\algorithms.py
>> line 315
>>
>> And apparently, it does not work (whereas in 4.4.0 and 5.1.2 it worked,
>> maybe these versions did not use this function).
>>
>> For the time being, I have created a dirty workaround where I have defined
>> new min / max functions
>>
>> fmin = lambda x,y:x if x<y else y
>> fmax = lambda x,y:x if x>y else y
>>
>>
>>
>> Below are the message error and a python script that reproduces the bug
>>
>>
>> Traceback (most recent call last):
>> File "<string>", line 20, in <module>
>> File "<string>", line 326, in RequestData
>> File
>> "D:\ParaView-5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\vtk\numpy_interface\algorithms.py",
>> line 354, in max
>> return _global_func(MaxImpl(), array, axis, controller)
>> File
>> "D:\ParaView-5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\vtk\numpy_interface\algorithms.py",
>> line 182, in _global_func
>> res = impl.op()(array, axis)
>> File
>> "D:\ParaView-5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\vtk\numpy_interface\internal_algorithms.py",
>> line 363, in max
>> ans = numpy.max(narray, axis)
>> File
>> "D:\ParaView-5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\numpy\core\fromnumeric.py",
>> line 2125, in amax
>> out=out, keepdims=keepdims)
>> File
>> "D:\ParaView-5.2.0-Qt4-OpenGL2-Windows-64bit\bin\lib\site-packages\numpy\core\_methods.py",
>> line 17, in _amax
>> out=out, keepdims=keepdims)
>>
>>
>>
>>
>> Test case reproducing the bug:
>>
>>
>>
>> from paraview.simple import *
>> paraview.simple._DisableFirstRenderCameraReset()
>> programmableSource1 = ProgrammableSource()
>> programmableSource1.Script = \
>> """gg=max(5.0,6.0)
>> #This script generates a helix curve.
>> #This is intended as the script of a 'Programmable Source'
>> import math
>>
>> numPts = 80 # Points along Helix
>> length = 8.0 # Length of Helix
>> rounds = 3.0 # Number of times around
>>
>> #Get a vtk.PolyData object for the output
>> pdo = self.GetPolyDataOutput()
>>
>> #This will store the points for the Helix
>> newPts = vtk.vtkPoints()
>> for i in range(0, numPts):
>> #Generate the Points along the Helix
>> x = i*length/numPts
>> y = math.sin(i*rounds*2*math.pi/numPts)
>> z = math.cos(i*rounds*2*math.pi/numPts)
>> #Insert the Points into the vtkPoints object
>> #The first parameter indicates the reference.
>> #value for the point. Here we add them sequentially.
>> #Note that the first point is at index 0 (not 1).
>> newPts.InsertPoint(i, x,y,z)
>>
>> #Add the points to the vtkPolyData object
>> #Right now the points are not associated with a line -
>> #it is just a set of unconnected points. We need to
>> #create a 'cell' object that ties points together
>> #to make a curve (in this case). This is done below.
>> #A 'cell' is just an object that tells how points are
>> #connected to make a 1D, 2D, or 3D object.
>> pdo.SetPoints(newPts)
>>
>> #Make a vtkPolyLine which holds the info necessary
>> #to create a curve composed of line segments. This
>> #really just hold constructor data that will be passed
>> #to vtkPolyData to add a new line.
>> aPolyLine = vtk.vtkPolyLine()
>>
>> #Indicate the number of points along the line
>> aPolyLine.GetPointIds().SetNumberOfIds(numPts)
>> for i in range(0,numPts):
>> #Add the points to the line. The first value indicates
>> #the order of the point on the line. The second value
>> #is a reference to a point in a vtkPoints object. Depends
>> #on the order that Points were added to vtkPoints object.
>> #Note that this will not be associated with actual points
>> #until it is added to a vtkPolyData object which holds a
>> #vtkPoints object.
>> aPolyLine.GetPointIds().SetId(i, i)
>>
>> #Allocate the number of 'cells' that will be added. We are just
>> #adding one vtkPolyLine 'cell' to the vtkPolyData object.
>> pdo.Allocate(1, 1)
>>
>> #Add the poly line 'cell' to the vtkPolyData object.
>> pdo.InsertNextCell(aPolyLine.GetCellType(), aPolyLine.GetPointIds())
>>
>> #The Helix is ready to plot! Click 'Apply'.
>> """
>> renderView1 = GetActiveViewOrCreate('RenderView')
>> programmableSource1Display = Show(programmableSource1, renderView1)
>> renderView1.ResetCamera()
>> Render()
>>
>>
>>
>> Guillaume Jacquenot
>>
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the ParaView Wiki at:
>> http://paraview.org/Wiki/ParaView
>>
>> Search the list archives at: http://markmail.org/search/?q=ParaView
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/paraview
>>
>
>
>
> --
> Cory Quammen
> Staff R&D Engineer
> Kitware, Inc.
--
Cory Quammen
Staff R&D Engineer
Kitware, Inc.
More information about the ParaView
mailing list