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:[email protected]]
Sent: Wednesday, April 18, 2018 21:14
To: Cory Quammen
Cc: Caffagni, Andrea; Andy Bauer; [email protected]
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 
<[email protected]<mailto:[email protected]>> 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 
<[email protected]<mailto:[email protected]>> 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:[email protected]<mailto:[email protected]>]
Sent: Wednesday, April 18, 2018 15:11
To: Caffagni, Andrea
Cc: [email protected]<mailto:[email protected]>
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 
<[email protected]<mailto:[email protected]>> 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<http://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<http://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.



_________________________________________________________________________________________________________________
_______________________________________________
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

Reply via email to