I'm working on calculating the Enhanced Vegetation Index (EVI) of a Sentinel-2 image in Google Earth Engine. My code is:
//evi visual parameters
var evivisparam = {bands: ['B4', 'B8', 'B2'], min: -11000, max: 11000};
//evi calculation of img161
var evi = img161.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': img161.select('B8'),
'RED': img161.select('B4'),
'BLUE': img161.select('B2')
});
Map.addLayer(evi, evivisparam, 'EVI img161');
When I run this, the console prints the error:
EVI img161: Layer error: Image.visualize: No band named 'B4'. Available band names: [constant].
I know that these bands do exist from using
var bandnamesimg161 = img161.bandNames();
print(bandnamesimg161);
which listed the 16 Sentinel-2 bands, including the 3 mentioned. Why does Google Earth Engine not recognize the bands, and how do I make it print the image 'evi'?