[Paraview] Problem with numpy array

Andy Bauer andy.bauer at kitware.com
Thu Apr 19 09:22:47 EDT 2018


The Gradient of Unstructured Dataset does increase the tensor dimension. So
a scalar, or 1 component array in VTK/PV, becomes a vector, or a 3
components array. Similarly, a vector becomes a 2nd order tensor, or 9
component array.

Andrea: could you try upgrading to ParaView 5.5 (available at
paraview.org/download) ? Some of the numpy support has been improved since
5.3. I tried your original Programmable Filter script and I got an
eigenvectors and eigenvalues array:

*import* *numpy* *as* *np*

*from* *numpy* *import* linalg *as* LA

*from* *paraview* *import* numpy_support

input = inputs[0]



numPoints = input.GetNumberOfPoints()

*print* "number of points",numPoints

tensors = input.PointData['Gradients']

*print* "tensors[0:3]",tensors[0:3]

eigenvalues,eigenvectors = LA.eig(tensors)

*print* 'eigenvalues', eigenvalues[0]

*print* 'eigenvectors',eigenvectors[0]

output.PointData.append(eigenvalues,'eigenvalues')

output.PointData.append(eigenvectors,'eigenvectors')


Once you get PV 5.5, you can try loading the attached eigen.pvsm state file
which worked for me if you want to test it out. Note that since I used the
Gradient of Unstructured Dataset filter twice to go from a scalar array to
a second order tensor before doing the programmable filter, I used
Gradients2 for the output array name for the second order tensor.

Best,
Andy



On Thu, Apr 19, 2018 at 1:03 AM, Caffagni, Andrea <
Andrea.Caffagni at ferrari.com> wrote:

