I am new to using GDAL in Python and I am trying to use it to retrieve the band data from Sentinel 2 SAFE-products. I managed to extract the band array, but I couldn't manage to get it scaled correctly.
This extracts the unscaled array of Band 4:
import gdal
product_path = "S2B_MSIL2A_20200124T101219_N0213_R022_T33UUU_20200124T121752.SAFE"
dataset = gdal.Open(product_path + "MTD_MSIL2A.xml")
bands10m_path = dataset.GetSubDatasets()[0][0]
bands10m_dataset = gdal.Open(bands10m_path)
b4_band = bands10m_dataset.GetRasterBand(1)
b4_array = b4_band.ReadArray()
So far so good, but the data type of the array is uint16
and the values range from 0
to 16896
.
b4_band.GetMinimum()
and b4_band.GetMaximum()
both return None
.
And b4_band.GetStatistics(True,True)
returns [0.0, 2829.0, 347.05880000000104, 334.8397839901348]
(as min, max, mean, stddev).
Does this help me somehow to extract the correct scale? I am clueless...