Skip to content

Monthly Cloud Free Composites in Earth Engine

One of the most sought after functions in Earth Engine is the possibility of using deep time stack imagery to create cloud free composites. One of the simplest way of thinking about this is to use reducers that we talked about earlier, where we look at an entire stack of pixels and choose the median value of the distribution of pixel across stack and we end up getting a cloud free composite over the given time period. Depending on the number of images, the actual number of cloud free images in the overall stack your results may need more fine tune adjustments.

composite
Multi Month Composite: A single month is added FCC

For this setup we look at how we added PlanetScope Surface Reflectance data earlier , filtering it using date and Cloud cover for the scene. The next step we are building an function to calculate monthly composites from June to August 2018. Note that this is another way of creating a function where we have inserted the map function and the collection inside the function so it can be run directly. We might be interested in sorting these collections using month and hence we set the month as a metadata for each image in the cloud free composite.

You can get the complete code here or copy and paste it from below

//Add an AOI
var aoi=ee.FeatureCollection("users/io-work-1/vector/subset")

//Zoom to AOI
Map.centerObject(aoi,15)

//Add an image collection
var collection=ee.ImageCollection('users/io-work-1/open-ca/PS4BSR')

//print collection properties
print("Collection",collection)

//Create Monthly Composite from PlanetScope Surface Reflectance
var months = ee.List.sequence(6, 8)

var multimonth = ee.ImageCollection(months
  .map(function(m) {
    var start = ee.Date.fromYMD(2018, m, 1)
    var end = start.advance(1, 'month');
    var image = collection.filterDate(start, end).median();
    return image.set('month', m)
}))

print(multimonth);

//Add a visualization
var vis = {"opacity":1,"bands":["b4","b3","b2"],"min":-433.8386769876429,"max":2822.7077530529555,"gamma":1};

//Add the Image
Map.addLayer(ee.Image(ee.ImageCollection(multimonth).first()).clip(aoi),vis,ee.String('2018-').cat(ee.String(ee.Image(ee.ImageCollection(multimonth).first()).get('month'))).slice(0,6).getInfo())