> If I add simply the code suggested from you Oscar, my filters becomes:
>
>
>
> *import* *numpy* *as* *np*
>
> *from* *numpy* *import* linalg *as* LA
>
> *from* *paraview* *import* numpy_support
>
> *from* *vtk.util* *import* numpy_support
>
> input = inputs[0]
>
>
>
> numPoints = input.GetNumberOfPoints()
>
> *print* "number of points",numPoints
>
> *#print "keys",input.GetPointData().keys()*
>
> tensorsVTK = input.PointData['Gradients']
>
> tensorsNP=numpy_support.vtk_to_numpy(tensorsVTK)
>
> *#tensors[0,:,:]=np.diag((1,2,3))*
>
> *#tensors[0,:,:]=[[1,-1,2],[2,-1,3],[0,0,1]]*
>
> *print* "tensors[0:3]",tensors[0:3]
>
> eigenvalues,eigenvectors = LA.eig(tensorsNP)
>
> *print* 'eigenvalues', eigenvalues[0]
>
> *print* 'eigenvectors',eigenvectors[0]
>
> output.PointData.append(eigenvalues,'eigenvalues')
>
> output.PointData.append(eigenvectors,'eigenvectors')
>
>
>
>
>
> I obtain the following Output:
>
>
>
>
>
> Traceback (most recent call last):
>
> File "<string>", line 22, in <module>
>
> File "<string>", line 8, in RequestData
>
> UnboundLocalError: local variable 'NumPy_data' referenced before assignment
>
> Traceback (most recent call last):
>
> File "<string>", line 22, in <module>
>
> File "<string>", line 12, in RequestData
>
> File "C:\Program Files\ParaView 5.3.0-Qt5-OpenGL2-Windows-
> 64bit\bin\lib\site-packages\vtk\util\numpy_support.py", line 213, in
> vtk_to_numpy
>
> typ = vtk_array.GetDataType()
>
> AttributeError: 'VTKCompositeDataArray' object has no attribute
> 'GetDataType'
>
> number of points 1
>
>
>
> I need to reshape the vector or define the type?
>
>
>
> Best Regards,
>
> Andrea
>
>
>
> *From:* Oscar Wilsby [mailto:ow222 at cam.ac.uk]
> *Sent:* Wednesday, April 18, 2018 21:14
> *To:* Cory Quammen
> *Cc:* Caffagni, Andrea; Andy Bauer; paraview at public.kitware.com
>
> *Subject:* Re: [Paraview] Problem with numpy array
>
>
>
> Hi Andy,
>
>
>
> I haven’t verified, but at a glance it looks like what you are passing to
> the the LA.eig function is not a 2D numpy array. Can you try doing
> np.asarray(tensors) or
>
>
>
> from vtk.util.numpy_support import vtk_to_numpy
>
> tensors = vtk_to_numpy(tensors)
>
> and then pass that to LA.eig?
>
>
>
> Kind regards,
>
>
>
> Oscar
>
>
>
>
>
> On 18 Apr 2018, at 16:33, Cory Quammen <cory.quammen at kitware.com> wrote:
>
>
>
> Hey Andy,
>
> Does the GradientOfUnstructuredDataSet filter produce a tensor from an
> input vector field? My testing in ParaView indicates it doesn't , but I'm
> not super familiar with it.
>
> Thanks,
>
> Cory
>
>
>
> On Wed, Apr 18, 2018 at 11:14 AM, Caffagni, Andrea <Andrea.Caffagni@
> ferrari.com> wrote:
>
> Dear Cory,
>
> This is the complete message that I have obtained like output:
>
>
>
> Traceback (most recent call last):
>
> File "<string>", line 22, in <module>
>
> File "<string>", line 14, in RequestData
>
> File "C:\Program Files\ParaView 5.3.0-Qt5-OpenGL2-Windows-
> 64bit\bin\lib\site-packages\numpy\linalg\linalg.py", line 1095, in eig
>
> _assertRankAtLeast2(a)
>
> File "C:\Program Files\ParaView 5.3.0-Qt5-OpenGL2-Windows-
> 64bit\bin\lib\site-packages\numpy\linalg\linalg.py", line 202, in
> _assertRankAtLeast2
>
> 'at least two-dimensional' % len(a.shape))
>
> numpy.linalg.linalg.LinAlgError: 0-dimensional array given. Array must be
> at least two-dimensional
>
> number of points 1
>
> tensors[0:3] [VTKArray([[[ 8.34616375, -23.89611435, 2.00894117],
>
> [ 0.67995167, -23.11237526, 289.07113647],
>
> [ 27.26550674, -231.06710815, 16.90883636]]], dtype=float32)]
>
>
>
>
>
> From this, I have thought about the vtk array.
>
>
>
> Best regards,
>
> Andrea
>
>
>
> *From:* Cory Quammen [mailto:cory.quammen at kitware.com]
> *Sent:* Wednesday, April 18, 2018 15:11
> *To:* Caffagni, Andrea
> *Cc:* paraview at public.kitware.com
> *Subject:* Re: [Paraview] Problem with numpy array
>
>
>
> Hi Andrea,
>
>
>
> Besides the error message, what does your script print?
>
>
>
> Thanks,
>
> Cory
>
>
>
>
>
> On Wed, Apr 18, 2018 at 2:14 AM, Caffagni, Andrea <
> Andrea.Caffagni at ferrari.com> wrote:
>
> Dear Users,
>
> I need to solve an eigenproblem in a point of a CFD field.
>
> Using the GradientOfUnstructuredDataSet I calculate the velocity gradient
> of my velocity field, than I isolate may point of interest and I have
> written the following ProgrammableFilter:
>
>
>
> *import* *numpy* *as* *np*
>
> *from* *numpy* *import* linalg *as* LA
>
> *from* *paraview* *import* numpy_support
>
> input = inputs[0]
>
>
>
> numPoints = input.GetNumberOfPoints()
>
> *print* "number of points",numPoints
>
> tensors = input.PointData['Gradients']
>
> *print* "tensors[0:3]",tensors[0:3]
>
> eigenvalues,eigenvectors = LA.eig(tensors)
>
> *print* 'eigenvalues', eigenvalues[0]
>
> *print* 'eigenvectors',eigenvectors[0]
>
> output.PointData.append(eigenvalues,'eigenvalues')
>
> output.PointData.append(eigenvectors,'eigenvectors')
>
>
>
> I have obtained the following error message:
>
>
>
> Traceback (most recent call last):
>
> File "<string>", line 22, in <module>
>
> File "<string>", line 14, in RequestData
>
> File "C:\Program Files\ParaView 5.3.0-Qt5-OpenGL2-Windows-
> 64bit\bin\lib\site-packages\numpy\linalg\linalg.py", line 1095, in eig
>
> _assertRankAtLeast2(a)
>
> File "C:\Program Files\ParaView 5.3.0-Qt5-OpenGL2-Windows-
> 64bit\bin\lib\site-packages\numpy\linalg\linalg.py", line 202, in
> _assertRankAtLeast2
>
> 'at least two-dimensional' % len(a.shape))
>
> numpy.linalg.linalg.LinAlgError: 0-dimensional array given. Array must be
> at least two-dimensional
>
>
>
>
>
> I imagine that the problem is linked to the vtk array, I need to convert
> my ‘Gradients’ matrix in a nparray?
>
> Someone have the same problem?
>
>
>
> Best Regards,
>
> Andrea
>
>
>
>
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
> Questo messaggio è da intendersi esclusivamente ad uso del destinatario e
> può contenere informazioni che sono di natura privilegiata, confidenziale o
> non divulgabile secondo le leggi vigenti. Se il lettore del presente
> messaggio non è il destinatario designato, o il dipendente/agente
> responsabile per la consegna del messaggio al destinatario designato, si
> informa che ogni disseminazione, distribuzione o copiatura di questa
> comunicazione è vietata anche ai sensi della normativa vigente in materia
> di protezione dei dati personali. Se avete ricevuto questo messaggio per
> errore, vi preghiamo di notificarcelo immediatamente a mezzo e-mail di
> risposta e successivamente di procedere alla cancellazione di questa e-mail
> e relativi allegati dal vostro sistema.
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
> This message is intended only for the use of the addressee and may contain
> information that is privileged, confidential and exempt from disclosure
> under applicable law. If the reader of this message is not the intended
> recipient, or the employee or agent responsible for delivering the message
> to the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is prohibited under the
> applicable data protection law. If you have received this e-mail by
> mistake, please notify us immediately by return e-mail and delete this
> e-mail and all attachments from your system.
>
>
>
> ____________________________________________________________
> _____________________________________________________
>
>
> _______________________________________________
> 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:
> https://public.kitware.com/mailman/listinfo/paraview
>
>
>
>
>
> --
>
> Cory Quammen
> Staff R&D Engineer
> Kitware, Inc.
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
> Questo messaggio è da intendersi esclusivamente ad uso del destinatario e
> può contenere informazioni che sono di natura privilegiata, confidenziale o
> non divulgabile secondo le leggi vigenti. Se il lettore del presente
> messaggio non è il destinatario designato, o il dipendente/agente
> responsabile per la consegna del messaggio al destinatario designato, si
> informa che ogni disseminazione, distribuzione o copiatura di questa
> comunicazione è vietata anche ai sensi della normativa vigente in materia
> di protezione dei dati personali. Se avete ricevuto questo messaggio per
> errore, vi preghiamo di notificarcelo immediatamente a mezzo e-mail di
> risposta e successivamente di procedere alla cancellazione di questa e-mail
> e relativi allegati dal vostro sistema.
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
> This message is intended only for the use of the addressee and may contain
> information that is privileged, confidential and exempt from disclosure
> under applicable law. If the reader of this message is not the intended
> recipient, or the employee or agent responsible for delivering the message
> to the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is prohibited under the
> applicable data protection law. If you have received this e-mail by
> mistake, please notify us immediately by return e-mail and delete this
> e-mail and all attachments from your system.
>
>
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
>
> --
>
> Cory Quammen
> Staff R&D Engineer
> Kitware, Inc.
>
> _______________________________________________
> 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:
> https://public.kitware.com/mailman/listinfo/paraview
>
>
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
> Questo messaggio è da intendersi esclusivamente ad uso del destinatario e
> può contenere informazioni che sono di natura privilegiata, confidenziale o
> non divulgabile secondo le leggi vigenti. Se il lettore del presente
> messaggio non è il destinatario designato, o il dipendente/agente
> responsabile per la consegna del messaggio al destinatario designato, si
> informa che ogni disseminazione, distribuzione o copiatura di questa
> comunicazione è vietata anche ai sensi della normativa vigente in materia
> di protezione dei dati personali. Se avete ricevuto questo messaggio per
> errore, vi preghiamo di notificarcelo immediatamente a mezzo e-mail di
> risposta e successivamente di procedere alla cancellazione di questa e-mail
> e relativi allegati dal vostro sistema.
>
> ____________________________________________________________
> _____________________________________________________
>
>
>
> This message is intended only for the use of the addressee and may contain
> information that is privileged, confidential and exempt from disclosure
> under applicable law. If the reader of this message is not the intended
> recipient, or the employee or agent responsible for delivering the message
> to the intended recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is prohibited under the
> applicable data protection law. If you have received this e-mail by
> mistake, please notify us immediately by return e-mail and delete this
> e-mail and all attachments from your system.
>
>
>
> ____________________________________________________________
> _____________________________________________________
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/paraview/attachments/20180419/afd65510/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: eigen.pvsm
Type: application/octet-stream
Size: 431870 bytes
Desc: not available
URL: <https://public.kitware.com/pipermail/paraview/attachments/20180419/afd65510/attachment-0001.obj>


More information about the ParaView mailing list