I want to know the basic stats (max, min, mean, std) of my raster file. I use two different methods and get similar, but different results. I assume the results should be exactly the same with any method, is that right? What am I doing wrong?
Let' use this single band raster as test file.
Method 1 (gdal on python)
from osgeo import gdal myRaster = 'path/to/input.tiff' gtif = gdal.Open(myRaster) srcband = gtif.GetRasterBand(1) stats = srcband.GetStatistics(True, True) print ('Minimum: %.3f\nMaximum: %.3f\nMean: %.3f\nStDev: %.3f' % (stats, stats, stats, stats))
With Method 1 I get the following values:
Method 2 (gdalinfo from command line)
I simply use the command
gdalinfo input.tiff -stats
I get the whole stats including:
This means that both methods result in the same Minimum value (-63.630 in both cases), but differ in the Maximum value (with concomitant differences in Mean and Standard Deviation). I read somewhere that there can be some problems with how to treat NaN values, but I am not sure this is the problem here.
Edit 00: I just tried the same using
rasterio and it gives exactly the same values (for all 4 stats) as the command-line gdalinfo