Advertisement
petrovnn

Untitled

Nov 26th, 2020
791
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Function to mask clouds using the Sentinel-2 QA band
  3.  * @param {ee.Image} image Sentinel-2 image
  4.  * @return {ee.Image} cloud masked Sentinel-2 image
  5.  */
  6. function maskS2clouds(image) {
  7.   var qa = image.select('QA60');
  8.  
  9.   // Bits 10 and 11 are clouds and cirrus, respectively.
  10.   var cloudBitMask = 1 << 10;
  11.   var cirrusBitMask = 1 << 11;
  12.  
  13.   // Both flags should be set to zero, indicating clear conditions.
  14.   var mask = qa.bitwiseAnd(cloudBitMask).eq(0)
  15.       .and(qa.bitwiseAnd(cirrusBitMask).eq(0));
  16.  
  17.   return image.updateMask(mask).divide(10000);
  18. }
  19.  
  20. var dataset = ee.ImageCollection('COPERNICUS/S2_SR')
  21.                   .filterDate('2020-06-01', '2020-08-30')
  22.                   // Pre-filter to get less cloudy granules.
  23.                   .filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',20))
  24.                   .map(maskS2clouds)
  25.                   .median();
  26.  
  27. var visualization = {'bands':['B4','B3','B2'],'min': 0,'max': 0.3};
  28.  
  29. Map.setCenter(28.3, 57.85, 7);
  30.  
  31. Map.addLayer(dataset, visualization, 'RGB'); // .dataset.mean()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement