|
[Sponsors] | |||||
|
|
|
#1 |
|
New Member
Jeff Cumpston
Join Date: Oct 2011
Posts: 8
Rep Power: 3 ![]() |
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 |
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Niels Nielsen
Join Date: Mar 2009
Location: Denmark
Posts: 383
Rep Power: 10 ![]() |
Hi
Try this Code:
numCells = DataSliceFile.GetNumberOfCells()
data=[]
for x in range(numCells):
data.append(DataSliceFile.GetCellData().GetArray('p').GetValue(x))
print data
Code:
numCells = DataSliceFile.GetNumberOfCells()
new=DataSliceFile.CellData['p']
data=[]
for x in range(numCells):
data.append(new[x])
print 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
__________________
Linnemann |
|
|
|
|
|
|
|
|
#3 |
|
Senior Member
Eelco van Vliet
Join Date: Mar 2009
Location: The Netherlands
Posts: 114
Rep Power: 6 ![]() |
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 |
|
|
|
|
|
|
|
|
#4 |
|
New Member
Join Date: Feb 2012
Posts: 10
Rep Power: 3 ![]() |
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()
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... Last edited by eric_albin; December 5, 2012 at 12:30. |
|
|
|
|
|
|
|
|
#5 |
|
Senior Member
Niels Nielsen
Join Date: Mar 2009
Location: Denmark
Posts: 383
Rep Power: 10 ![]() |
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
Code:
1600 -0.053845824021 Also extensive use of python object inspector Code:
print dir(pdi) Hope this helps
__________________
Linnemann |
|
|
|
|
|
|
|
|
#6 |
|
New Member
Join Date: Feb 2012
Posts: 10
Rep Power: 3 ![]() |
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 |
|
|
|
|
|
|
|
|
#7 |
|
Senior Member
Niels Nielsen
Join Date: Mar 2009
Location: Denmark
Posts: 383
Rep Power: 10 ![]() |
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
Code:
1600 -0.053845824021
__________________
Linnemann |
|
|
|
|
|
|
|
|
#8 |
|
New Member
Join Date: Feb 2012
Posts: 10
Rep Power: 3 ![]() |
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 |
|
|
|
|
|
![]() |
| Tags |
| openfoam, paraview 3.10, python, vtk |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get Python Shell into ParaView 3.8.1? | blaise | OpenFOAM Installation | 3 | July 24, 2012 04:58 |
| extracting data from paraview | tharem | OpenFOAM Paraview & paraFoam | 1 | January 17, 2011 23:45 |
| paraview - plotting difference to reference data | joewe | ParaView | 0 | August 30, 2010 18:01 |
| paraFoam reader for OpenFOAM 1.6 | smart | OpenFOAM Installation | 13 | November 16, 2009 21:41 |
| How to update polyPatchbs localPoints | liu | OpenFOAM Running, Solving & CFD | 6 | December 30, 2005 17:27 |