[Paraview] numpy_interface/dataset_adapter append method fails on string datatypes ?

Dean Neumann dwneumann at gmail.com
Mon Jul 11 16:17:18 EDT 2016


Thank you Utkarsh,  that did the trick.
Regards,
Dean

On Fri, Jul 8, 2016 at 1:43 PM, Utkarsh Ayachit <utkarsh.ayachit at kitware.com
> wrote:

> Dean,
>
> Current numpy support in VTK doesn't include string arrays, You can
> overcome that as follows:
>
> colNames = [ 'simulation', 'v0 (m/s)', 'k (%)' ]
> col0     = [ 'm01-sim001', 'm01-sim002', 'm02-sim001' ]
> ...
> strArray = vtk.vtkStringArray()
> strArray.SetName(colNames[0])
> strArray.SetNumberOfTuples(len(col0))
> for i in range(len(col0)):
>     strArray.SetValue(i, col0[i])
> output.RowData.AddArray(strArray)
>
>
>
>
> On Fri, Jul 1, 2016 at 9:46 PM, Dean Neumann <dwneumann at gmail.com> wrote:
>
>> I am trying to write a python programmable filter which calculates
>> statistics across multiple input datasets and outputs those as a vtkTable.
>>
>> All is ok for numeric values.   But I can't seem to get any approach to
>> work for outputting a vtkTable column of string values.
>> Using numpy_interface/dataset_adapter.py is the cleanest approach I've
>> yet tried for appending  columns of numeric values to an output dataset of
>> type vtkTable, but it raises the following error on string-valued arrays:
>>
>>> Traceback (most recent call last):
>>
>> File "<string>", line 29, in <module>
>>
>> File "<string>", line 14, in RequestData
>>
>> File "C:\Program
>>> Files\ParaView\lib\paraview-5.0\site-packages\vtk\numpy_interface\dataset_adapter.py",
>>> line 648, in append
>>
>> narray = narray * numpy.ones(arrLength)
>>
>> TypeError: only integer arrays with one element can be converted to an
>>> index
>>
>>
>> Can someone please post an example python programmable filter that
>> outputs a vtkTable which includes a column of string valued data?   I have
>> attached a minimal script which reproduces the problem.
>>
>>
>> Thanks....
>>
>> Dean Neumann
>>
>> _______________________________________________
>> 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/20160711/aa1d9f88/attachment.html>


More information about the ParaView mailing list