I have created a script of sentinel-2 images from 2017 oct to 2018 april with 20% cloud-cover at 15-days time interval. I have one imagecollection every 15 days, i also calculated NDVI and added that as a band for the first 15-days collection.
Now, every collection has a number of images with specific NDVI values. What i want to do is to compare pixel by pixel NDVI values every image within the collection and choose the pixel with highest NDVI value and print down which image among all the images is giving the highest NDVI and choose the reflectance values corresponding to that pixel and that image within that imagecollection, this way create a 15-day maximum reflectance composite derived from the maximum NDVI value-showing image inside an imagecollection. So, my aim is to get maximum reflectances of images within imagecollection for each pixel. I want to do that for every 15-days collection.
I am very much new to coding but i am in my thesis now and stuck at this point. Can anybody tell me how do i do this in GGE? I am mentioning the first 15-days code here-
var tanguarhaor = ee.Geometry.Polygon([
[[90.9952, 25.16], [91.2616,25.1824],[91.4841,25.1053],[91.55, 24.9647], [91.4594, 24.8065], [90.8772, 24.814],[90.781,24.9635],[90.8043,25.1103],[90.9952,25.16]]
]);
Map.centerObject(tanguarhaor);
Map.addLayer(tanguarhaor, {color: 'FF0000'}, 'geodesic polygon');
function maskS2clouds(image) {
var qa = image.select('QA60');
var cloudBitMask = 1 << 10;
var cirrusBitMask = 1 << 11;
var mask = qa.bitwiseAnd(cloudBitMask).eq(0).and(
qa.bitwiseAnd(cirrusBitMask).eq(0));
return image.updateMask(mask).divide(10000)}
var start = ee.Date('2017-10-01');
var finish =ee.Date('2017-10-15');
var TahirpurOCT17first = ee.ImageCollection('COPERNICUS/S2')
.filterBounds(tanguarhaor)
.filterDate(start,finish)
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE',10))
.map(maskS2clouds);
var IMAGE1 = TahirpurOCT17second.map(function(image) { return image.clip(tanguarhaor); });
var addNDVI = function(image){var ndvi=image.normalizedDifference(['B8','B4']).rename('NDVI');return image.addBands(ndvi);};
var ndvi1 = IMAGE1.map(addNDVI);
var ndvi2 = ndvi1.sort('system:time_start', false);
var collection = ndvi2.select(['NDVI']);
print(collection);
I am stuck at the point how do i know from which image the maximum NDVI value is coming from within the imagecollection 'collection' in the script for each pixel and get the reflectance values corresponding to that pixel of that image within that 15-day imagecollection? Is it possible to get the result as a map somehow?