I used this script for Landsat 8 and it worked fine, I've changed the band info for Landsat 5 but now I get this error:
ImageCollection (Error)
Error in map(ID=0):
Image.select: Pattern 'B4' did not match any bands.
Where am I going wrong?
// Import landsat imagery. Create function to cloud mask from
// the pixel_qa band of Landsat 5 SR data.
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var imageCollection = ee.ImageCollection('LANDSAT/LT05/C01/T1_SR')
.filterBounds(AOI);
function maskL8sr(imageCollection) {
var cloudShadowBitMask = 1 << 3;
var cloudsBitMask = 1 << 5;
var qa = imageCollection.select('pixel_qa');
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
return imageCollection.updateMask(mask).divide(10000)
.select("B[0-9]*")
.copyProperties(imageCollection, ["system:time_start"]);
}
var stepList = ee.List.sequence(2000,2012);
var filterCollection = stepList.map(function(year){
var startDate = ee.Date.fromYMD(year,3,1);
var endDate = ee.Date.fromYMD(year,5,31);
var composite_i = imageCollection.filterDate(startDate, endDate)
.map(maskL8sr)
.median()
.set('system:time_start',startDate);
return composite_i;
});
print(filterCollection)
var yearlyComposites = ee.ImageCollection(filterCollection);
print(yearlyComposites, 'Masked and Filtered Composites');
// Add Enhanced Vegetation Index to a function and apply it.
// EVI = 2.5 * ((NIR - Red) / (NIR + 6 * Red – 7.5 * Blue + 1))
function evi(img){
var eviImg = img.select(['B4','B3','B1'],['nir','red','blue']);
eviImg = eviImg.expression(
'(2.5 * ((NIR - RED)) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': eviImg.select('nir'),
'RED': eviImg.select('red'),
'BLUE': eviImg.select('blue')
}).rename('EVI');
return img.addBands(eviImg);
}
yearlyComposites = yearlyComposites.map(function(image){
return evi(image);
});
print(yearlyComposites, 'With EVI as Band');