CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Visualization & Post-Processing Software > ParaView

[General] Extracting ParaView Data into Python Arrays

Register Blogs Community New Posts Updated Threads Search

Like Tree14Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 19, 2012, 02:01
Question Extracting ParaView Data into Python Arrays
  #1
New Member
 
Jeff Cumpston
Join Date: Oct 2011
Posts: 8
Rep Power: 15
Jeffzda is on a distinguished road
Hi all,

When scripting paraview using python, how do I extract raw tuple data from a 'slice' proxy without first exporting to CSV? I used paraview.servermanager.Fetch() function to retrieve the raw data and it looks like the resulting vtk object contains it but I just can't seem to get the actual DATA! Does anyone know what I can do?

Here's what I've done so far:


>>> from paraview.simple import *
>>> File = OpenFOAMReader('file.OpenFOAM')
>>> SliceFile = Slice(File)
>>> DataSliceFile = paraview.servermanager.Fetch(SliceFile)

getting appended
use composite data append
vtkPOpenFOAMReader : [ ...........]
vtkCutter : [ ...........]
vtkReductionFilter : [ ...........]
vtkClientServerMoveData : [ ...........]

>>> print(DataSliceFile)

...
...

Cell Data:
Debug: Off
Modified Time: 113008
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 11
Array 0 name = R
Array 1 name = T
Array 2 name = U
Array 3 name = alphat
Array 4 name = epsilon
Array 5 name = k
Array 6 name = kappat
Array 7 name = magT
Array 8 name = nut
Array 9 name = p
Array 10 name = p_rgh
Number Of Components: 18
Number Of Tuples: 400
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )

...
...

Above is only part of the output to the 'print' command but as you can see there are tuples there for the taking! 400 of them. Can anyone help me get to them?

Thanks is advance,

Jeff
Jeffzda is offline   Reply With Quote

Old   January 19, 2012, 02:44
Default
  #2
Senior Member
 
linnemann's Avatar
 
Niels Nielsen
Join Date: Mar 2009
Location: NJ - Denmark
Posts: 556
Rep Power: 27
linnemann will become famous soon enough
Hi

Try this

Code:
numCells = DataSliceFile.GetNumberOfCells()

data=[]
for x in range(numCells):
    data.append(DataSliceFile.GetCellData().GetArray('p').GetValue(x))

print data
or this

Code:
numCells = DataSliceFile.GetNumberOfCells()
new=DataSliceFile.CellData['p']

data=[]
for x in range(numCells):
    data.append(new[x])

print data
It depends on how the data is stored, if its a vtkMultiBlockDataSet or vtkDataSet. This is at least how I get my data.

if DataSliceFile is vtkMultiBlockDataSet then you might need to do some GetBlock(0) thing http://www.vtk.org/doc/nightly/html/...ckDataSet.html

This can also give some inspiration.

http://www.vtk.org/doc/nightly/html/...loatArray.html

http://www.vtk.org/Wiki/Python_Programmable_Filter

http://paraview.org/Wiki/ParaView/Python_Scripting
Jeffzda and Pagoda like this.
__________________
Linnemann

PS. I do not do personal support, so please post in the forums.
linnemann is offline   Reply With Quote

Old   January 23, 2012, 06:02
Default accessing vtk data array example in pvbatch
  #3
Senior Member
 
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 124
Rep Power: 19
eelcovv is on a distinguished road
Hy,
I don't know if the post above already answers your question, but here a script I wrote a while ago which I used to obtain the mimumum Uz value plus the position of this minimum over a plane per time step and export these values. Those pvbatch commands to access the data arrays are not very well documented, so perhaps you can get some inspiration by it.

Regards
Eelco
Attached Files
File Type: gz pvmpiSkin.tar.gz (11.1 KB, 385 views)
eelcovv is offline   Reply With Quote

Old   December 5, 2012, 13:05
Default
  #4
New Member
 
Join Date: Feb 2012
Posts: 13
Rep Power: 14
eric_albin is on a distinguished road
I must be very ignorant but I still do not succeed to do a simple script to access to some points of a data stored in a vts file!
Here is what I try to do :
Code:
r = OpenDataFile("THI2D_0000.vts")
r.UpdatePipeline()
pdi = r.PointData
print 'len(pdi):', len(pdi)
ai = pdi[2]
print "Range:", pdi[1].Name
for n in range(pdi.GetNumberOfArrays()):
   print pdi.GetArray(n).GetName(), ' ',
   pdi.GetArray(n).GetRange()
