CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   ParaView (https://www.cfd-online.com/Forums/paraview/)
-   -   [OpenFOAM] Python script to export animation images (https://www.cfd-online.com/Forums/paraview/118731-python-script-export-animation-images.html)

mahyarv14 June 3, 2013 09:33

Python script to export animation images
 
Hey everyone,

I am new to CFD and having a bit of trouble. My goal is to export the animation from ParaView as a video file or a series of images using some kind of script. The only way that I know how to export images is to manually go and click to export the images. I want to have a script that automatically does this so it would be more efficient. My current version of ParaView is 3.12.0 32-bit. I tried using this link http://paraview.org/Wiki/ParaView/Python_Scripting

to setup the python to work with the ParaVeiw, but no success. I could not find the path(s) that were mentioned on the tutorial. Any help is appreciate.


Thanks,
Mahyar

mahyarv14 June 3, 2013 12:33

So I tried using the Trace option in ParaView but I get the following error:

from paraview.simple import *
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/opt/paraviewopenfoam3120/lib/paraview-3.12/site-packages/paraview/simple.py", line 39, in <module>
import servermanager
File "/opt/paraviewopenfoam3120/lib/paraview-3.12/site-packages/paraview/servermanager.py", line 43, in <module>
import paraview, re, os, os.path, new, sys, vtk
File "/opt/paraviewopenfoam3120/lib/paraview-3.12/site-packages/paraview/vtk/__init__.py", line 1, in <module>
from vtkCommonPython import *
ImportError: No module named vtkCommonPython

I cannot find vtkCommonPython anywhere on my system.

JR22 June 3, 2013 19:36

  1. In paraview: File > Save Animation
  2. Then use one of several methods to make the video from the PNGs:

startingWithCFD June 4, 2013 06:56

Hello! Even though the easiest manner is to use JR22's method, it is sometimes not possible. When I leave work, I only have remote access to a windows machine and through that to the cluster server (yeap, those lovely security restrictions lead to inefficient situations). Therefore, the best way to see the results when I am away is to develop a paraview script to post-process.

So, I find the OP's question for a script meaningful and did not have the time to work on it myself. Does someone have something ready to share or some guidelines?

elvis June 4, 2013 09:13

Hi

what about "Advanced Paraview Tutorial", by Dave DeMarle, Kitware, Inc. given on the 6th Openfoam workshop?
http://openfoam-extend.sourceforge.n...m/training.htm

mahyarv14 June 4, 2013 09:32

I was able to solve the vtkCommonPython error by uninstalling ParaView 3.12 and installing a newer version. Now, I have used the Trace option to get a script from ParaView.

My main goal is to have a script run automatically once it detects the output files from OpenFOAM. It should basically create the vtk files, open them with ParaView, and output a video of the simulation to a specified directory.

Currently, I am somewhat stuck on calling Terminal commands in Ubuntu via a python script.

First, I have changed my directory using os.chdir(/path/to/files)

Then, I used os.system("paraFoam") in order to open ParaView from a directory but it says "sh: 1: paraFoam: not found"

CFDUser_ May 21, 2014 19:53

Quote:

Originally Posted by mahyarv14 (Post 431928)
I was able to solve the vtkCommonPython error by uninstalling ParaView 3.12 and installing a newer version. Now, I have used the Trace option to get a script from ParaView.

My main goal is to have a script run automatically once it detects the output files from OpenFOAM. It should basically create the vtk files, open them with ParaView, and output a video of the simulation to a specified directory.

Currently, I am somewhat stuck on calling Terminal commands in Ubuntu via a python script.

First, I have changed my directory using os.chdir(/path/to/files)

Then, I used os.system("paraFoam") in order to open ParaView from a directory but it says "sh: 1: paraFoam: not found"

Hi Mahyar,
Did you get any success? I am also trying to do the same. If you found the path will you guide me?

Regards,
CFDUser_

wyldckat May 25, 2014 07:01

Greetings to all!

For future reference, the issue with the missing vtkCommonPython was reported here: http://www.openfoam.org/mantisbt/view.php?id=969 - a fix is also provided there.

As for CFDUser's question and Mahyar's issue: if a more detailed script had been provided, it would possibly had been easier to help. Anyway, as far as I can see:
  1. Once you're using Python scripting, and if you've already exported to VTK file format, it doesn't make much sense to call the paraFoam script.
  2. If you're going to use Python to call ParaView, it probably makes even more sense to use ParaView's pvpython application, which allows you to run Python code with ParaView's functionality ready to be used.
  3. To do such a thing, you should first prepare the Python part of the script directly in ParaView. The "Python Trace" feature that is available in the "Tools" menu should help: http://www.paraview.org/Wiki/Python_GUI_Tools#Trace
  4. Once that script is tested and working, you can try it out by calling pvpython from the command line.
Best regards,
Bruno

CFDUser_ May 25, 2014 20:19

Quote:

Originally Posted by wyldckat (Post 493997)
Greetings to all!

For future reference, the issue with the missing vtkCommonPython was reported here: http://www.openfoam.org/mantisbt/view.php?id=969 - a fix is also provided there.

As for CFDUser's question and Mahyar's issue: if a more detailed script had been provided, it would possibly had been easier to help. Anyway, as far as I can see:
  1. Once you're using Python scripting, and if you've already exported to VTK file format, it doesn't make much sense to call the paraFoam script.
  2. If you're going to use Python to call ParaView, it probably makes even more sense to use ParaView's pvpython application, which allows you to run Python code with ParaView's functionality ready to be used.
  3. To do such a thing, you should first prepare the Python part of the script directly in ParaView. The "Python Trace" feature that is available in the "Tools" menu should help: http://www.paraview.org/Wiki/Python_GUI_Tools#Trace
  4. Once that script is tested and working, you can try it out by calling pvpython from the command line.
Best regards,
Bruno

Thank you very much Bruno, I follow most of your reply's. You are like OpenFOAM best documentation. :)

Regards,
CFDUser_

openfoammaofnepo July 10, 2014 12:54

Dear Bruno,

I am wondering if I can post-processing my data using Paraview script. For example, I need to the following action for each time step:

Code:

output the velocity components on one slice to CSV file
in the script, how can I add the looping to go through all the time instants?

I read the following link:

http://www.paraview.org/Wiki/ParaView/Python_Scripting

But it is very difficult to understand for me now. Do you have any suggestions?

Thank you.
OFFO

Quote:

Originally Posted by wyldckat (Post 493997)
Greetings to all!

For future reference, the issue with the missing vtkCommonPython was reported here: http://www.openfoam.org/mantisbt/view.php?id=969 - a fix is also provided there.

As for CFDUser's question and Mahyar's issue: if a more detailed script had been provided, it would possibly had been easier to help. Anyway, as far as I can see:
  1. Once you're using Python scripting, and if you've already exported to VTK file format, it doesn't make much sense to call the paraFoam script.
  2. If you're going to use Python to call ParaView, it probably makes even more sense to use ParaView's pvpython application, which allows you to run Python code with ParaView's functionality ready to be used.
  3. To do such a thing, you should first prepare the Python part of the script directly in ParaView. The "Python Trace" feature that is available in the "Tools" menu should help: http://www.paraview.org/Wiki/Python_GUI_Tools#Trace
  4. Once that script is tested and working, you can try it out by calling pvpython from the command line.
Best regards,
Bruno


wyldckat August 16, 2014 11:11

Hi OFFO,

Quote:

Originally Posted by openfoammaofnepo (Post 500988)
I read the following link:

http://www.paraview.org/Wiki/ParaView/Python_Scripting

But it is very difficult to understand for me now. Do you have any suggestions?

I don't know if you've managed to solve this issue.
If not, perhaps it's easier if you explain what you've already learned so far in using ParaView Python, so that I can figure out what needs to be explained.

Best regards,
Bruno


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