Shaun Levick https://www.geospatialecology.com

Environmental Monitoring and Modelling

Lab 10 - Communicating Google Earth Engine discoveries

Objective

The goal of this lab is to gain understanding of different ways of communicating discoveries you make in Google Earth Engine - including the publishing of maps, charts and animated time-lapse videos.

Acknowledgments

Maps

We have use the mapping feature of Earth Engine in all of the previous labs (Map.addLayer). Once aspect we have not covered so far is how to add a legend to a map. I have provide two examples below that you can modify for categorical or continuous data.

  • Generic approach for categorical data
// set position of panel
var legend = ui.Panel({
  style: {
    position: 'bottom-left',
    padding: '8px 15px'
  }
});

// Create legend title
var legendTitle = ui.Label({
  value: 'My Legend',
  style: {
    fontWeight: 'bold',
    fontSize: '18px',
    margin: '0 0 4px 0',
    padding: '0'
    }
});

// Add the title to the panel
legend.add(legendTitle);

// Creates and styles 1 row of the legend.
var makeRow = function(color, name) {

      // Create the label that is actually the colored box.
      var colorBox = ui.Label({
        style: {
          backgroundColor: '#' + color,
          // Use padding to give the box height and width.
          padding: '8px',
          margin: '0 0 4px 0'
        }
      });

      // Create the label filled with the description text.
      var description = ui.Label({
        value: name,
        style: {margin: '0 0 4px 6px'}
      });

      // return the panel
      return ui.Panel({
        widgets: [colorBox, description],
        layout: ui.Panel.Layout.Flow('horizontal')
      });
};

//  Palette with the colors
var palette =['ff0000', '00ff00', '0000ff'];

// name of the legend
var names = ['Red','Green','Blue'];

// Add color and and names
for (var i = 0; i < 3; i++) {
  legend.add(makeRow(palette[i], names[i]));
  }  

// add legend to map (alternatively you can also print the legend to the console)
Map.add(legend);
  • Gradient legend for continuous data
var chirps = ee.ImageCollection("UCSB-CHG/CHIRPS/PENTAD")

// Calculate rainfall in 2009
var P = chirps.select("precipitation").filterDate('2009-01-01', '2009-12-31').sum()

// create vizualization parameters
var viz = {min:0, max:3500, palette:['ffffff','b7f0ae','21f600','0000FF','FDFF92','FF2700','d600ff']};

// add the map
Map.addLayer(P, viz);

// set position of panel
var legend = ui.Panel({
style: {
position: 'bottom-left',
padding: '8px 15px'
}
});

// Create legend title
var legendTitle = ui.Label({
value: 'Rainfall (mm)',
style: {
fontWeight: 'bold',
fontSize: '18px',
margin: '0 0 4px 0',
padding: '0'
}
});

// Add the title to the panel
legend.add(legendTitle);

// create the legend image
var lon = ee.Image.pixelLonLat().select('latitude');
var gradient = lon.multiply((viz.max-viz.min)/100.0).add(viz.min);
var legendImage = gradient.visualize(viz);

// create text on top of legend
var panel = ui.Panel({
widgets: [
ui.Label(viz['max'])
],
});

legend.add(panel);

// create thumbnail from the image
var thumbnail = ui.Thumbnail({
image: legendImage,
params: {bbox:'0,0,10,100', dimensions:'10x200'},
style: {padding: '1px', position: 'bottom-center'}
});

// add the thumbnail to the legend
legend.add(thumbnail);

// create text on top of legend
var panel = ui.Panel({
widgets: [
ui.Label(viz['min'])
],
});

legend.add(panel);

Map.add(legend);

Charting

We have also explored a number of different charting options in previous lab, but once you become more familiar with JavaScript you will find that you have huge flexibility in the way you present data in graphs.

The Google Earth Engine Developer Guide covers and provides a nice set of examples here:

Time-lapse animations

Earlier in the class we looked at some of the examples of Google Earth Time-lapse. These are very powerful for communicating changes in landscapes. You can develop you own time-lapses using and modifying the example below.

Note: first run the script below to see the location of the Landsat tile in your map view, and then draw in a geometry polygon (roi) within that area to clip your video area.

// Load a Landsat 8 image collection and define path and row.
var collection = ee.ImageCollection('LANDSAT/LC08/C01/T1_TOA')
  // Northern Territory.
  .filter(ee.Filter.eq('WRS_PATH', 105))
  .filter(ee.Filter.eq('WRS_ROW', 69))
  // Filter cloudy scenes.
  .filter(ee.Filter.lt('CLOUD_COVER', 10))
  // Get 20 years of imagery.
  .filterDate('2013-05-01','2019-09-30')
  // Need to have 3-band imagery for the video.
  .select(['B7', 'B5', 'B3'])
  // Need to make the data 8-bit.
  .map(function(image) {
    return image.multiply(512).uint8();
  });

//Map the mean pixel value. Note the unsual range of min and max for Landsat, thsi is because we have converted to 8-bit data.
Map.addLayer(collection.median(), {min:0,max:200}, 'Median')

// Define an area within the tile to export using the rectangle geometry
var polygon = roi

// Export (change dimensions or scale for higher quality).
Export.video.toDrive({
  collection: collection,
  description: 'L8VideoExample',
  dimensions: 720,
  framesPerSecond: 12,
  region: polygon
});

Exercise

Modify the time-lapse video export code above to create a time-lapse of mangrove dynamics along the coast of the Gulf of Carpentaria .


GEARS - Geospatial Ecology and Remote Sensing - https://www.geospatialecology.com

(c) Shaun R Levick