Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. var ROI = ee.Geometry.Point([141.041807, -34.033391]);
  2.  
  3. var kulkurna_A = ee.Geometry.Polygon([
  4. [
  5. [141.045513, -34.031637], [141.045252, -34.031597], [141.045002, -34.031647],
  6. [141.044686, -34.031915], [141.044520, -34.032018], [141.040777, -34.035606],
  7. [141.040349, -34.036386], [141.041069, -34.036233], [141.041372, -34.035775],
  8. [141.042721, -34.034827], [141.043463, -34.034567], [141.045337, -34.031958]
  9. ]
  10. ]);
  11.  
  12. Map.addLayer(kulkurna_A, {color: 'blue'}, 'Kulkurna_A');
  13.  
  14. var kulkurna_B = ee.Geometry.Polygon([
  15. [
  16. [141.041761, -34.031699], [141.041590, -34.031794], [141.039482, -34.033245],
  17. [141.038768, -34.034018], [141.039511, -34.035584], [141.039796, -34.034948],
  18. [141.039535, -34.033698], [141.040783, -34.032723], [141.041335, -34.032393],
  19. [141.041793, -34.031935]
  20. ]
  21. ]);
  22.  
  23. Map.addLayer(kulkurna_B, {color: 'red'}, 'Kulkurna_B');
  24.  
  25.  
  26. //Center the Map
  27. Map.setCenter(141.041807, -34.033391, 15);
  28.  
  29.  
  30. var ens = [
  31. ee.Feature(kulkurna_A, {label : 'Kulkurna A'}),
  32. ee.Feature(kulkurna_B, {label : 'Kulkurna B'})
  33. ];
  34.  
  35. var collection = ee.FeatureCollection(ens);
  36. //print(collection); //Un comment to see values in console
  37.  
  38. // NDVI: NIR B5 and RED B4
  39. var addNDVI = function(L8) {
  40. var nir = L8.select('B5');
  41. var red = L8.select('B4');
  42. var ndvi = nir.subtract(red).divide(nir.add(red)).rename('NDVI');
  43. return L8.addBands(ndvi);
  44. };
  45.  
  46. // Apply the cloud mask and NDVI function to Landsat 8 imagery and print the chart
  47. var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_RT_TOA")
  48. .filter(ee.Filter.calendarRange(2013,2019,'year'))
  49. .filter(ee.Filter.calendarRange(1,12,'month'))
  50. .filterBounds(ROI)
  51. //Filter the WRS Row to 84 to prevent NDVI readings coming in from the overlap of adjacent rows
  52. //(Landsat.usgs.gov/landsat_acq#convertPathRow)
  53. .filter(ee.Filter.eq('WRS_ROW',84))
  54. //Filter the row
  55. .filter(ee.Filter.eq('WRS_PATH',96))
  56. .map(addNDVI);
  57.  
  58. //------------------------------------------------
  59. //Start graphing results
  60. //------------------------------------------------
  61.  
  62. // Create an empty panel in which to arrange widgets.
  63. // The layout is vertical flow by default.
  64. var panel = ui.Panel({style: {width: '400px'}})
  65. .add(ui.Label('NDVI Charts'));
  66.  
  67. // Define customisation options.
  68. var options = {
  69. title: {label: ens},
  70. hAxis: {title: 'Time'},
  71. vAxis: {title: 'NDVI'},
  72. lineWidth: 2,
  73. pointSize: 3,
  74. series: {
  75. 0: {color: 'blue'}, //Colour of Chart
  76. }};
  77.  
  78. //Graph all regions on same chart
  79. var all_regions_graph = ui.Chart.image.seriesByRegion({
  80. imageCollection: l8,
  81. regions: collection,
  82. band: 'NDVI',
  83. reducer: ee.Reducer.mean(),
  84. scale: 30,
  85. seriesProperty: 'label'
  86. })
  87. .setChartType('ScatterChart')
  88. .setOptions({
  89. title: 'Kulkurna A & B',
  90. hAxis: {title: 'Time'},
  91. vAxis: {title: 'NDVI'},
  92. lineWidth: 2,
  93. pointSize: 3,
  94. });
  95. //Print graph to User Interface, .set(x, name of graph) where: x = UI vertical position
  96. panel.widgets().set(2, all_regions_graph);
  97.  
  98. //Graph individual region on its own chart
  99. var kulkurna_A_graph = ui.Chart.image.seriesByRegion({
  100. imageCollection: l8,
  101. regions: kulkurna_A,
  102. band: 'NDVI',
  103. reducer: ee.Reducer.mean(),
  104. scale: 30,
  105. seriesProperty: 'kulkurna_A',
  106. })
  107. .setChartType('ScatterChart')
  108. .setOptions({
  109. title: 'Kulkurna A',
  110. hAxis: {title: 'Time'},
  111. vAxis: {title: 'NDVI'},
  112. lineWidth: 2,
  113. pointSize: 3,
  114. series: {0: {color: 'blue'}},
  115. });
  116. //Print graph to User Interface, .set(x, name of graph) where: x = UI vertical position
  117. panel.widgets().set(3, kulkurna_A_graph);
  118.  
  119. //Graph individual region on its own chart
  120. var kulkurna_B_graph = ui.Chart.image.seriesByRegion({
  121. imageCollection: l8,
  122. regions: kulkurna_B,
  123. band: 'NDVI',
  124. reducer: ee.Reducer.mean(),
  125. scale: 30,
  126. seriesProperty: 'Kulkurna B'
  127. })
  128. .setChartType('ScatterChart')
  129. .setOptions({
  130. title: 'Kulkurna B',
  131. hAxis: {title: 'Time'},
  132. vAxis: {title: 'NDVI'},
  133. lineWidth: 2,
  134. pointSize: 3,
  135. series: {0: {color: 'red'}},
  136. });
  137. //Print graph to User Interface, .set(x, name of graph to show) where: x = UI vertical position
  138. panel.widgets().set(4, kulkurna_B_graph);
  139.  
  140.  
  141. // Add the panel to the ui.root.
  142. ui.root.add(panel);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement