Difference between revisions of "ParaView/Automation with Python"

From PHASTA Wiki
Jump to: navigation, search
m (Jrwrigh moved page Paraview Automation with Python to ParaView/Automation with Python: Move to a subpage organization)
 
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
1. Extract surface using paraview, the code will look like
+
ParaView has a built in Python interpreter that allows for operations done in ParaView to be automated.
  
from paraview.simple import *
+
== Extract surface using paraview, the code will look like ==
  
<nowiki>#========== read in data file</nowiki>
+
<nowiki>from paraview.simple import *
  
 +
#========== read in data file
 
print 'Read phasta file'
 
print 'Read phasta file'
 +
dataObj = PhastaReader( FileName= 'restart_one.pht' )  # you have to change the name of this pht file
 +
SRF = ExtractSurface(Input=dataObj)
 +
MGBLK1 = MergeBlocks(Input=SRF)
 +
vtkWriter = DataSetWriter(FileName = 'Surface.vtk' , Input = MGBLK1, FileType = 1) # you have to change the name of this vtk file
 +
vtkWriter.UpdatePipeline()
 +
</nowiki>
  
<nowiki>dataObj = PhastaReader( FileName= 'restart_one.pht' )  # you have to change the name of this pht file</nowiki>
+
Get the python file from
  
SRF = ExtractSurface(Input=dataObj)
+
<code>/users/ychen/NGC/geometry2012/pvExtractSuface.py</code>
  
MGBLK1 = MergeBlocks(Input=SRF)
+
==Generating Python Scripts for Data Extraction==
 
 
<nowiki>vtkWriter = DataSetWriter(FileName = 'Surface.vtk' , Input = MGBLK1, FileType = 1) # you have to change the name of this vtk file</nowiki>
 
  
vtkWriter.UpdatePipeline()
+
Generating python scripts can be done in the Paraview GUI and is actually pretty easy and straightforward. This process is documented [https://fluid.colorado.edu/tutorials/Paraview_Data_Extraction_Automation_1.mp4 here] in an example. Once the the script you want is generated, that script can be edited to automate data extraction. Again, a general example of this is outlined [https://fluid.colorado.edu/tutorials/Paraview_Data_Extraction_Automation_2.mp4 here]. Finally, once the script is run, data will be exported and look something like [https://fluid.colorado.edu/tutorials/Paraview_Data_Extraction_Automation_3.mp4 this].
  
 +
== Examples ==
  
Get the python file from
+
You can find examples of advanced uses for the ParaView scripting in the [https://github.com/PHASTA/utilities utilities] repository. Specifically, the <code>general/ParaView_*</code> directories.
  
/users/ychen/NGC/geometry2012/pvExtractSuface.py
+
[[Category:Paraview]]  [[Category:Post-processing]] [[Category:Python]]

Latest revision as of 11:02, 18 September 2022

ParaView has a built in Python interpreter that allows for operations done in ParaView to be automated.

Extract surface using paraview, the code will look like

from paraview.simple import *

#========== read in data file
print 'Read phasta file'
dataObj = PhastaReader( FileName= 'restart_one.pht' )  # you have to change the name of this pht file
SRF = ExtractSurface(Input=dataObj)
MGBLK1 = MergeBlocks(Input=SRF)
vtkWriter = DataSetWriter(FileName = 'Surface.vtk' , Input = MGBLK1, FileType = 1) # you have to change the name of this vtk file
vtkWriter.UpdatePipeline()

Get the python file from

/users/ychen/NGC/geometry2012/pvExtractSuface.py

Generating Python Scripts for Data Extraction

Generating python scripts can be done in the Paraview GUI and is actually pretty easy and straightforward. This process is documented here in an example. Once the the script you want is generated, that script can be edited to automate data extraction. Again, a general example of this is outlined here. Finally, once the script is run, data will be exported and look something like this.

Examples

You can find examples of advanced uses for the ParaView scripting in the utilities repository. Specifically, the general/ParaView_* directories.