An important concept in spatial statistics is pixel weights. When calculating pixel statistics with a polygon, partial pixel overlaps are treated differently by different packages and you need to understand this to evaluate the accuracy of your results. Consider the following image. What is the correct answer?
The answer to the above question really depends on how you decide which pixels are within the polygon and if so, do you consider them to be fully or partially inside. Different geospatial software account for these differently.
QGIS considers only the pixels whose centroid is within the region and assigns a weight of 1 to these pixels and 0 to others. There is no support for partial pixels. Users need to vectorize the rasters and perform analysis in vector space if they need accurate weighted statistics. This may not be feasible for large rasters. Check this stackexchange post for more details.
Popular packages such as rasterstats considers all pixels whose centroid is within the region as weight 1 and ignores others. rasterio is similar but has an option
all_touched which includes all pixels that are touched by the region. There is no support for partial pixels.
Google Earth Engine
GEE uses weighted reducers by default – meaning it considers the proportional value of partial pixels when computing statistics. You have the option to run the computation in un-weighted mode resulting in all pixels being considered equal weight. I explain more in the video linked here.
There is an open-source tool – exactextract – that does weighted statistics accounting for partial pixel overlaps. It’s a command-line tool that is designed to overcome the limitation of other open-source geospatial tools while computing zonal statistics.
The bottom line? The difference in the results is small when you are working with higher resolution rasters with small pixels but become significant when you are working with gridded rasters with large pixels. Understanding how your software deals with partial pixels will help you evaluate the high accuracy of your results.