Mapping Functions Across Image Collections

Yes! Incredibly fast calculations on Image collections!

This introductory training is part of the official training materials prepared by the United States Department of Agriculture.

The Code Editor offers access to the full power of Earth Engine; however, a basic understanding of the fundamentals of coding and JavaScript is required. In this exercise, you will continue to learn about JavaScript syntax and some new Earth Engine spatial data concepts. You will build what you learned in exercise two about image objects; however you will now turn your focus to working with collections of images, or stacks of similar image objects. In this exercise, you will focus on basic concepts and methods associated with image collections in Earth Engine. This is an introduction to get users writing some simple JavaScript scripts.

Mapping Functions Across Image Collections

1. Now that we know our function works, let’s apply it to the image collection that you created in the first half of this exercise.

2. Copy the cloud masking function (just the lines below).

var cloudfunction = function(image){
//use add the cloud likelihood band to the image
var CloudScore = ee.Algorithms.Landsat.simpleCloudScore(image);
//isolate the cloud likelihood band
var quality = CloudScore.select('cloud');
//get pixels above the threshold
var cloud01 = quality.gt(cloud_thresh);
//create a mask from high likelihood pixels
var cloudmask = image.mask().and(cloud01.not());
//mask those pixels from the image
return image.mask(cloudmask);
}

3. Next open up the script from earlier, named ‘Ex 3 Image Collection Part 5’.

4. Paste the cloud filter function and the cloud_thresh variable into the script (after the lines that created the filtered image collection, but before the median reducer). See full example below.

// Get a collection.
var L8_collection = ee.ImageCollection('LANDSAT/LC8_L1T_TOA');

// Filter to scenes that intersect your boundary
var L8_StudyArea = L8_collection.filterBounds(StudyArea);

// Filter to scenes for a given time period
var L8_SA_2015 = L8_StudyArea.filterDate('2015-01-01', '2015-12-31');
print(L8_SA_2015, 'L8_SA_2015');

var cloud_thresh = 40;

var cloudfunction = function(image){
//use add the cloud likelihood band to the image
var CloudScore = ee.Algorithms.Landsat.simpleCloudScore(image);
//isolate the cloud likelihood band
var quality = CloudScore.select('cloud');
//get pixels above the threshold
var cloud01 = quality.gt(cloud_thresh);
//create a mask from high likelihood pixels
var cloudmask = image.mask().and(cloud01.not());
//mask those pixels from the image
return image.mask(cloudmask);
};

//reduce to median value per pixel
var median_L8_2015 = L8_SA_2015.median();
print(median_L8_2015, 'median_L8_2015');
//add layers
Map.addLayer(median_L8_2015,
  { min:0.05, max: 0.8, bands: 'B6, B5, B4'}, 'median_L8_2015 with clouds');
Map.centerObject(StudyArea, 7);

5. Now add a statement that maps the function across our image collection. Then add the image collection with clouds masked to the map display. See example map statement below.

var L8_SA_2015NoClouds = L8_SA_2015.map(cloudfunction);
Map.addLayer(ee.Image(L8_SA_2015NoClouds.first()),
  {min:0.05, max: 0.8, bands: 'B6, B5, B4'}, 'first image no clouds');

Map.centerObject(StudyArea, 7);

6. Change the median reducer statement to run on the L8_SA_2015NoClouds image collection that you just created. See example code below.

//reduce to median value per pixel
var median_L8_2015 = L8_SA_2015NoClouds.median();
print(median_L8_2015, 'median_L8_2015');
//add layers
Map.addLayer(median_L8_2015,
  {min:0.05, max: 0.8, bands: 'B6, B5, B4'}, 'median composite of cloud free images');

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s