[Paraview] passing a numpy array to a programmable filter

Alessandro De Maio demaio.a at gmail.com
Tue May 30 14:39:16 EDT 2017


Thank you very much Utkarsh,
     your suggestion was very helpful as always!

Alessandro

On Tue, May 30, 2017 at 4:23 PM, Utkarsh Ayachit <
utkarsh.ayachit at kitware.com> wrote:

> The best option would be to indeed move the Python code to "get" the array
> from the the other numerical process to the Programmable Filter's script
> itself, rather than doing it in the batch script.
>
> The do-at-your-own-peril option, which may work if you don't intend to run
> the batch script in parallel or client-server modes,  would be to pass the
> array via a global variable in some module that both the batch script and
> the programmable filter script import. Since the Python interpreter is
> shared between the two, and modules don't get imported twice, you should be
> able to set the variable in one and access it in another.
>
> Utkarsh
>
> On Fri, May 26, 2017 at 10:53 AM, Alessandro De Maio <demaio.a at gmail.com>
> wrote:
>
>> Dear all,
>>      I'm writing a pvbatch script in which I need to perform some
>> calculations on paraview objects (provided by a quite complex pipeline that
>> starts from reading vtu files and processing through reseamplewithdataset
>> filter and other filter manipulations) by using a programmable filter to
>> which I must pass some information that in the main script is representable
>> as a quite big float numpy ndarray. This array comes from another numerical
>> process that cannot be included in the same programmable filter.
>>
>> I don't know how to pass this numpy array to the programmable filter.
>> Probably I could use the Parameters property of the programmable filter
>> but, if I correctly understand the use of this feature, the whole array
>> should be converted to a very big string (or more than one) and then
>> reconverted back to float values inside the PF.
>>
>> I've tried to create a vtkTable object in the main script using the
>> following lines:
>>
>> T = vtkTable()
>> array_vtk = numpy_support.numpy_to_vtk(array)
>> array_vtk.SetName("AAA")
>> T.AddColumn(array_vtk)
>>
>> and this seems to generate a vtkTable object (by printing type(T) I get
>> "<type 'vtkCommonDataModelPython.vtkTable'> " ) but this is not a
>> Paraview class object so when I pass this as an input argument to the
>> Programmable Filter I obviously get the error:
>> "vtkCommonDataModelPython.vtkTable' object has no attribute 'SMProxy'.
>>
>>
>>
>> Is there any way to do this? I've thought about using
>> servermanager.CreateProxy() but I don't know how to use it and if it could
>> help.
>>
>> Of course the easy solution could be to write the array to the disk from
>> the main script and to read it from the  disk inside the programmable
>> filter, but I would like to avoid passing through the disk writing that
>> could be too much slow.
>>
>> Any help would be appreciated.
>> Thank you in advance
>>
>> Alessandro
>>
>> _______________________________________________
>> 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
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/paraview/attachments/20170530/5831362f/attachment.html>


More information about the ParaView mailing list