I am trying to load a map and be able to see the GRI(Green Chlorophyll index) on a certain area. I tried doing it with NDVI, however when I do it for GRI, I get an entirely black area.
I'm not really sure what Im doing wrong especially that I'm new to this.
Any tip would be really appreciated!
var AOI = Boundary_Graf;
var points = Points_Graf;
//Display the exact location of the points
var shp = ee.FeatureCollection(points);
Map.addLayer(shp, {}, 'Graf.Points');
//Display the exact location of the polygon
var shp = ee.FeatureCollection(AOI);
Map.addLayer(shp, {}, 'Polygon_Graf');
//Open S2
var S2 = ee.ImageCollection("COPERNICUS/S2")
//Filter for a specific date (now just chose it randomly)
. filterDate("2022-01-01", "2022-06-22")
//Filter for the polygon area
. filterBounds(AOI)
//Filter data based on metadata property -> cloudy pixel percentage <5%
.filterMetadata('CLOUDY_PIXEL_PERCENTAGE', 'less_than', 5)
// Subsetting the image based on AOI
.map(function(image){return image.clip(AOI)})
// Printing the S2 layer to the console
print ("S2 collection:", S2);
var trueColour = {bands:["B8", "B4", "B3"], max: 3048, gamma:1};
var visParams = {min: 0, max: 0.8, palette: 'FFFFFF, CE7E45, DF923D, F1B555, FCD163, 99B718, 74A901, 66A000, 529400,' +
'3E8601, 207401, 056201, 004C00, 023B01, 012E01, 011D01, 011301'};
// Calculate NDVI
var NDVI_collection = S2.map(function(image){
var NDVI = image.normalizedDifference(['B8','B4']).rename('NDVI');
return NDVI
.copyProperties(image, ['system:time_start']);
});
// Calculate GCI
var CGI_collection = S2.map (function(image){
var CGI = image.expression ('(((NIR) / (GREEN)) - 1)', {
'NIR': image.select ('B8'),
'GREEN': image.select ('B3')
}).rename("GCI");
return CGI;
});
Map.centerObject(AOI);
Map.addLayer(S2, trueColour, 'true-colour image');
Map.addLayer(NDVI_collection, visParams,'Sentinel-2 NDVI');
Map.addLayer(CGI_collection, visParams, 'Sentinel-2 CGI');