Advertisement
Guest User

Untitled

a guest
Aug 17th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. var L8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_TOA")
  2. .filterDate('2016-06-01', '2016-07-31') // you can change date here
  3. .filter(ee.Filter.lt("CLOUD_COVER", 0.75))
  4. .filterBounds(collection[i])
  5. .map(maskLandsatclouds)
  6. .sort('DATE_ACQUIRED')
  7. .select(L8bands)
  8.  
  9. var count = L8.size();
  10. for (var j=0;j< 10 ;j++){
  11. // Get the number of images.
  12. print(j);
  13.  
  14. var mosaic_L8 =L8.median().clip(collection[i]); // here we are taking the
  15. median at each pixel in the collection
  16. Map.addLayer(mosaic_L8, L8vis, "mosaic_L8")
  17.  
  18. // Create an NDWI image, define visualization parameters and display.
  19. var ndwi = mosaic_L8.normalizedDifference(['B3', 'B5']);
  20.  
  21. var ndwiViz = {min: 0.5, max: 1, palette: ['44c9f1', '1637f1']};
  22. //Map.addLayer(ndwi, ndwiViz, 'NDWI', false);
  23.  
  24. // Mask the non-watery parts of the image, where NDWI < 0.10.
  25. var ndwiMasked = ndwi.updateMask(ndwi.gte(0.10));
  26. Map.addLayer(ndwiMasked, ndwiViz,'NDWI masked '+ ee.Number(j).getInfo());
  27.  
  28. Map.centerObject(ndwiMasked);
  29.  
  30. // // NDWI expression
  31. var ndwiL8 = mosaic_L8.expression(
  32. '(G - NIR) / (G + NIR)' , {
  33. 'NIR' : mosaic_L8.select('B5'),
  34. 'G' : mosaic_L8.select('B3')
  35. } ) ;
  36.  
  37. // NDWI math operation
  38. var ndwi_L8 = mosaic_L8.select('B3').subtract(mosaic_L8.select('B5'))
  39. .divide(mosaic_L8.select('B3').add(mosaic_L8.select('B5')));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement