ee.ImageCollection

Adding an Image on it's own is useful, but sometimes it's easier to search through a collection of images and filter according to their properties.

The Data Catalog supplies Images often as part of an ImageCollection, which is a stack or sequence of Images.

Sentinel ImageCollection

Here, we're going to look through the Sentinel Collections, made available by the European Commission and European Space Agency's Copernicus Program. It contains vast amounts of data which can be explored in the GEE Data Catalog:

Screenshot of the Sentinel Collection in the GEE data catalog https://developers.google.com/earth-engine/datasets/catalog/sentinel

Adding a Collection is straightforward - Earth Engine supplies a snippet that can be copied and used in Code Editor:

S2a MSI ImageCollection landing page, GEE Data Catalog

Filtering an Image

You can filter an ImageCollection by dataset properties, such as dates, spatial extent, quality etc.

For the polar regions, it is useful to filter by date to remove times without sunlight, area of interest, or cloud cover.

You can also chain filters so you apply them all at once:

var s2_filter = ee.ImageCollection('COPERNICUS/S2_SR')  
                .filterDate('2022-01-01', '2022-05-01')  
                .filterBounds(ee.Geometry.Point(-68.124, -67.5679))  
                .filter('CLOUDY_PIXEL_PERCENTAGE < 50');

Sorting an ImageCollection

Sometimes it is useful to sort a collection by properties such as by observation time, cloud cover etc.

ee.ImageCollection('').sort('property')

This can look like:

var s2_sort_obs = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterBounds(ee.Geometry.Point(-68.124, -67.5679))
  .filterDate('2022-11-01', '2022-03-01')  
  // Sort by observation time:
  .sort('system:time_start');

Or by cloudiness:

var s2_sort_clouds = ee.ImageCollection('COPERNICUS/S2_SR')
  .filterBounds(ee.Geometry.Point(-68.124, -67.5679))
  .filterDate('2022-01-01', '2022-05-01')
  // Sort by Cloud parameter: 
  .sort('CLOUDY_PIXEL_PERCENTAGE');

Reducing Images

Filtering an ImageCollection often results with multiple images.

This can be reviewed in the CodeEditor by printing the results in the Console:

var s2_filter = ee.ImageCollection('COPERNICUS/S2_SR')  
                .filterDate('2021-09-01', '2022-03-01')  
                .filterBounds(ee.Geometry.Point(-68.124, -67.5679))  
                .filter('CLOUDY_PIXEL_PERCENTAGE < 50')
                
var s2_filter_rgb = s2_filter.select(['B4', 'B3', 'B2']);

print('s2_filter_rgb', s2_filter_rgb)

In the Console we can see that this filter has resulted in 11 images:

Screenshot of GEE Code Editor, showing the Console tab. In this case, filtering the ImageCollection has resulted in the selection of 11 Images.

While this is useful, it would be easier if we only had one image to manage. We can do this by reducing the ImageCollection by value. In this case, we can look for the Median values across each pixel.

ee.ImageCollection.median

This can look like:

var s2_filter = ee.ImageCollection('COPERNICUS/S2_SR')  
                .filterDate('2021-09-01', '2022-03-01')  
                .filterBounds(ee.Geometry.Point(-68.124, -67.5679))  
                .filter('CLOUDY_PIXEL_PERCENTAGE < 50')


var s2_filter_rgb = s2_filter.select(['B4', 'B3', 'B2'])

var composite = s2_filter_rgb.median();

print('median composite:', composite)

And now the Console shows that the result is one single Image, composed of the 3 bands:

Screenshot of GEE Code Editor, showing the Console tab. In this case, selecting the median values of the filtered ImageCollection has resulted in the selection of 1 Image.

Last updated