Fall 2023 Lecture - Lab 19
Objective: In this lab, you will learn how to create an animated image series and a filmstrip using Google Earth Engine. You will work with an ImageCollection to filter, composite, sort, and visualize images before generating the final outputs.
Overview: You will go through the following steps:
1. Filtering
2. Compositing
3. Sorting
4. Image visualization
Lab Instructions:
1. Introduction and setup
- Go to Google Earth Engine (https://earthengine.google.com/)
- Sign in with your Google account
- Create a new script and name it something like "Lab19_Animation_Filmstrip"
2. Filtering
- Start by importing a dataset you want to work with in the script editor. For example, you can use the MODIS Terra Vegetation Indices 16-Day Global 1km dataset and select the NDVI band:
-
var col = ee.ImageCollection('MODIS/006/MOD13A2').select('NDVI'); - Now, filter the ImageCollection to include only the relevant data based on dates, spatial extent, and other properties. You can use the filterDate and filterBounds methods for this purpose.
-
// Filter the ImageCollection based on dates and spatial extent
var startDate = '2018-01-01';
var endDate = '2018-12-31';
var regionOfInterest = ee.Geometry.Rectangle([-18.698368046353494, 38.1446395611524, 52.229366328646506, -36.16300755581617]);
var filtered = col.filterDate(startDate, endDate)
.filterBounds(regionOfInterest);
3. Compositing
- Create a composite image by reducing the images within the desired date ranges. This will help to reduce the number of images in the collection and improve quality. Use the reduce method to achieve this.
-
// Composite images within a date range using the median reducer
var composite = filtered.reduce(ee.Reducer.median());
4. Sorting
- Sort the collection by time to ensure the proper chronological sequence. You can use the sort method and the system:time_start property to sort the collection by time.
-
// Sort the collection by time
var sorted = filtered.sort('system:time_start');
5. Image visualization
- Visualize the images in the collection by mapping image bands to color channels or grading values of a single band along a color palette. Use the getVideoThumbURL and getFilmstripThumbURL methods to achieve this.
-
// Define visualization parameters
var visParams = {
min: 0.0,
max: 9000.0,
palette: [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
};
// Visualize the images in the collection
var visualized = sorted.map(function(image) {
return image.visualize(visParams);
});
6. Generate the outputs
- Create an animated image series using the getVideoThumbURL method, and a filmstrip using the getFilmstripThumbURL method. Define the necessary parameters for both methods, such as region, dimensions, and framesPerSecond.
- Print the URLs for both the animation and the filmstrip. You can also render the animation and the filmstrip directly in the console using the ui.Thumbnail function.
-
// Define parameters for getVideoThumbURL and getFilmstripThumbURL methods
var outputParams = {
'region': regionOfInterest,
'dimensions': 600,
'crs': 'EPSG:3857',
'framesPerSecond': 10
};
// Create an animated image series
var animationUrl = visualized.getVideoThumbURL(outputParams);
print("Animation URL:", animationUrl);
// Create a filmstrip
var filmstripUrl = visualized.getFilmstripThumbURL(outputParams);
print("Filmstrip URL:", filmstripUrl);
// Render the animation and the filmstrip directly in the console
print("Animation:", ui.Thumbnail(visualized, outputParams));
print("Filmstrip:", ui.Thumbnail(visualized, outputParams));
Congrats, you made a gif. It should look like this:
![]()
7. Challange
- Now that you have worked through the example,, could you change it up? Create a gif at a different scale or location. Modify the code to show a different convenience, for example, or zoom in or out to show something interesting. Or, if you want to have a lot of fun, try out a different dataset. Read: https://developers.google.com/earth-engine/guides/ic_visualization for some more ideas.
- After completing the lab and challenge, save your script by clicking the "Save" button at the top of the script editor. Make sure you comment well your code.
- Share your work with by clicking the "Share" button and providing the generated link here on Canvas.
Lab Submission
Submit lab via email.
Subject: Lab 19 - Making GIFs and Videos of Environmental Change - [Your Name]