for n in range(pdi.NumberOfArrays):
   print pdi[n].Name, ' ', pdi[n].GetRange()
for k, v in pdi.iteritems():
   print k, v.GetRange()
This just gives me access to the "names" and the "ranges" of the arrays :
p, li { white-space: pre-wrap; } len(pdi): 3
Range: U2
U1 U2 Vort U1 (-0.27383780094, 0.24077918789)
U2 (-0.227040989, 0.28179814685)
Vort (0.00085531204979, 9.2079403574)
U1 (-0.27383780094, 0.24077918789)
U2 (-0.227040989, 0.28179814685)
Vort (0.00085531204979, 9.2079403574)

How can I access to the number of points and to the 10th value of U1 for instance?
Please...
Attached Files
File Type: zip readVTS.zip (38.7 KB, 44 views)
Zaphod'sSecondHead likes this.

Last edited by eric_albin; December 5, 2012 at 13:30.
eric_albin is offline   Reply With Quote

Old   December 6, 2012, 02:02
Default
  #5
Senior Member
 
linnemann's Avatar
 
Niels Nielsen
Join Date: Mar 2009
Location: NJ - Denmark
Posts: 556
Rep Power: 27
linnemann will become famous soon enough
Hi

Did this on a windows machine with the python programmable filter inside paraview.

Code
Code:
pdi = self.GetInput()
inn=pdi.GetPointData()
numPoints=pdi.GetNumberOfPoints()
print numPoints
U10=inn.GetArray("U1").GetValue(10)
print U10
Output
Code:
1600
-0.053845824021
You should be able to change this to fit your script.

Also extensive use of python object inspector
Code:
print dir(pdi)
will print all the calls available to the object pdi.

Hope this helps
mgg and Zaphod'sSecondHead like this.
__________________
Linnemann

PS. I do not do personal support, so please post in the forums.
linnemann is offline   Reply With Quote

Old   December 6, 2012, 03:49
Default
  #6
New Member
 
Join Date: Feb 2012
Posts: 13
Rep Power: 14
eric_albin is on a distinguished road
Dear Linnemann,

Thank you so much for your post.
This really helps me a lot.

In fact, the script you gave works perfectly inside the programmable filter but do not work inside the python shell :

Traceback (most recent call last):
File "<string>", line 33, in <module>
NameError: name 'self' is not defined

This is a normal issue according to these links :
http://www.paraview.org/Wiki/ParaVie...Python_Filters
http://comments.gmane.org/gmane.comp...iew.user/11839

In fact, if I use your command "" inside a python shell, I have only these classes available for pdi :

['FieldData', 'GetArray', 'GetFieldData', 'GetNumberOfArrays', 'NumberOfArrays', 'OutputPort', 'Proxy', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__iter__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'has_key', 'items', 'iteritems', 'keys', 'values']


I will then try to do the job I have to do inside the programmable filter...
Thanks a lot, Eric
eric_albin is offline   Reply With Quote

Old   December 6, 2012, 06:10
Default
  #7
Senior Member
 
linnemann's Avatar
 
Niels Nielsen
Join Date: Mar 2009
Location: NJ - Denmark
Posts: 556
Rep Power: 27
linnemann will become famous soon enough
Hi

Here is some code that works in the pvPython script environment.

Code:
from paraview.simple import *

r = OpenDataFile("THI2D_0000.vts")
r.SMProxy.UpdatePipeline(0) # If dealing with multiple times
r.UpdatePipelineInformation()

data = servermanager.Fetch(r) #I think this was the only one missing in your original to get the actual data.

numPoints=data.GetNumberOfPoints()
print numPoints

U10=data.GetPointData().GetArray("U1").GetValue(10)
print U10
Output
Code:
1600
-0.053845824021
__________________
Linnemann

PS. I do not do personal support, so please post in the forums.
linnemann is offline   Reply With Quote

Old   December 6, 2012, 09:10
Default
  #8
New Member
 
Join Date: Feb 2012
Posts: 13
Rep Power: 14
eric_albin is on a distinguished road
Thank you very much again.
This works perfectly in a python shell. With your indications, I can now compute anything I want like the rms fluctuation of velocities both in the programmable filter or directly in the python shell.

I hope this will be useful for other users on the web because this is not straightforward for beginners in python.
a nice day,
Eric
eric_albin is offline   Reply With Quote

Old   January 6, 2017, 10:41
Default
  #9
New Member
 
Join Date: Jan 2017
Location: Germany
Posts: 19
Rep Power: 9
beral is on a distinguished road
Hi there,

I had the same problem and found the solution here. Thanks! Now I have the data and the next problem...

