Search code examples
rastergdalosgeo

Cannot Run Raster Calculation Using GDAL


I am having some trouble running a raster calculation through GDAL. I am attempting to convert a raster to dB through the equation below.

A = my raster file

"10*log10(power(A,2))-83"

Using gdal_calc it looks like the following.

C:\>gdal_calc.py -A "C:\Users\moses\Desktop\Calc_Test\test444.img" 
--outfile="C:\Users\moses\Desktop\Calc_Test\test555.img" 
--calc="10*log10(power(A,2))-83" --debug --overwrite

I have attempted to do this in separate pieces. So, raise the raster to the second power, then get log10 of that result. But each time that I do this i recieve the following error...

:1: RuntimeWarning: divide by zero encountered in log10

Any idea on how I might go about resolving this?

Thanks in advance for any potential help.


Solution

  • Apparently some of your pixel values contain zeros. So if you take log10(0), it returns -Inf which causes the error.

    Try this:

    C:\>gdal_calc.py -A "C:\Users\moses\Desktop\Calc_Test\test444.img" --outfile="C:\Users\moses\Desktop\Calc_Test\test555.img" --calc="10*log10(power(A+0.0001,2))-83" --debug --overwrite
    

    Or set your 0 values to NA.