Building time-lapse imagery with Google Earth Engine

If you have an hour (or 3) to spare then there are certainly worse things to do than to investigate the last 30 or so years of time-lapsed imagery on Google Earth Engine Timelapse. It can make for uncomfortable viewing as ice retreats or urban areas expand at a phenomenal rate. It can inform you; watch the explosion of activity in the Barnett Shale and you might get an insight into the fall in oil price. It can shock you as lakes dry up in front of your eyes. It is the Wikipedia equivalent of Earth Observation. A time-lapse image certainly does say a thousand words.

Undoubtedly this is an amazing creation. If you have ever worked with Satellite data you instantly have an appreciation of the effort involved here. Whether it is the filtering for cloud free images (some places are much cloudier than others), accounting for sensor failures (Landsat 7 ETM) or balancing the imagery there are plenty of challenges here. Not only would the cost of this imagery but the physical computer processing power to process it would have made this project virtually impossible at the start of this decade.

And now?

 

Well now…

 

You can do this yourself!

 

Google Earth Engine (GEE)

I have written about Google Earth Engine before and I will certainly build on it in the future as this really is a brilliant evaluation tool for Earth Observation projects. You want to look over the last year of Sentinel 1 data? You could download each acquisition and process each data set, but if you want to do this fast, Google Earth Engine is the perfect tool. Remember to abide by the licensing terms.

1.2 Limitations on Use. Services may only be used for development, research, or educational purposes. Services may not be used for sustained commercial purposes, but may be evaluated in a production environment. Applications and data created with Services may not be sold or licensed for a fee.

How to create your own time lapse imagery in Google Earth Engine

You have a choice with GEE – it’s JavaScript or Python. My preference is for Python and I will use that in the example here. The code is pretty much interchangeable to be honest, it is not too much effort to convert between languages.

Below is a Python script to produce a timelapse .mp4 file of all the Landsat 8 imagery (5% cloud cover) over the Dubai area in the UAE.

import ee
from ee import batch

## Initialize (a ee python thing)
ee.Initialize()

## define your collection
collection = ee.ImageCollection('LANDSAT/LC8_L1T_TOA')

#Dubai Path and Row
path = collection.filter(ee.Filter.eq('WRS_PATH', 160))
pathrow = path.filter(ee.Filter.eq('WRS_ROW', 43))
 
##Filter cloudy scenes.
clouds = pathrow.filter(ee.Filter.lt('CLOUD_COVER', 5))

## select the bands, we are going for true colour... but could be any!
bands = clouds.select(['B4', 'B3', 'B2'])

##make the data 8-bit.
def convertBit(image):
    return image.multiply(512).uint8()  

## call the conversion    
outputVideo = bands.map(convertBit)

print "about to build video"

#Export to video.
# Dubai
out = batch.Export.video.toDrive(outputVideo, description='dubai_video_andy2', dimensions = 720, framesPerSecond = 2, region=([55.6458,25.3540], [54.8135,25.3540],[54.8135,24.8042],[55.6458,24.8042]), maxFrames=10000)

## process the image
process = batch.Task.start(out)

print "process sent to cloud"

 

You will import GEE and initalise it, then define the image collection you want to access, in this case Landsat 8 TOA (Top Of Atmosphere), filter it on path and row then cloud cover and then the bands you wish to display. Convert the image to 8 bit for video output and then export to your google drive (in the example above I am setting a region to clip the data to dimensions, frames per second and maximum number of frames). I have tried to write the code so it is simple to understand, instead of the fewest lines.

Make it more reusable

What happens though if you don’t know the path and row number? You shouldn’t need to know this, right? you just want the data. Perhaps you only have a coordinate? Well Earth Engine will allow you to parse a coordinate or in fact an area (fusion table or nested loop of coordinates) and get the imagery in that vicinity.

 

#Dubai Path and Row
#path = collection.filter(ee.Filter.eq('WRS_PATH', 160))
#pathrow = path.filter(ee.Filter.eq('WRS_ROW', 43))


pointUAE = ee.Geometry.Point(55, 25)
pathrow = collection.filterBounds(pointUAE)

I have commented out the path and row search and replaced it with a point. This is not 100% foolproof as you are reliant upon GEE picking the data that will cover your area, but it is fast if you just want to quickly get an output. Alternatively you could always define a polygon instead.

polyUAE = ee.Geometry.Polygon([[55.6458,25.3540], [54.8135,25.3540],[54.8135,24.8042],[55.6458,24.8042]])
pathrow = collection.filterBounds(polyUAE)

Here is my output

or perhaps a False colour? Vegetation appears in red

Decades of imagery is in your hands. What do you want to see in time series? Utilise the full range of spectral bands, merge images from different sensors. There is massive potential.

The code is available on my github page.

I have grouped all my previous blogs (technical stuff / tutorials / opinions / ideas) are here http://gis.acgeospatial.co.uk

I am @map_andrew on twitter