# Grdvolume for volume calculation

Edit: this is very confusing. Pardon messy post.

I’m using grdvolume, and wondering if I’m using it correctly and understand what it does. Tips appreciated!

My end goal: calculate the volume of water in some region.

Docs
grdvolume

Questions

• the -Sunit controls the unit in the plane; default is meter (`-Se`). Area calculated will then be in m^2. Correct?

• `-Z` only deals with the vertical. Assuming a grid in meter, `-Z0.001` would change the vertical units used in the calculator to kilometers. Correct?

• If using -Z, one should be careful to use a corresponding `-S`. E.g. `-Z0.001` should encourage use of `-Sk`. Correct?

• -C: Why isn’t it a corresponding `-Crlow/high/delta` (Note the `r`) as there is for -C (``-Clow/high/delta`)?

• The docs notes that `-Crcval` calculates the outside volume. So does `-Crlow/high`. Correct? I would like to add a note about his so that it is clear that all uses of `-Cr` will give an outside volume.

• If you omit `-C`, what does the output mean? it is interpreted to mean `-C0`. But I get different results - ever so slightly - but why?
Only area is calculated (the area for all cells), since no z-value given, I assume.

``````# make very simple grid of a sloping surface
\$ gmt grdmath -I1 -R-100/100/-100/100 X = tri.nc

\$ gmt grdvolume -C0 tri.nc
0       19999.96        999996.020931   49.9999010464
\$ gmt grdvolume tri.nc
0       40000   0       0
``````

Possible actions

• I would like to add to the docs that all use of `-Cr` will calculate an outside volume.
• Add a simple figure that illustrates the use of the four different `-C`-variants.

volume and area values from `grdvolume` seems complete nonsense to me:

``````gmt grdvolume tri.nc -C-100
-100	39999.9603271	3999992.06543	99.9999008179
``````

area of 40000 is obviously equvalent to 200x200 (the grid area), volume of 4000000 is obviously equivalent to 200x200x100 which is nonsense actually absolutely correct. Surface area seems wrong on the other hand.
.

I tried to calculate area manually using `grdgradient` and `grdmath`:

``````gmt grdgradient tri.nc -Gtri_grad.nc -A270
gmt grdmath tri_grad.nc AREA ATAN COS DIV SUM = tri_area_SUM.nc
gmt grdinfo tri_area_SUM.nc | grep v_min
tri_area_SUM.nc: v_min: 56898.3476562 v_max: 56898.3476562 name: z
``````

not sure that I have calculated correctly, but at least the area of 56898 is close to manual area calculations 200x200/cos(45 degrees) = 56568.542494924

Might of course be bugs but you are creating a Cartesian grid, no -fg here.

Thanks both of you for answering.
This is meant to be as-easy-as-possible, so cartesian it is.

I made this simple plot of a constant sloping surface to do some mental work trying to figure this out.

Notes

• feels like I’m practising elementery school maths - and failing.
• grdvolume doesn’t take into account the slope This does not matter for the volume calculation, since the ‘area of the hypotenuse’ does not matter - it’s the area of the cross section that is important.

Calcluating the area and volume with help from the plot and checking with grdvolume

• Count the colored squares to get the cross section area used for volume calculation

• I think I understand `-Cr[..]`, and it’s intuitively and geometrically easy to understand the results.

• The small lowermost blue triangle is A = base x height = 2.5 x 2.5 / 2 = 3.125. Multiply by length, which is 20, to get the volume: V = A x length = 3.125 x 20 = 62.5. With grdvolume:

``````\$ gmt grdvolume tri.nc -Cr-10/-7.5
0       49.9999523163   62.4998812676   1.24999881744
``````
• The big blue triangle: A = 5^5 / 2 + 5^2 / 2 = 37.5. V = 37.5 x 20 = 750. With grdvolume:

``````\$ gmt grdvolume tri.nc -Cr-5/0
0       99.9999952316   749.999503791   7.49999539554
``````
• Now lets take the big red one, now using `-C`. This is more awkward as you have to specify a delta. I don’t want to specify any delta, I just want to know the volume between contours 0 and -5. This is exactly as big as the big blue one, so I would expect the exact same volume (V = 750) with the same reasoning as above. However, I get this:

``````\$ gmt grdvolume tri.nc -C0/5/1
0       199.99998       999.999808217   4.99999954109   <-- volume for cont 0 to 10, 10^2/2*20
1       179.999979734   809.999828219   4.4999995523
2       159.999980927   639.999847412   3.99999952316
3       139.999980927   489.999866486   3.49999952316
4       119.999980926   359.999885559   2.99999952316
5       99.9999809265   249.999904633   2.49999952316   <-- volume for cont 5 to 10, 5^2/2*20
``````

So I would get the right answer by subtracting the 0 contour volume from the 5 contour volume, 1000-250 = 750. Why does it do this?

grdvolume-testing.txt (1.2 KB)

I may have time to look at this at some point (my time is pretty restricted). But obviously this is a good opportunity to add some more test scripts for grdvolume and ensure any bugs or “features” are fixed.

1 Like

Super.

Part of the problem is that I don’t know if I’m using it correct, or that it gives ‘wrong’ values. Hence I made the plot and the train of thought.

Andreas, I think you need to replace `*` in arithmetic expressions with something or use it between the quotes. Otherwise `*` results in some font formatting change like changing from upright to italic. It is possible to understand anyway but best to have all the expressions written clearly.

@mkononets: did not think about that. Sorry and thanks! Will fix Fixed.

We should have math markup available sometime soon; see here.

OK so for the “original” 100x100 grid

``````gmt grdvolume tri.nc -C-100
-100	39999.9603271	3999992.06543	99.9999008179
``````

the volume seems correct: (`200*200*200*1/2 = 4000000`)
while the surface area is not correct (`39999.9603271` approx equal to `200*200` which is simply the grid area) meaning slope is not taken into account.
relationship `area*average height = volume` holds: `39999.9603271 * 99.9999008179` equals exactly to `3999992.06543`. This does not make much sense to me, these average height and area values, as long as the area is wrong (unless there is another elementary mistake of mine).

Great sum-up.

Interesting spotting that the volume (by the looks of it; since it equals exactly the number) is computed by taking area x (volume / area). I guess this will work fine when dealing with a simple artifical grid like the one I created, but must surely fail when you have an irregular surface (e.g. real tpopgraphy)…?

I thought this was done in a more robust way, according to the docs; volume integration.

well this is exactly what is written in the `grdvolume`’s documentation:

so a correct volume divided with a wrong area gives not so meaningful “maximal mean height”

So the docs actually reads like `grdvolume` has never been supposed to calculate surface area correctly.
Rather, it calculates the correct volume, as it says in the docs. then divides it with the grid area and also provides the “maximal mean height”. I kind of don’t understand the meaning of the “maximal mean height” calculated this way but that’s a different issue.

Pretty sure my needs at the time was Birds Eye area and not area of actual sloping surface. But should not be hard to add options for this.

You can see the references to my papers what this was used for.