I'm using GDAL and numpy so far in my Python program. I am able to get the max and min values of a band within a .grib2 file with:
def getDataStats(grib2Filepath, bandNr):
local_minimum = None
local_maximum = None
file = gdal.Open(grib2Filepath)
srcband = file.GetRasterBand(bandNr)
fileStats = srcband.GetStatistics(True, True)
local_minimum = fileStats[0]
local_maximum = fileStats[1]
I am trying to get the coordinates that correspond to the maximum and minimum values. I've tried:
data_array = srcband.ReadAsArray().astype(float)
(y_index, x_index) = np.nonzero(data_array == local_minimum)
But
print(f"min: {local_minimum}, max: {local_maximum}, x: {x_index}, y: {y_index}")
serves
min: -51.380010986328, max: 36.499993896484, x: [], y: []