I want to work with the CellData.
Code:
cellData = data.GetCellData()
#cellData is a vtkCellArray
cellData.GetNumberOfCells()        #26000
cellData.InitTraversal()
cellData.GetNextCell(...)         # here is my problem
vtkIdList is required as parameter and I can't figure out, where to get this list.

What IdList is meant and where to find it in the data?
beral is offline   Reply With Quote

Old   January 10, 2017, 00:31
Default VTK Multi Blockset data extraction or modification
  #10
New Member
 
Andi Hartarto
Join Date: Jan 2017
Posts: 3
Rep Power: 9
andidi is on a distinguished road
Dear all,

Thank you for your discussions. I have benefited greatly.
Please help me solve this puzzle I have related to your discussion.
linnemann's solution works are looks great.
Unfortunately my work involves usage of the vtkMultiBlockDataSet and I am stuck with it.

I did

from paraview.simple import *
trial5e=ExodusIIReader(FileName=['C:\\Users\\....\\trial5.e'])
trial6= paraview.servermanager.Fetch(trial5e)

# use composite data append
print (trial6)

vtkMultiBlockDataSet ...
...
...
Number of Children:8
Child 0: vtkMultiBlockDataSet
...
Number of Children: 1
Child 0: vtk UnstructuredGrid
...
Field data:
....
Number of points : 2230
Number of cells: 29284
Cell Data:
..
Number of arrays:6
Array 1 = Tetrahedra Rank.
Array 3=ObjectId
....


My ultimate goal is to make ObjectId equal to Tetrahedra Rank.

Please help me


Quote:
Originally Posted by linnemann View Post
Hi

Try this

Code:
numCells = DataSliceFile.GetNumberOfCells()

data=[]
for x in range(numCells):
    data.append(DataSliceFile.GetCellData().GetArray('p').GetValue(x))

print data
or this

Code:
numCells = DataSliceFile.GetNumberOfCells()
new=DataSliceFile.CellData['p']

data=[]
for x in range(numCells):
    data.append(new[x])

print data
It depends on how the data is stored, if its a vtkMultiBlockDataSet or vtkDataSet. This is at least how I get my data.

if DataSliceFile is vtkMultiBlockDataSet then you might need to do some GetBlock(0) thing http://www.vtk.org/doc/nightly/html/...ckDataSet.html

This can also give some inspiration.

http://www.vtk.org/doc/nightly/html/...loatArray.html

http://www.vtk.org/Wiki/Python_Programmable_Filter

http://paraview.org/Wiki/ParaView/Python_Scripting
andidi is offline   Reply With Quote

Old   January 10, 2017, 09:28
Default
  #11
New Member
 
Join Date: Jan 2017
Location: Germany
Posts: 19
Rep Power: 9
beral is on a distinguished road
Can you copy the whole answer of "print (trial6) here?

The Data Set has a hierarchy and you'll have to go through it with getters, until you arrive the arrays.

The first should probably be:

