1
import numpy as np
from gdalconst import*
band = 'band1.tif'
band1_12 = dataset1_12.GetRasterBand(1)
max = band1_12.GetMaximum() 
print(max) #this gives 2425.0

data1 = np.array(band1_12.ReadAsArray()).astype(np.float)
data1 = data1.flatten()
max = np.amax(data1)
print(max) #this gives 1977.0

What is the possible cause of error? Also if I use gdalinfo band1.tif , I see the max value as 2425

I am using gdal version- '1100100' and python 3 on Jupyter Notebook.

Link to file band1.tif -here

  • 2
    What software are you using? GDAL? If so, please edit your question or at least the tags to clarify. – Fezter May 9 '17 at 5:08
  • Yes GetMaximum() is a function of gdal library. – Sumedha Khatter May 9 '17 at 7:15
  • If you supply the version number of both GDAL and python, someone might point to a (previous) bug. Where did you download GDAL from or have you build it your self? If you supply the contents of dataset1_12 or band1_12 someone might try to replicate your test. – Chau May 9 '17 at 7:21
  • Chau I have added all the details, you asked.Thanks! – Sumedha Khatter May 9 '17 at 8:03
  • Your question remains quite unclear so I think you should review and edit it some more. I think it may be that you are trying to understand why band1_12.GetMaximum() gives a different result to np.amax(data1) but from what I can see you have not provided a code snippet or snippets that a tester could just copy/paste to run your test. – PolyGeo May 10 '17 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.