# Problem with volume calculation

**URL:** https://discourse.paraview.org/t/problem-with-volume-calculation/8318
**Category:** ParaView Support
**Created:** [November 4, 2021, 10:43am UTC](https://discourse.paraview.org/t/problem-with-volume-calculation/8318 "2021-11-04T10:43:14Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![benediktB](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/9f8e36/32.png) [@benediktB](https://discourse.paraview.org/u/benediktB)
#### Post date: [November 4, 2021, 10:43am UTC](https://discourse.paraview.org/t/problem-with-volume-calculation/8318/1 "2021-11-04T10:43:14Z")

</div>

Dear community,  
I simulate bubble collapses.  
With a pvbatch-script I want to calculate the volume of the bubble.  
I use the precompiled version ParaView-5.10.0-RC1-osmesa-MPI-Linux-Python3.9-x86\_64  
The following function should do this:

```auto
def Process( file ):
   xdmf = pv.Xdmf3ReaderS( FileName = [file] )
   xdmf.CellArrays = ['levelset']
   bubble = createThreshold( xdmf )
   v = algs.volume( bubble )
   i = sum(v)
   print(i)
   return i

```

The ´createThreshold´ function creates a dataset which contains only the bubble, therefore the name of its result. In the next step, I want to calculate the volume of the complete ´bubble´-dataset  
But during the ´volume ´-algorithm the following error occurs:

```auto
Traceback (most recent call last):
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Validation/johnsen_3d_3/../../track_volume.py", line 86, in <module>
    Main()
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Validation/johnsen_3d_3/../../track_volume.py", line 78, in Main
    i = Process( f )
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Validation/johnsen_3d_3/../../track_volume.py", line 51, in Process
    v = algs.volume( xdmf )
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Paraview/ParaView-5.10.0-RC1-osmesa-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/vtkmodules/numpy_interface/algorithms.py", line 140, in new_dsfunc2
    return dsfunc(ds)
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Paraview/ParaView-5.10.0-RC1-osmesa-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/vtkmodules/numpy_interface/internal_algorithms.py", line 499, in volume
    ds = dataset.NewInstance()
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Paraview/ParaView-5.10.0-RC1-osmesa-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/servermanager.py", line 432, in __ConvertArgumentsAndCall
    return _getPyProxy(retVal)
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Paraview/ParaView-5.10.0-RC1-osmesa-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/servermanager.py", line 2574, in _getPyProxy
    classForProxy = ActiveConnection.ProxiesNS.getClass(smproxy)
  File "/gpfs/scratch/pr62wu/ga87xol2/ALPACA-Hoppe_new_develop/Paraview/ParaView-5.10.0-RC1-osmesa-MPI-Linux-Python3.9-x86_64/lib/python3.9/site-packages/paraview/servermanager.py", line 2787, in getClass
    assert not hasattr(cls, nsname)
TypeError: hasattr(): attribute name must be string

```

Since I use the precompiled files, I can change the file in which the error occurs, but I don’t know, what I have to do.  
Can you help me?  
Or is there a better way to calculate the volume after all?

---

<div class="post-metadata">

### Author: ![pavel](https://discourse.paraview.org/user_avatar/discourse.paraview.org/pavel/32/8287_2.png) [@pavel](https://discourse.paraview.org/u/pavel)
#### Post date: [January 26, 2022, 11:05am UTC](https://discourse.paraview.org/t/problem-with-volume-calculation/8318/2 "2022-01-26T11:05:13Z")

</div>

Hello,

You could try to use _Python calculator_ (from Filters menu) above bubble’s threshold. In the _Expression_ field of this calculator call `volume(inputs[0])` function to have an array with volumes of cells (then you could sum them etc.).

Best Regards,  
Pavel