Code:
blocklData = trial6.GetBlock(int Blocknumber)
print (blockData)
And so on, until you arrive the Datastructure, where the Arrays are. It looks like it is CellData. There could be a function like this:
Code:
celldData = someData.GetCellData()
arr1 = cellData.GetArray(1)
arr3 = cellData.GetArray(3)
Depending on the type of Array (or not depending, I don't know...) there could be a GetValue(int position) Function and a SetValue(int position, type value) Function, which you can use on arr1 and arr3 to manipulate their values. check, if their length is the same, if you use a loop.

Note, this is a newbie help.
beral is offline   Reply With Quote

Old   January 10, 2017, 21:00
Default
  #12
New Member
 
Andi Hartarto
Join Date: Jan 2017
Posts: 3
Rep Power: 9
andidi is on a distinguished road
Dear beral, here is the whole code i've done and the answer

Python 2.7.3 (default, Sep 27 2016, 14:23:08) [MSC v.1500 64 bit (AMD64)] on win32
>>> from paraview.simple import *
paraview version 5.2.0
>>> trial5e=ExodusIIReader(FileName=['C:\\Users\\.......\\trial5.e'])
>>> trial6=paraview.servermanager.Fetch(trial5e)
use composite data append
>>> print(trial6)
vtkMultiBlockDataSet (0000020549E0F7A0)
Debug: Off
Modified Time: 262806
Reference Count: 1
Registered Events: (none)
Information: 000002054A042510
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262710
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 8
Child 0: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262724
Reference Count: 1
Registered Events: (none)
Information: 000002054A041DE0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262716
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 1
Child 0: vtkUnstructuredGrid
Debug: Off
Modified Time: 261408
Reference Count: 1
Registered Events: (none)
Information: 0000020549F75650
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 261408
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 2
Array 0 name = ElementBlockIds
Array 1 name = Title
Number Of Components: 2
Number Of Tuples: 1
Number Of Points: 2230
Number Of Cells: 29284
Cell Data:
Debug: Off
Modified Time: 261399
Reference Count: 1
Registered Events:
Registered Observers:
vtkObserver (0000020549FD5610)
Event: 33
EventName: ModifiedEvent
Command: 0000020549F75740
Priority: 0
Tag: 1
Number Of Arrays: 6
Array 0 name = TetrahedraNo
Array 1 name = TetrahedraRank
Array 2 name = vtkOriginalCellIds
Array 3 name = ObjectId
Array 4 name = GlobalElementId
Array 5 name = PedigreeElementId
Number Of Components: 6
Number Of Tuples: 29284
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds:
Debug: Off
Modified Time: 260035
Reference Count: 4
Registered Events: (none)
Name: GlobalElementId
Data type: idtype
Size: 29284
MaxId: 29283
NumberOfComponents: 1
Information: 0000020549F788A0
Debug: Off
Modified Time: 261537
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F77AE0)
Name: GlobalElementId
Number Of Components: 1
Number Of Tuples: 29284
Size: 29284
MaxId: 29283
LookupTable: (none)
PedigreeIds:
Debug: Off
Modified Time: 260039
Reference Count: 3
Registered Events: (none)
Name: PedigreeElementId
Data type: idtype
Size: 29284
MaxId: 29283
NumberOfComponents: 1
Information: 0000020549F783A0
Debug: Off
Modified Time: 261547
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F780D0)
Name: PedigreeElementId
Number Of Components: 1
Number Of Tuples: 29284
Size: 29284
MaxId: 29283
LookupTable: (none)
EdgeFlag: (none)
Point Data:
Debug: Off
Modified Time: 261405
Reference Count: 1
Registered Events:
Registered Observers:
vtkObserver (0000020549FD5400)
Event: 33
EventName: ModifiedEvent
Command: 0000020549F75740
Priority: 0
Tag: 1
Number Of Arrays: 3
Array 0 name = vtkOriginalPointIds
Array 1 name = GlobalNodeId
Array 2 name = PedigreeNodeId
Number Of Components: 3
Number Of Tuples: 2230
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds:
Debug: Off
Modified Time: 260050
Reference Count: 4
Registered Events: (none)
Name: GlobalNodeId
Data type: idtype
Size: 2230
MaxId: 2229
NumberOfComponents: 1
Information: 0000020549F77810
Debug: Off
Modified Time: 261487
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F77720)
Name: GlobalNodeId
Number Of Components: 1
Number Of Tuples: 2230
Size: 2230
MaxId: 2229
LookupTable: (none)
PedigreeIds:
Debug: Off
Modified Time: 260054
Reference Count: 3
Registered Events: (none)
Name: PedigreeNodeId
Data type: idtype
Size: 2230
MaxId: 2229
NumberOfComponents: 1
Information: 0000020549F772C0
Debug: Off
Modified Time: 261497
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F774F0)
Name: PedigreeNodeId
Number Of Components: 1
Number Of Tuples: 2230
Size: 2230
MaxId: 2229
LookupTable: (none)
EdgeFlag: (none)
Bounds:
Xmin,Xmax: (100000, 110000)
Ymin,Ymax: (2e+006, 2.01e+006)
Zmin,Zmax: (-8000, 1653.55)
Compute Time: 263265
Number Of Points: 2230
Point Coordinates: 0000020549642A70
Locator: 0000000000000000
Number Of Pieces: 1
Piece: -1
Ghost Level: 0
Child 1: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262735
Reference Count: 1
Registered Events: (none)
Information: 000002054A042150
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262731
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0
Child 2: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262746
Reference Count: 1
Registered Events: (none)
Information: 000002054A041E30
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262742
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0
Child 3: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262757
Reference Count: 1
Registered Events: (none)
Information: 000002054A041ED0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262753
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0
Child 4: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262768
Reference Count: 1
Registered Events: (none)
Information: 000002054A041FC0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262764
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0
Child 5: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262779
Reference Count: 1
Registered Events: (none)
Information: 000002054A0420B0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262775
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0
Child 6: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262790
Reference Count: 1
Registered Events: (none)
Information: 000002054A0422E0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262786
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0
Child 7: vtkMultiBlockDataSet
Debug: Off
Modified Time: 262801
Reference Count: 1
Registered Events: (none)
Information: 000002054A0412A0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262797
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 0


