I've been trying to generate time-series indexes charts and print it on the panel, but the SAVI index chart ends up looking just the same as the NDVI chart, besides, the range is wrong (0 - 1.5).
Here is the link: https://code.earthengine.google.com/2199b03f692cdd7fba825910b1c667f2#
Here is the code:
var geometry =
/* color: #d63000 */
/* displayProperties: [
{
"type": "rectangle"
}
] */
ee.Geometry.Polygon(
[[[-44.695355502403196, -20.688760721370848],
[-44.695355502403196, -22.689497956455646],
[-41.904828158653196, -22.689497956455646],
[-41.904828158653196, -20.688760721370848]]], null, false);
var l8 = ee.ImageCollection ('LANDSAT/LC08/C01/T1_SR')
.filterDate('2017-06-01','2018-08-31').filterBounds(geometry)
.map(function(image){return image.clip(geometry)});
//Importando coleção EVI:
var dataset = ee.ImageCollection('LANDSAT/LC08/C01/T1_8DAY_EVI')
.filterDate('2017-06-01','2018-08-31')
.map(function(image){return image.clip(geometry)});
var evi = dataset.select('EVI');
var visParams = {
bands: ['B5', 'B6', 'B4'],
min: 0,
max: 5000,
gamma: 0.7,
};
/*
var l8_mosaic = ee.ImageCollection ('LANDSAT/LC08/C01/T1_SR')
.filterDate('2017-06-01','2018-08-31').filterBounds(geometry1);
var l8_median_cloud = l8_mosaic.map(addQualityBands).map(maskL8sr);
var rgb = l8_median_cloud.select(['B6', 'B5', 'B4']).median().clip(geometry);
*/
//Vgetation indexes:
//SAVI time-series:
var savi = l8.map(function(image) {
return image.select().addBands(image.expression(
'(1 + L) * ((NIR - RED) / (NIR + RED + L))', {
'NIR': image.select('B5'),
'RED': image.select('B4'),
'L': 0.5
}).float()).rename('SAVI')});
//NDVI time-series:
var ndvi = l8.map(function(image) {
return image.select().addBands(image.normalizedDifference(["B5", "B4"]))
.rename('NDVI').float();
});
//Params for visualization:
var colorizedVis = {
min: 0.0,
max: 1.0,
palette: [
'FFFFFF', 'CE7E45', 'DF923D', 'F1B555', 'FCD163', '99B718', '74A901',
'66A000', '529400', '3E8601', '207401', '056201', '004C00', '023B01',
'012E01', '011D01', '011301'
],
};
Map.setCenter(-45.92506211512293,-23.20796402902837, 8);
//Add layers:
//Map.addLayer(rgb,visParams, 'R5G6B4');
Map.addLayer(ndvi.median(), colorizedVis, 'NDVI');
Map.addLayer(evi.median(), colorizedVis, 'EVI');
Map.addLayer(savi.median(), colorizedVis, 'SAVI');
///////Create panel:
var panel = ui.Panel();
panel.style().set('width', '500px');
//labels:
var intro = ui.Panel([
ui.Label({
value: 'Gráficos NDVI, EVI e SAVI Inspector',
style: {fontSize: '20px', fontWeight: 'bold'}
}),
ui.Label('Click a point on the map to inspect.')
]);
panel.add(intro);
// Create panels to hold lon/lat values.
var lon = ui.Label();
var lat = ui.Label();
panel.add(ui.Panel([lon, lat], ui.Panel.Layout.flow('horizontal')));
// Register a callback on the default map to be invoked when the map is clicked.
Map.onClick(function(coords) {
// Update the lon/lat panel with values from the click event.
lon.setValue('lon: ' + coords.lon.toFixed(2)),
lat.setValue('lat: ' + coords.lat.toFixed(2));
//Add a red dot for the point clicked on.
var point = ee.Geometry.Point(coords.lon, coords.lat);
var dot = ui.Map.Layer(point, {color: 'FF0000'});
Map.layers().set(1, dot);
//NDVI chart:
var ndviChart = ui.Chart.image.series(ndvi, point, ee.Reducer.mean(), 30);
ndviChart.setOptions({
title: 'NDVI Over Time',
vAxis: {title: 'NDVI'},
hAxis: {title: 'date', format: 'yy-MM', gridlines: {count: 14}},
});
//EVI chart:
var eviChart = ui.Chart.image.series(evi, point, ee.Reducer.mean(), 30);
eviChart.setChartType('LineChart').setOptions({
title: 'EVI Over Time',
vAxis: {title: 'EVI'},
hAxis: {title: 'date', format: 'yy-MM', gridlines: {count: 14}},
});
// SAVI chart:
var saviChart = ui.Chart.image.series(savi, point, ee.Reducer.mean(), 500);
saviChart.setOptions({
title: 'SAVI Over Time',
vAxis: {title: 'SAVI'},
hAxis: {title: 'date', format: 'yy-MM', gridlines: {count: 14}},
});
//widgets position:
panel.widgets().set(2, ndviChart);
panel.widgets().set(3, eviChart);
panel.widgets().set(1, saviChart);
});
//cursor:
Map.style().set('cursor', 'crosshair');
//Inserting panel on position 0 on ui.root.
ui.root.insert(0, panel);