Get data from Calculator filter in python script
Hi all,
New on python scripting with Paraview, I am trying for a while to do a (I hope) simple thing but without any success... I have generated in my script a Calculator filter (let's call it Calculator1). When I display it in a Paraview spreadsheet view, it looks like below: ___|__Point_ID__|___Points___|___Result___| _0_|__0_________|__67.15...__|__4.35e+06__| That is: a single row with a column called Result (among other columns). I would like to get the value of this Result (4.35e+06 here) into a python variable. Can anyone help me with this?... Thank you very much! Best regards, William |
Greetings William,
Have a look into this section: http://www.paraview.org/Wiki/ParaVie...tiple_Datasets In other words, you can get in into another Python calculator the "Result" field, for example: Code:
inputs[0].PointData['Result'] Best regards, Bruno |
1 Attachment(s)
Hi Bruno,
Thank you very much for your help ! I cannot share my case but I enclose the python script I use... (and copy paste it in this post). I have a wing surface with pressure data. I want to split it into several 2D profiles, and to calculate the lift coefficient on each of these profiles. The last object "Calculator2" is the one from which I would like to extract the "Result" value... I tried Calculator2.PointData['Result'] but it returns "Array: Result"... Here is my script: try: paraview.simple except: from paraview.simple import * # Get active boundary (actualy a 3D wing from a mesh with pressure data) Boundary = GetActiveSource() # Extract surface from this wing boundary (necessary to compute normal vectors) ExtractSurface1 = ExtractSurface( Boundary ) # Compute normal vectors of the wing surface GenerateSurfaceNormals1 = GenerateSurfaceNormals( ExtractSurface1 ) # For several positions on the z axis... for z in range(500,5500,1000): # Make a cut of the wing to have a local 2D profile |
2 Attachment(s)
Hi,
I made a test case on which to run my script: https://www.dropbox.com/s/tacsiz95qe...g_pressure.zip It consist of a Ensight Gold case. I just use an Extract Block filter to extract the "wing" boundary, then select the ExtractBlock1 object and open a Python shell and run the script. Before: Attachment 25866 After: Attachment 25867 Best regards, William |
I finally use a workaround consisting in exporting data into CSV files...
http://www.paraview.org/Wiki/ParaVie...rting_CSV_Data Adapting to my script, it looks like: writer = CreateWriter(str(z)+".csv", Calculator2) writer.FieldAssociation = "Points" writer.UpdatePipeline() del writer Like this I have separated files for each 2D profile. Not beautiful at all, but it works... But I hope there is a way to avoid such CSV file export and to get values directly in the python script... Best regards, William |
Hi William,
Many thanks for sharing the information you've managed to figure out! The idea I had given on the other post relied on using the filter "Python Calculator", which does provide access to values on arrays, but it works differently from the main Python scripting system that ParaView uses. It took me a few minutes to figure this one out. The instructions are partially given here: http://paraview.org/Wiki/ParaView/Py...Source_Proxies The rest I used the knowledge I have of VTK. The example is as follows, with comments along the way: Code:
Calculator2=GetActiveSource() Bruno |
1 Attachment(s)
Thank you Bruno ! ! ! ! :D
I dreamed it, you did it ! :) It works perfectly :) Enclosed is my script fixed with your solution :) Thank you again ! :D Best regards, William |
1 Attachment(s)
Hi all...
I am still struggling making my script. I figured out that I have to use the Python Calculator to do what I need. But after creating the Python Calculator object, I cannot use the solution above on it. I put Code:
data=servermanager.Fetch(areaCalculator) Code:
pointData=data.GetPointData() If someone can help.............. :( Enclosed is my script (please, use the previous case and modify the path inside the python script). Code:
try: paraview.simple |
Hi William,
I won't be able to look into the code before the weekend, but there is a quick tip I can give right now... actually, I already mentioned in the previous post, so I'll rephrase it:
Another tip is from another thread and I quote: Quote:
Best regards, Bruno |
1 Attachment(s)
Hi @wyldckat,
Thank you for your time! I read you, trust you, but I still don't see how to do... But the thing which is very strange to me is that my script works perfectly with a Python Calculator made on a source Sphere, but not with the same Python Calculator made on my wing surface... Here is my script: Code:
try: paraview.simple Code:
#test_on='sphere' Output: Quote:
Quote:
:confused: |
Hi William,
A quick question: does it work if you work with it manually on ParaView? Because I'm guessing that you don't know about the method "UpdatePipeline()": http://paraview.org/Wiki/ParaView/Py...ing_a_Pipeline Quote:
Best regards, Bruno |
Yahaaaa !
Thank you very much @Wyldckat ! :D with a Code:
areaCalculator.UpdatePipeline() I hope you don't think I don't read the documentation :) Just that it is lots of info at a time and I don't have much time to develop my script... Merci infiniment ! :D Best regards, William |
:(
Spoke to fast... It doesn't change anything actually.......................... :( |
Hi William,
Try on the other variables before that part. The biggest suspect is "wing_pressure_case" since it's the reader and seems to be a bit more tricky to use, given its configuration settings. And if "UpdatePipeline()" doesn't work, try "Update()". Best regards, Bruno |
Hi @Wyldckat,
I gave up with this method. I put an UpdatePipe() on all objects. I tried Update() without success. I came back to the CSV file solution. I export the data into a temporary CSV file, then import it with the csv python library and delete it. It takes one cent of second and it is very robust. Maybe I will later understand what I did wrong. Thank you very much for your precious help anyway ! ;) Best regards, William |
Hi William,
OK, I've figured out the problem. If you had checked what "data" was, it would tell you this: Code:
>>> data To unwrap the data, you can use "MergeBlocks": Code:
mergedAreaCalculator=MergeBlocks(areaCalculator) If I'm not mistaken, this filter can be applied directly to the reader, so that you won't have to be bothered by it later on in the code :). Best regards, Bruno |
Hello, @Wyldckat :)
I had seen that the wing data was under multi-block format and noticed this was the only one difference between it and the source sphere case. But I really didn't know what to do with this! I tried lots of things, and finally gave up! Now my script is ready to use with the CSV solution. Don't know if I will use the MergeBlock solution on it. But I am happy to see the source of the mistake ! (I tested on my test script, it works) Thank you very much! :) Best regards, William |
Using mergeBlock in Paraview
Hi all,
I have a question about using mergeBlock in Paraview ! I tried to save the data on a .vtk file, it works for the first iteration but I need to save the last iteration's data in my .vtk file. Any one have an idea please ? :confused::confused: Thanks |
All times are GMT -4. The time now is 06:31. |