Getting error: Error in map(ID=8): Image.select: Pattern 'B5' did not match any bands in Google Earth Engine

889 Views Asked by At

Trying to modify a code in Google Earth Engine I found in the internet which I need for performing time series analysis. I need Landsat images from 1984-2022, that’s why I merged two Image Collection (L5 and L8). But I am getting an error: ImageCollection (Error) Error in map(ID=28): Image.select: Pattern 'B5' did not match any bands.

var collectionL5 = ee.ImageCollection('LANDSAT/LT05/C02/T1_TOA')
  .filterBounds(studyArea);
  

var collectionL8 = ee.ImageCollection('LANDSAT/LC08/C02/T1_TOA')
  .filterBounds(studyArea);


function maskL8sr(collectionL5) {
  var cloudShadowBitMask = 1 << 3;
  var cloudsBitMask = 1 << 5;

  var qa = collectionL5.select('QA_PIXEL');

  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0));

  return collectionL5.updateMask(mask).divide(10000)
      .select("B[0-9]*")
      .copyProperties(collectionL5, ["system:time_start"]);
}

function maskL8sr(collectionL8) {
  var cloudShadowBitMask = 1 << 3;
  var cloudsBitMask = 1 << 5;

  var qa1 = collectionL8.select('QA_PIXEL');

  var mask = qa1.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa1.bitwiseAnd(cloudsBitMask).eq(0));

  return collectionL8.updateMask(mask).divide(10000)
      .select("B[0-9]*")
      .copyProperties(collectionL8, ["system:time_start"]);
}

var imageCollection = collectionL5.merge(collectionL8).filterBounds(studyArea);



var stepList = ee.List.sequence(1984,2021);

var filterCollection = stepList.map(function(year){
  var startDate = ee.Date.fromYMD(year,5,1);
  var endDate = ee.Date.fromYMD(year,9,15);
  var composite_i = imageCollection.filterDate(startDate, endDate)
                        .map(maskL8sr)
                        .median()
                        .set('system:time_start',startDate);
  return composite_i;
});

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(['B5','B4','B2','B6','B3'],['nir','red','blue','swir1','green']);
  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'),
      'SWIR1': eviImg.select('swir1'),
      'GREEN': eviImg.select('green')
    }).rename('EVI');
  return img.addBands(eviImg);
}

yearlyComposites = yearlyComposites.map(function(image){
  return evi(image);
});

print(yearlyComposites, 'With EVI as Band');

// Create image collection of yearly composites, selecting the EVI band.
var eviCollection = yearlyComposites.select('EVI');

But I am getting error: ImageCollection (Error) Error in map(ID=28): Image.select: Pattern 'B5' did not match any bands.

I know that the problem is in Image 28. While checking the bands I noticed that image 28 is empty.I also noticed that 28 image is a "transitional" image between the L5 and L8 collections. Image28 Can it be possible that somehow while merging two image collections they overlap each other ending up with empty image inside.

1

There are 1 best solutions below

0
On

Try 'SR_B5' instead 'B5'

bands info:

SR_B1 SR_B2 SR_B3 SR_B4 SR_B5 SR_B6 SR_B7 SR_QA_AEROSOL ST_B10 ST_ATRAN ST_CDIST ST_DRAD ST_EMIS ST_EMSD ST_QA ST_TRAD ST_URAD QA_PIXEL QA_RADSAT