>>> block1Data=trial6.GetBlock(0)
>>> print block1Data
vtkMultiBlockDataSet (0000020549E0E6C0)
Debug: Off
Modified Time: 262724
Reference Count: 2
Registered Events: (none)
Information: 000002054A041DE0
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 262716
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 0
Number Of Components: 0
Number Of Tuples: 0
Number Of Children: 1
Child 0: vtkUnstructuredGrid
Debug: Off
Modified Time: 261408
Reference Count: 1
Registered Events: (none)
Information: 0000020549F75650
Data Released: False
Global Release Data: Off
UpdateTime: 0
Field Data:
Debug: Off
Modified Time: 261408
Reference Count: 1
Registered Events: (none)
Number Of Arrays: 2
Array 0 name = ElementBlockIds
Array 1 name = Title
Number Of Components: 2
Number Of Tuples: 1
Number Of Points: 2230
Number Of Cells: 29284
Cell Data:
Debug: Off
Modified Time: 261399
Reference Count: 1
Registered Events:
Registered Observers:
vtkObserver (0000020549FD5610)
Event: 33
EventName: ModifiedEvent
Command: 0000020549F75740
Priority: 0
Tag: 1
Number Of Arrays: 6
Array 0 name = TetrahedraNo
Array 1 name = TetrahedraRank
Array 2 name = vtkOriginalCellIds
Array 3 name = ObjectId
Array 4 name = GlobalElementId
Array 5 name = PedigreeElementId
Number Of Components: 6
Number Of Tuples: 29284
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds:
Debug: Off
Modified Time: 260035
Reference Count: 4
Registered Events: (none)
Name: GlobalElementId
Data type: idtype
Size: 29284
MaxId: 29283
NumberOfComponents: 1
Information: 0000020549F788A0
Debug: Off
Modified Time: 261537
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F77AE0)
Name: GlobalElementId
Number Of Components: 1
Number Of Tuples: 29284
Size: 29284
MaxId: 29283
LookupTable: (none)
PedigreeIds:
Debug: Off
Modified Time: 260039
Reference Count: 3
Registered Events: (none)
Name: PedigreeElementId
Data type: idtype
Size: 29284
MaxId: 29283
NumberOfComponents: 1
Information: 0000020549F783A0
Debug: Off
Modified Time: 261547
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F780D0)
Name: PedigreeElementId
Number Of Components: 1
Number Of Tuples: 29284
Size: 29284
MaxId: 29283
LookupTable: (none)
EdgeFlag: (none)
Point Data:
Debug: Off
Modified Time: 261405
Reference Count: 1
Registered Events:
Registered Observers:
vtkObserver (0000020549FD5400)
Event: 33
EventName: ModifiedEvent
Command: 0000020549F75740
Priority: 0
Tag: 1
Number Of Arrays: 3
Array 0 name = vtkOriginalPointIds
Array 1 name = GlobalNodeId
Array 2 name = PedigreeNodeId
Number Of Components: 3
Number Of Tuples: 2230
Copy Tuple Flags: ( 1 1 1 1 1 0 1 1 )
Interpolate Flags: ( 1 1 1 1 1 0 0 1 )
Pass Through Flags: ( 1 1 1 1 1 1 1 1 )
Scalars: (none)
Vectors: (none)
Normals: (none)
TCoords: (none)
Tensors: (none)
GlobalIds:
Debug: Off
Modified Time: 260050
Reference Count: 4
Registered Events: (none)
Name: GlobalNodeId
Data type: idtype
Size: 2230
MaxId: 2229
NumberOfComponents: 1
Information: 0000020549F77810
Debug: Off
Modified Time: 261487
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F77720)
Name: GlobalNodeId
Number Of Components: 1
Number Of Tuples: 2230
Size: 2230
MaxId: 2229
LookupTable: (none)
PedigreeIds:
Debug: Off
Modified Time: 260054
Reference Count: 3
Registered Events: (none)
Name: PedigreeNodeId
Data type: idtype
Size: 2230
MaxId: 2229
NumberOfComponents: 1
Information: 0000020549F772C0
Debug: Off
Modified Time: 261497
Reference Count: 1
Registered Events: (none)
PER_COMPONENT: vtkInformationVector(0000020549F774F0)
Name: PedigreeNodeId
Number Of Components: 1
Number Of Tuples: 2230
Size: 2230
MaxId: 2229
LookupTable: (none)
EdgeFlag: (none)
Bounds:
Xmin,Xmax: (100000, 110000)
Ymin,Ymax: (2e+006, 2.01e+006)
Zmin,Zmax: (-8000, 1653.55)
Compute Time: 263265
Number Of Points: 2230
Point Coordinates: 0000020549642A70
Locator: 0000000000000000
Number Of Pieces: 1
Piece: -1
Ghost Level: 0

