I am trying to calculate MNDWI index for Sentinel 2 image of an area for 2015 year data in Google Earth Engine.
var image2 = ee.ImageCollection('COPERNICUS/S2')
.filterDate('2015-06-23', '2015-12-31')
// Pre-filtering to get less cloudy granules.
.filter(ee.Filter.lt('CLOUDY_PIXEL_PERCENTAGE', 20))
.filterBounds(point)
.select(['B3', 'B11'])
.reduce(ee.Reducer.percentile([20]))
.rename(['B3', 'B11'])
var mndwi2 = image2.expression('(green - swir) / (green + swir)' ,{
'green':image2.select('B3'),
'swir':image2.select('B11'),
}).rename('MNDWI2');
//adding the layer
Map.addLayer(mndwi2.clip(roi), imageVisParam, 'MNDWI_2015');
//making water zones from 2020 mndwi image
var zones_2015 = mndwi2.gt(0.1).unmask(0);
Map.addLayer(zones_2015.clip(roi), VIS_WATER_MASK, 'water zones for 2015');
It is giving error :
MNDWI_2015: Layer error: Image.select: Pattern 'B11' did not match any bands. water zones for 2015: Layer error: Image.select: Pattern 'B3' did not match any bands.
But as I am changing my year from 2015 to any other year it is working fine. Is there some issue with particular 2015 data or something wrong in the code? Some days back I apply the entire procedure for the same 2015 year for other area and everything works well but this time it is giving error for trying for other area.
Script link: https://code.earthengine.google.com/47dd2ed2fc7ca17b90c769e1c91ac971