[GIS] Mask clouds in LandSat 8 surface refletance image

google-earth-enginelandsatndvi

I would like to know how to remove the clouds in a ImageCollection of LandSat 8 Surface Reflectance (SR) image and create a single image without clouds using google earth engine, to calculate NDVI. I wore a javaScrit code to remove clouds in Landsat 8 TOA Reflectance, but it doesn't work for SR imagens…

Best Answer

The Surface Reflectance products contain a band called 'cfmask' and 'cfmask_conf'. The documentation tells you that all pixels labelled 4 in the first band are clouds. If you just want to mask clouds from your NDVI calculation you just have to update the image mask. If you want to do an ImageCollection you simply have to .map it as a function.

An example image from the alps with only clouds masked from the NDVI as well as an NDVI time-series from the region. The great thing about the EarthEngine is that instead of the NDVI mean you can also look at the NDVI time-series for selected areas.

// single image
var lt8 = ee.Image('LANDSAT/LC8_SR/LC81930272016103')

var lt8_ndvi = lt8
  .normalizedDifference(['B4', 'B5'])  // calculate NDVI
  .updateMask(lt8.select(['cfmask']).neq(4))  // mask everything labeled 'cloud'

// Map.centerObject(lt8_ndvi, 10)
Map.addLayer(lt8_ndvi, {}, "LC81930272016103 NDVI cloud masked", 0)

// image collection
var lt8_ic = ee.ImageCollection('LANDSAT/LC8_SR')
  .filterBounds(aoi)  // filter to area-of-interest
  .filterDate(ee.Date("2016-01-01"),ee.Date("2016-12-31"))  // filter to 2016

var lt8_ndvi_ic = lt8_ic
  .map(function(img){  // add cloud free NDVI to all images
  return img.addBands(img.normalizedDifference(['B4', 'B5'])).updateMask(img.select(['cfmask']).neq(4))
  });

print(lt8_ndvi_ic)

Map.centerObject(testPoint, 10)
var ndvi_viz = {min:-0.8, max:0.3, palette:'000000,00FF00'};
Map.addLayer(lt8_ndvi_ic.select('nd').mean(), ndvi_viz, "LT8 2016 NDVI mean")

// NDVI time-series chart
// Create and print the chart.
print(ui.Chart.image.series(lt8_ndvi_ic.select('nd'), testPoint, ee.Reducer.mean(), 30));