Averaging Vegetative Sentinel 2 Imagery with Python!

Emery Silberman
2 min readAug 9, 2020

When trying to see how a farm field has done over the course of a year or how it compares to previous years, it becomes very difficult to use individual imagery snapshots as these will tend to overwhelm the viewer with too much data. With a satellite taking a snapshot of a field every 5–7 days, a years worth of farm imagery can be 30–40 snapshots! Also, since not all fields are planted at the same time, it becomes incredibly difficult to follow trends.

Maybe you have a repository of imagery like this?

My solution to this is to average the imagery! I’ve written about this before, but that was the manual process and it definitely tests your patience. This sounds like a job for programming!

To get this going, we need to assemble all the imagery that we want to average into one folder (I’ve grouped by year). Then, using the following script, python will load each image in the folder into GDAL and take the average then spit out a single averaged geotiff!

Notes on running this script: I used python 3.7 so make sure you use at least 3.7. Also make sure you’ve installed the dependencies such as numpy and gdal.

GeoTIFF averaging script.

Just toss a cool color scale on the imagery and you’ve got yourself a nice piece of agricultural information to look at!

Extra Credit: Want to clip a bunch of imagery to a shapefile? Here’s a little script to do just that to a folder of tiffs.

--

--

Emery Silberman

Working to solve to worlds problems starting with technology in agriculture.