I want to make a 32-days composite from 8-days LST data by taking its average value, but I am facing a problem in checking QC-day, the other thing is, due to data gaps (missing DN values) we cannot take its average simply (DN1+DN2+DN3)/3 etc because due to data gaps some value are missing.My problem is when I add all the four images and then divide them by 4 it doesn't give the average values because of missing values. for exp. (2+8+6+0)/4, fourth pixel is missing, how can i exclude the missing values and specify the average of existing values? if someone knows any code/proper method, please share and help me
You specified python, So I am assuming you are familiar how to use GDAL to load the images into numpy arrays. This assumes that you stacked 4 8-day composites into a 3D numpy array, where each layer along the z-axis represents one image (just like if you would stack them as a multilayer image).
import numpy as np # load your data into a 3D numpy array of the shape(layer, Y, X) composite8_stack # this is your image stack, as produced by gdal.ReadAsArray() no_data = -32768 # insert the NoData value of you images here composite8_stack[composite8_stack == no_data] = np.NaN #replace NoData values # calculate the mean along the z-axis while ignoring NoData values composite32 = np.nanmean(composite8_stack, axis=0)
The numpy function
axis=0 (the z-axis, layers) does exactly what you want - calculating the mean only from valid observations. Using this it should be easy to loop through your list of images, read 4 8-day composites at a time and produce the 32-day composite from them.
Reclassify 0 as NoData. If you are using arcpy you need spatial analyst extension.
In ARCPY use Cell Statistics, you just need ignore NoData http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/cell-statistics.htm