Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Draw bunch of raw files with paraview
#!/usr/bin/env python
import os, sys
import glob, natsort, argparse
ParaviewPath="/home/bikulov/bin/ParaView-4.3.1-Linux-64bit/lib/paraview-4.3"
print("export LD_LIBRARY_PATH={ParaviewPath}:$LD_LIBRARY_PATH".format(ParaviewPath=ParaviewPath))
sys.path.append(os.path.join(ParaviewPath, "site-packages"))
sys.path.append(os.path.join(ParaviewPath, "site-packages/vtk"))
from paraview.simple import *
def main(pipeline, state, files, output):
filenames = natsort.natsorted(files)
servermanager.LoadState(state)
view = servermanager.GetRenderView()
camera = view.GetActiveCamera()
phase = FindSource(pipeline)
# Set white background
SetViewProperties(view, Background = [1, 1, 1])
try:
os.makedirs(output)
except:
pass
imgNum = 0
for f in filenames:
phase.FilePrefix = f
phase.FileNameChanged()
view.WriteImage(os.path.join(output, str(imgNum).zfill(6) + ".png"), "vtkPNGWriter", 1)
imgNum += 1
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="PROG", description="Draw With Paraview")
parser.add_argument("--state", type=str, help="State file to load", default="state.pvsm")
parser.add_argument("--pipeline", type=str, help="Pipiline name for changing file", default="data")
parser.add_argument("--output", type=str, help="Output path for images", default="img")
parser.add_argument("files", nargs="*", help="Files to be used in the pipeline")
args = parser.parse_args()
main(pipeline=args.pipeline, state=args.state, files=args.files, output=args.output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.