# pvpython and postprocessing

**URL:** https://discourse.paraview.org/t/pvpython-and-postprocessing/5556
**Category:** ParaView Support
**Created:** [October 13, 2020, 12:43pm UTC](https://discourse.paraview.org/t/pvpython-and-postprocessing/5556 "2020-10-13T12:43:02Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Propanotriol](https://discourse.paraview.org/user_avatar/discourse.paraview.org/propanotriol/32/2598_2.png) [@Propanotriol](https://discourse.paraview.org/u/Propanotriol)
#### Post date: [October 13, 2020, 12:43pm UTC](https://discourse.paraview.org/t/pvpython-and-postprocessing/5556/1 "2020-10-13T12:43:02Z")

</div>

Dear all,

I am trying to automatise my post-processing of an OpenFOAM case using pvpython.

I obtain the result that I need and I want, however, I want to improve the code. I am really new, and it is my first time with pvpython/python and paraview.

The problem is that when I execute my pvpython code, I have a paraview GUI that opens while the code is running. But I do not want it to appear, I just want to execute the script and obtain the results without any extra window opening.

The code is built using the trace tool of paraview. I tried to suppress the code lines that open the windows but if I do so, the date do not get updated when I change the time (timestep) in which. E.g. I want to make the time average of a slice averaged property, if I do not show the window, the data, even if I do change properly the time step, do not get updated.

The code is the following:

> import sys  
> import numpy as np  
> import os  
> import signal  
> import vtk.util.numpy\_support as nps  
> import matplotlib.pyplot as plt  
> from numpy import linalg as LA  
> import math
> 
> from paraview.simple import \*
> 
> testingFunctionsfoam = OpenFOAMReader(FileName=‘/home/saddik/Desktop/LongerSim/LongerSim.foam’)  
> testingFunctionsfoam.MeshRegions = [‘internalMesh’]  
> testingFunctionsfoam.CellArrays = [‘H2’]  
> testingFunctionsfoam.Decomposepolyhedra = 0
> 
> animationScene1 = GetAnimationScene()
> 
> timeKeeper1 = GetTimeKeeper()  
> timesteps = timeKeeper1.TimestepValues  
> numTimesteps = len(timesteps)
> 
> animationScene1.UpdateAnimationUsingDataTimeSteps()
> 
> testingFunctionsfoam.SkipZeroTime = 0
> 
> renderView1 = GetActiveViewOrCreate(‘RenderView’)
> 
> layout1 = GetLayout()
> 
> materialLibrary1 = GetMaterialLibrary()
> 
> renderView1.Update()
> 
> renderView1.Update()
> 
> cellSize1 = CellSize(Input=testingFunctionsfoam)
> 
> cellSize1.ComputeVertexCount = 0  
> cellSize1.ComputeLength = 0  
> cellSize1.ComputeArea = 0
> 
> renderView1.Update()
> 
> SetActiveSource(cellSize1)  
> Data = servermanager.Fetch(cellSize1)
> 
> Data0 = Data.GetBlock(0)  
> Volume\_i = Data0.GetCellData().GetArray(‘Volume’)
> 
> Volume\_i\_np = nps.vtk\_to\_numpy(Volume\_i)  
> Volume\_TOT = np.sum(Volume\_i\_np)
> 
> delta =   
> for i in range(0, numTimesteps):  
> SetActiveSource(cellSize1)  
> Data = servermanager.Fetch(cellSize1)
> 
> Data0 = Data.GetBlock(0)
> 
> H2\_i = Data0.GetCellData().GetArray(‘H2’)
> 
> H2\_i\_np = nps.vtk\_to\_numpy(H2\_i)
> 
> H2\_i\_Volume\_i = np.multiply(H2\_i\_np, Volume\_i\_np)
> 
> sumH2\_i\_Volume\_i = np.sum(H2\_i\_Volume\_i)
> 
> H2\_avg = sumH2\_i\_Volume\_i / Volume\_TOT
> 
> H2\_i\_H2\_avg\_Volume\_i = np.multiply(np.absolute(H2\_i\_np - H2\_avg), Volume\_i\_np)
> 
> sum\_H2\_i\_H2\_avg\_Volume\_i = np.sum(H2\_i\_H2\_avg\_Volume\_i)
> 
> if sumH2\_i\_Volume\_i \< 1e-16:  
> sumH2\_i\_Volume\_i = 1  
> sum\_H2\_i\_H2\_avg\_Volume\_i = 0   
> delta\_i = 1 - 0.5\*(sum\_H2\_i\_H2\_avg\_Volume\_i/sumH2\_i\_Volume\_i)
> 
> delta.append(delta\_i)
> 
> SetActiveSource(cellSize1)
> 
> cellSize1Display = Show(cellSize1, renderView1, ‘GeometryRepresentation’)
> 
> renderView1.Update()
> 
> animationScene1.GoToNext()  
> print(i)  
> print(delta[i])

Basically, If I suppress the line

> cellSize1Display = Show(cellSize1, renderView1, ‘GeometryRepresentation’)

The timestep do change but the information do not get updated.

I want to execute the code without any window opening.

Do you have any advice?

Thank you.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [October 13, 2020, 3:37pm UTC](https://discourse.paraview.org/t/pvpython-and-postprocessing/5556/2 "2020-10-13T15:37:18Z")

</div>

> [@Propanotriol](#):
>
> I want to execute the code without any window opening.

Try using `pvbatch` instead of `pvpython` or use the command line argument `--force-offscreen-rendering` to pvpython e.g. `pvpython --force-offscreen-rendering ....script.py`.

---

<div class="post-metadata">

### Author: ![Propanotriol](https://discourse.paraview.org/user_avatar/discourse.paraview.org/propanotriol/32/2598_2.png) [@Propanotriol](https://discourse.paraview.org/u/Propanotriol)
#### Post date: [October 15, 2020, 8:06am UTC](https://discourse.paraview.org/t/pvpython-and-postprocessing/5556/3 "2020-10-15T08:06:53Z")

</div>

Thank you for your answer, let me try.

Is pvbatch as powerful as pvpython?

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [October 15, 2020, 11:16am UTC](https://discourse.paraview.org/t/pvpython-and-postprocessing/5556/4 "2020-10-15T11:16:18Z")

</div>

> Is pvbatch as powerful as pvpython?

Yes, they exactly the same. `pvbatch` is intended for non-interactive use-cases (and distributed runs) while `pvpython` is intended for interactive ones.

---

<div class="post-metadata">

### Author: ![Propanotriol](https://discourse.paraview.org/user_avatar/discourse.paraview.org/propanotriol/32/2598_2.png) [@Propanotriol](https://discourse.paraview.org/u/Propanotriol)
#### Post date: [October 17, 2020, 10:01am UTC](https://discourse.paraview.org/t/pvpython-and-postprocessing/5556/5 "2020-10-17T10:01:35Z")

</div>

It works perfectly, I just run the same scripts with pvbatch. Thank you very much for the advice.
