I have 5 rasters, each having 10 bands, where each band corresponds to a specific date.
How do I calculate mean values for all 10 bands and save them?
I need to save the mean values in a dataframe like this example:
rasters bands mean date years
raster1 band1 1234 24/01/2000 2000
band2 45213 01/03/2000 2000
band3 4221 12/04/2000 2000
band4 ... ... ....
band10
raster 2 band 1 4521 01/02/2001 2001
band2 1234 04/05/2001 2001
... .... ....
This script calculates mean value for each band in my raster:
raster = gdal.Open("D:/script/NDVI2000.tif")
bands = raster.RasterCount
for band in range(1, bands+1):
data = raster.GetRasterBand(band).ReadAsArray().astype('float')
mean = np.mean(data[data != 0]) #calculate mean without value 0
print("Band %s: Mean = %s" % (band, round(mean, 2)))
Out[2]:
Band 1: Mean = 1712.83
Band 2: Mean = 1803.14
Band 3: Mean = 1662.33
Band 4: Mean = 1868.77
Band 5: Mean = 1900.97
Band 6: Mean = 2031.13
Band 7: Mean = 1847.89
Band 8: Mean = 2185.66
Band 9: Mean = 2081.14
Band 10: Mean = 8248.7
How can I save the mean result stats in the dataframe using gdal python 3 after I have the results for all rasters?
I need this dataframe to plot times series for NDVI.
date
data come from in your output example? – vpipkt Jan 16 '19 at 19:09