|
[Sponsors] |
[General] Script help needed - export screnshots for each time step, for multiple layouts |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
May 23, 2023, 15:07 |
Script help needed - export screnshots for each time step, for multiple layouts
|
#1 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
Just starting out with scripting, I could not find a way to do this:
I have one or more layouts in Paraview. Let's focus on the "more" part here, because for only one layout, I could use "save animation". Now I need a script that basically does the same as save animation, just for each layout that is present. I.e. save a separate image each time step, with the file name appended by a number. It should only visit each time step once, to avoid loading and processing each step multiple times. Like "advance time step" -> "write separate screenshots for each layout" -> "advance time step"... I'm sure some of you have scripts ready to do this. I would greatly appreciate if you could share. Or give me some hints. |
|
May 24, 2023, 05:26 |
|
#2 |
Senior Member
|
Hi Alex,
Just to be sure, you have multiple layouts as in multiple Renderviews, but not a split screen? Because for a split screen I think there is already the option when using saveAnimation. But If you want to make multiple screenshots of various layouts, something like this could do it: - prepare your pipeline (maybe save a statefile?) - start a Trace: - save screenshots for every layout - advance time - save screenshots for every layout - stop the trace You should now have a skeleton script that you can use. I guess it will show the commands to get a particular layout or renderview and save a screenshot for that and how to advance it in time. It is then up to you to create some simple loops and afterwards you can use ffmpeg to make animations from the separate images. Hope this helps. Best Regards, Tom Last edited by tomf; May 24, 2023 at 07:42. |
|
May 24, 2023, 06:30 |
|
#3 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
Yes, several layouts.
Up until now, I have been using split screens in a single layout when I needed more than one view for an animation. But that is a bit cumbersome, and very limited. I already found the trace feature of course. Thing is, I don't have the finer details to turn this into a proper script. Like making it work automatically for all existing time steps. Work for an arbitrary number of layouts in the state file. And last not least: append numbers to the file names. |
|
May 24, 2023, 08:07 |
|
#4 |
Senior Member
|
Hi Alex,
Thanks for the clarification. Some skeleton script which may work based on some quick trying (not tested): The assumption is that we start with a statefile/prepared pipeline with all the right things shown. The setup: Code:
from paraview.simple import * layouts=GetLayouts() timeKeeper=GetTimeKeeper() timeSteps=timeKeeper.TimestepValues views=GetRenderViews() animation=GetAnimationScene() Code:
# We loop over all timesteps and start by putting the animation time to the required timestep for time in timeSteps: animation.AnimationTime=time # Now we loop over all layouts, but as the layouts is an array of layouts, # we use the range and len functions to just use a counter for each layout and # set the resolution for each layout for layout in range(len(layouts)): SaveScreenshot('Image_Layout{:02d}_Time{}.png'.format(layout,time), layouts[layout], ImageResolution=views[layout].ViewSize) Cheers, Tom |
|
May 24, 2023, 10:07 |
|
#5 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
Thank you so much. The syntax you provided really made things easy for me.
Minor issue with Code:
for layout in range(len(layouts)): This is what I finally went with: It puts the images for each layout in a separate directory. And instead of appending a time value, it appends the time step number. Which makes things easier when working with ffmpeg later. Code:
# ParaView script for exporting screnshots of all layouts and all time steps in an existing state file import os import shutil from paraview.simple import * # image resolution xres=1920 yres=1080 # state file to use LoadState('state03.pvsm') # get info about number of time steps and number of layouts in state file layouts=GetLayouts() timeKeeper=GetTimeKeeper() timeSteps=timeKeeper.TimestepValues #views=GetRenderViews() animation=GetAnimationScene() # create one directory for each layout (remove first if it already exists) l=0 for layout in layouts: l=l+1 dirname='layout_{:02d}'.format(l) if os.path.exists(dirname): shutil.rmtree(dirname) os.makedirs(dirname) # loop over all time steps and layouts t=0 for time in timeSteps: t=t+1 animation.AnimationTime=time l=0 for layout in layouts: l=l+1 filename = 'layout_{:02d}'.format(l) + '/image_{:06d}.png'.format(t) print('writing file: ', filename) SaveScreenshot(filename, layouts[layout], SaveAllViews=1, ImageResolution=[xres, yres], SeparatorWidth=0) |
|
May 24, 2023, 11:03 |
|
#6 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
One more question:
since there will be some heavy lifting going on, I need to make things run in parallel. Just as an example, the "gradients of unstructured dataset" showed good speedup. Working with the GUI, I just enabled auto MPI parallel with a reasonable number of threads. This was good enough. Is my assumption correct that Code:
mpirun -np 16 pvbatch export_screenshots.py |
|
May 24, 2023, 11:29 |
|
#7 |
Senior Member
|
Hi,
Honestly I have had various success with the multicore running of ParaView in the past and never really got it to work. I do think that some of the later versions indeed handle some of the filters faster and I also think it works automatically on my machine just by running pvbatch/pvpython or just the GUI client. But I stopped to use the autoMPI as that seemed to freeze my desktop (again some time ago). I cannot even find the setting in v5.11 at least, but a few tests showed that all my processors are used by some filters (even though I did not specify any mpirun command before the paraview command). IIRC this was also mentioned in recent release notes. For me most stuff is fast enough, so never did investigate too much about it, but recently I came across some tips in the CFD Engine newsletter that may be of help for you. Other than that, I would encourage you to just try if this makes sense and I will be very eager to learn about the outcome. Best of luck! |
|
May 24, 2023, 15:10 |
|
#8 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46 |
Sure, whether you get any meaningful speedup very much depends on the filters you are using. It worked pretty ok for me so far. I know some things get no benefit from parallelism at all, or even take longer. Like loading certain file types. I was mostly asking to check if I am doing it right.
Anyway, here is my quick&dirty test. Mesh is around 60milion unstructured hexa8 cells in an ensight gold file format. The pipeline has cell-to-point data filter, gradient of unstructured data set, and some less parallel stuff like slices and iso-surfaces. Run on a system with lots of background processes, so not exactly best-case scenario for parallel speedup. System has an Epyc 7401 with 24 cores. Code:
Nthreads "timesteps per hour" speedup 01 20.6 1.0 04 44.0 2.1 16 65.5 3.2 Last edited by flotus1; May 24, 2023 at 17:07. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Setting up Lid driven Cavity Benchmark with 1M cells for multiple cores | puneet336 | OpenFOAM Running, Solving & CFD | 11 | April 7, 2019 00:58 |
A CFX-POST error (ver 14.5.7) | wangyflp88 | CFX | 2 | July 22, 2017 00:17 |
AMI interDyMFoam for mixer nu problem | danny123 | OpenFOAM Programming & Development | 8 | September 6, 2013 02:34 |
OpenFOAM on MinGW crosscompiler hosted on Linux | allenzhao | OpenFOAM Installation | 127 | January 30, 2009 19:08 |
IcoFoam parallel woes | msrinath80 | OpenFOAM Running, Solving & CFD | 9 | July 22, 2007 02:58 |