>>> dir(block1Data)
['ALL_PIECES_EXTENT', 'AddObserver', 'AttributeTypes', 'BOUNDING_BOX', 'BreakOnError', 'CELL', 'CELL_DATA_VECTOR', 'CURRENT_PROCESS_CAN_LOAD_BLOCK', 'CopyInformationFromPipeline', 'CopyInformationToPipeline', 'CopyStructure', 'Crop', 'DATA_EXTENT', 'DATA_EXTENT_TYPE', 'DATA_NUMBER_OF_GHOST_LEVELS', 'DATA_NUMBER_OF_PIECES', 'DATA_OBJECT', 'DATA_PIECE_NUMBER', 'DATA_TIME_STEP', 'DATA_TYPE_NAME', 'DataHasBeenGenerated', 'DebugOff', 'DebugOn', 'DeepCopy', 'EDGE', 'EDGE_DATA_VECTOR', 'FIELD', 'FIELD_ACTIVE_ATTRIBUTE', 'FIELD_ARRAY_TYPE', 'FIELD_ASSOCIATION', 'FIELD_ASSOCIATION_CELLS', 'FIELD_ASSOCIATION_EDGES', 'FIELD_ASSOCIATION_NONE', 'FIELD_ASSOCIATION_POINTS', 'FIELD_ASSOCIATION_POINTS_THEN_CELLS', 'FIELD_ASSOCIATION_ROWS', 'FIELD_ASSOCIATION_VERTICES', 'FIELD_ATTRIBUTE_TYPE', 'FIELD_NAME', 'FIELD_NUMBER_OF_COMPONENTS', 'FIELD_NUMBER_OF_TUPLES', 'FIELD_OPERATION', 'FIELD_OPERATION_MODIFIED', 'FIELD_OPERATION_PRESERVED', 'FIELD_OPERATION_REINTERPOLATED', 'FIELD_OPERATION_REMOVED', 'FIELD_RANGE', 'FastDelete', 'FieldAssociations', 'FieldOperations', 'GetActiveFieldInformation', 'GetActualMemorySize', 'GetAddressAsString', 'GetAssociationTypeAsString', 'GetAssociationTypeFromString', 'GetAttributeTypeForArray', 'GetAttributes', 'GetAttributesAsFieldData', 'GetBlock', 'GetClassName', 'GetCommand', 'GetData', 'GetDataObjectType', 'GetDataReleased', 'GetDataSet', 'GetDebug', 'GetExtentType', 'GetFieldData', 'GetGlobalReleaseDataFlag', 'GetGlobalWarningDisplay', 'GetInformation', 'GetMTime', 'GetMetaData', 'GetNamedFieldInformation', 'GetNumberOfBlocks', 'GetNumberOfElements', 'GetNumberOfPoints', 'GetReferenceCount', 'GetUpdateTime', 'GlobalReleaseDataFlagOff', 'GlobalReleaseDataFlagOn', 'GlobalWarningDisplayOff', 'GlobalWarningDisplayOn', 'HasMetaData', 'HasObserver', 'Initialize', 'InitializeObjectBase', 'InvokeEvent', 'IsA', 'IsTypeOf', 'Modified', 'NAME', 'NUMBER_OF_ASSOCIATIONS', 'NUMBER_OF_ATTRIBUTE_TYPES', 'NewInstance', 'NewIterator', 'NewTreeIterator', 'ORIGIN', 'PIECE_EXTENT', 'POINT', 'POINT_DATA_VECTOR', 'POINT_THEN_CELL', 'PrepareForNewData', 'ROW', 'Register', 'ReleaseData', 'RemoveAllObservers', 'RemoveBlock', 'RemoveNamedFieldInformation', 'RemoveObserver', 'RemoveObservers', 'SIL', 'SPACING', 'SafeDownCast', 'SetActiveAttribute', 'SetActiveAttributeInfo', 'SetBlock', 'SetDataSet', 'SetDataSetFrom', 'SetDebug', 'SetFieldData', 'SetGlobalReleaseDataFlag', 'SetGlobalWarningDisplay', 'SetInformation', 'SetNumberOfBlocks', 'SetPointDataActiveScalarInfo', 'SetReferenceCount', 'ShallowCopy', 'UnRegister', 'VERTEX', 'VERTEX_DATA_VECTOR', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__this__', '__vtkname__']


Quote:
Originally Posted by beral View Post
Can you copy the whole answer of "print (trial6) here?

The Data Set has a hierarchy and you'll have to go through it with getters, until you arrive the arrays.

The first should probably be:

Code:
blocklData = trial6.GetBlock(int Blocknumber)
print (blockData)
And so on, until you arrive the Datastructure, where the Arrays are. It looks like it is CellData. There could be a function like this:
Code:
celldData = someData.GetCellData()
arr1 = cellData.GetArray(1)
arr3 = cellData.GetArray(3)
Depending on the type of Array (or not depending, I don't know...) there could be a GetValue(int position) Function and a SetValue(int position, type value) Function, which you can use on arr1 and arr3 to manipulate their values. check, if their length is the same, if you use a loop.

Note, this is a newbie help.
andidi is offline   Reply With Quote

Old   January 17, 2017, 12:30
Default
  #13
New Member
 
Join Date: Jan 2017
Location: Germany
Posts: 19
Rep Power: 9
beral is on a distinguished road
Have you already fond a solution?

On block1data I would try one of the methods: GetBlock, GetData or GetDataSet.

You need Child 0, which is an vtkUnstructuredGrid. block1data has only this one child. One of the mentioned methods should return Child 0.
beral is offline   Reply With Quote

Old   March 14, 2017, 08:24
Default
  #14
New Member
 
Join Date: Jan 2017
Location: Germany
Posts: 19
Rep Power: 9
beral is on a distinguished road
When fetching the data of a pipeline object with servermanager.Fetch(...), the data is just a copy on the client side and all changes made on it are not done in the pipeline. It becomes a problem, if the modification of the data is an intermediate step and after it the modified data has to be available in the pipeline, for setting new filters or calculators on it.

If someone else has to fight with this problem, here is a possible solution. Everything is done within the Python Shell and can be saved as a Skript and be run out of the shell, too.

1. For the third step to work, we must explicitly set up a builtin server connection. Otherwise it will not work.
Code:
from paraview.simple import *             # this is how it alwys starts 
from paraview import servermanager       # need this for the connection
connection = servermanager.Connect()     # connection ist 'Connection (builtin:)' if it went right, 'None' otherwise
2. Fetch some data and work on it (an example):
Code:
# read in some PolyData
data = servermanager.Fetch(polyDataPipelineObject) # data is a local (client-side) copy of the Object data
print data  # 'vtkPolyData (10D8D290) ...' here we see, that some arrays are in the PointData
from paraview.vtk import vtkDoubleArray   # we will add an array to the PointData 
arr = vtkDoubleArray() 
arr.SetName("MyNewArray")   
arr.Resize(2)         # set length of the array to 2 
arr.SetValue(0,1)      # value on position 0 is 1
arr.SetValue(1,100)    # value on position 1 is 100 
p = data.GetPointData()  
p.AddArray(arr)   # arr is now part of 'data'. check it with 'print data'
3. Now put the data back in the pipeline:

Code:
t = TrivialProducer() # TrivialProducer is a pipeline object
filter = t.GetClientSideObject() # filter ist a vtkTrivialProducer (!= TrivialProducer)
filter.SetOutput(data)   # set our client-side 'data' as output of the server-side TrivialProducer
t.UpdatePipeline()  # 't' is a pipeline object, it has our modiefied data
Now it is possible to work with the modified data in the pipeline.
tho64 likes this.
beral is offline   Reply With Quote

Old   March 28, 2017, 09:19
Default
  #15
New Member
 
Michael Hoss
Join Date: Sep 2016
Posts: 8
Rep Power: 10
Knusper is on a distinguished road
Dear friends,

I have the following problem:

I want to extract the ranges (min/max) of arrays for Ux, Uy and Uz, but all of them are called "U [m/s]" and if I access that, I just get Ux!

More information:
If I load the cell data of a certain slice, get the velocity array 'U [m/s]' (there is no other velocity array!! I checked that by iterating over all existing arrays) and print its range, I always just get the Ux-range... But at least in the Paraview GUI, there are also Uy and Uz ranges (see attached picture).

Code:
cd = slice1.CellData
cdArray = cd.GetArray('U [m/s]')
myRange = cdArray.GetRange()
print "myRange = "+str(myRange)

Output:
>>>myRange = (0.006702960003167391, 0.015230599790811539) 
# this is just the range for Ux?!?
How can I get the other ranges (for Uy, Uz)??


Edit: Data is coming from OpenFOAM, but this thread is just suitable.
Attached Images
File Type: png U.PNG (26.5 KB, 27 views)
Knusper is offline   Reply With Quote

Old   March 28, 2017, 09:34
Default
  #16
New Member
 
Michael Hoss
Join Date: Sep 2016
Posts: 8
Rep Power: 10
Knusper is on a distinguished road
I just found the solution:

Code:
myDim = 1 # 0 for x, 1 for y, 2 for z, -1 for magnitute
range = cdArray.GetComponentRange(myDim)
This PPT presentation from kitware provided the info and seems quite useful overall:


https://www.google.de/url?sa=t&rct=j...,d.d24&cad=rja
Knusper is offline   Reply With Quote

Old   February 19, 2018, 04:37
Post How to extract 3D data from paraview
  #17
New Member
 
Ouardia
Join Date: Feb 2018
Posts: 2
Rep Power: 0
Ouardia is on a distinguished road
Hi all,

I have a basic question about how to extract 3D data from paraview ? I mean, the positions (X, Y, Z) and velocities (Ux(X, Y, Z), Uy (X, Y,Z), Uz(X, Y, Z)), in order to get a 3D quiver in Python !

Thanks a lot for your help
Regards,
Ouardia is offline   Reply With Quote

Old   January 3, 2019, 04:35
Default
  #18
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Hi,

to access the arrays of a filter in paraview with python do the following:

Code:
 #choose the solution
cfd_solution = FindSource('foam.foam')

 #Merge the blocks of a multiblock file to create one dataset.  
#This allows to access the data via the GetPointData or GetCellData command
 #Not needed if you do not have a multiblock file
 m = MergeBlocks(cfd_solution)

 #you could apply any other filter now on "m"
#imports the data from e.g. "m"
 d = servermanager.Fetch(m)

  #returns the number of arrays e.g. 4 => index 0 – 3  
 #d.GetCellData().GetNumberOfArrays() 
  #get the array string for the Number of arrays i
 #d.GetCellData().GetArrayName(i)

  #import numpy_support
  from paraview import numpy_support as ns

  #access the CellData of e.g. the array 'p'
  p = ns.vtk_to_numpy( d.GetCellData().GetArray('p') )   
Have fun.




Last edited by lukasf; January 9, 2019 at 04:16.
lukasf is offline   Reply With Quote

Old   November 11, 2019, 08:38
Default
  #19
Senior Member
 
Lukas Fischer
Join Date: May 2018
Location: Germany, Munich
Posts: 117
Rep Power: 8
lukasf is on a distinguished road
Note, to acces the coordinates of the cells I do the following:

#cellCenters1
cellCenters1 = CellCenters(Input=Filter_Object_of_interest_like_a _slice)
cellCenters1.VertexCells = 0
cellCenters1.UpdatePipeline()

#create a calculator and calculate Points
#otherwise GetPointData().GetArray('Points') does not find any Points

Calculator1 = Calculator(Input=cellCenters1)
Calculator1.ResultArrayName = 'Points'
Calculator1.Function = 'coords'

data_cell = servermanager.Fetch(Calculator1)
points = ns.vtk_to_numpy(data_cell.GetPointData().GetArray( 'Points'))
x = points[:,0]
y = points[:,1]
#etc...
lukasf is offline   Reply With Quote

Old   June 11, 2020, 16:54
Post Extract data from paraview & process it in python
  #20
Senior Member
 
Asmaa
Join Date: Mar 2016
Posts: 102
Rep Power: 10
foamiste is on a distinguished road
The link bellow suggest a detailed explanation of how to extract data from spreadsheet view in paraview and process it in Python :


https://www.youtube.com/watch?v=pT30R1P9wgo
foamiste is offline   Reply With Quote

Reply

Tags
openfoam, paraview 3.10, python, vtk


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[General] Paraview crashes using "Find Data" functionality Turbine ParaView 3 May 6, 2020 23:40
[OpenFOAM] Paraview Find Data cojua8 ParaView 2 March 19, 2018 09:57
[General] “Upload” vtk data from client to server in paraview script Jack001 ParaView 0 March 8, 2018 08:27
[General] Determining number of cores and/or paraview executable via python aerogt3 ParaView 0 December 9, 2014 06:54
studying a valve case mina.basta OpenFOAM 33 August 30, 2013 05:46


All times are GMT -4. The time now is 20:43.