0

I used the below code I got from a similar question for obtaining the time series of LST using Landsat 7 dataset. I am getting error as:

Image (Error) reduce.median: Error in map(ID=LE07_134040_20190110): Image.select: Pattern 'pixel_qa' did not match any bands.

The following is the code:

 var col = ee.ImageCollection("LANDSAT/LE07/C02/T2_L2")
.map(maskL8sr)
.filterDate('2019-01-01','2019-02-28')
.filterBounds(geometry);
print(col, 'collection');


//cloud mask
function maskL8sr(col) {
  // Bits 3 and 5 are cloud shadow and cloud, respectively.
  var cloudShadowBitMask = (1 << 3);
  var cloudsBitMask = (1 << 5);
  // Get the pixel QA band.
  var qa = col.select('pixel_qa');
  // Both flags should be set to zero, indicating clear conditions.
  var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
                 .and(qa.bitwiseAnd(cloudsBitMask).eq(0));
  return col.updateMask(mask);
}


//vis params
var vizParams = {
bands: ['SR_B3', 'SR_B2', 'SR_B1'],
min: 0,
max: 0.3,
};

var vizParams2 = {
bands: ['SR_B3', 'SR_B2', 'SR_B1'],
min: 0,
max: 0.3,
};

//image reduction
{
var image = col.median();
print(image, 'true color composite');
Map.addLayer(image, vizParams2);
}

var ndvi = image.normalizedDifference(['B5', 
'B4']).rename('NDVI');
var ndviParams = {min: -1, max: 1, palette: ['blue', 'white', 
'green']};
print(ndvi,'ndvi');
Map.addLayer(ndvi, ndviParams, 'ndvi');


//select thermal band 10(with brightness tempereature), no calculation 
var thermal = image.select('B10').multiply(0.1);
var b10Params = {min: 291.918, max: 302.382, palette: ['blue', 
'white', 'green']};
Map.addLayer(thermal, b10Params, 'thermal');

// find the min and max of NDVI
{
var min = ee.Number(ndvi.reduceRegion({
reducer: ee.Reducer.min(),
geometry: geometry,
scale: 5000,
maxPixels: 1e9
}).values().get(0));
print(min, 'min ndvi');
var max = ee.Number(ndvi.reduceRegion({
reducer: ee.Reducer.max(),
geometry: geometry,
scale: 5000,
maxPixels: 1e9
}).values().get(0));
print(max, 'max ndvi')
}

//fractional vegetation
{
var fv =(ndvi.subtract(min).divide(max.subtract(min))).pow(ee.Number(2)).rename('FV'); 
print(fv, 'fractional vegetation');
Map.addLayer(fv);
}

//Emissivity

var a= ee.Number(0.004);
var b= ee.Number(0.986);
var EM=fv.multiply(a).add(b).rename('EMM');
var imageVisParam3 = {min: 0.9865619146722164, max:0.989699971371314};
Map.addLayer(EM, imageVisParam3,'EMM');

//LST in Celsius Degree 
function addLST (img) {
  var LST =  img.expression(
  '(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15', {
  'Tb': img.select('B10').multiply(0.1),
  'Ep': EM.select('EMM')
  }).rename('LST').select('LST');
  return img.addBands(LST)
  }

var withLST = col.map(addLST);
print('withLST', withLST);


 // Create an image time series chart.
var chart = ui.Chart.image.doySeriesByRegion
({imageCollection: withLST, 
bandName: "LST",
regions: geometry,
//regionReducer: geometry, 
scale: 200, 
yearReducer: ee.Reducer.mean(), 
//seriesProperty, 
startDay: 153, 
endDay: 244});

// Add the chart to the map.
chart.style().set({
  position: 'bottom-right',
  width: '500px',
  height: '300px'
});
Map.add(chart);
Map.centerObject(geometry);

Link: https://code.earthengine.google.com/14dabf05f6c98b52f679f18147c71765

1 Answer 1

0

I'm not sure why you are working with Tier 2 data and not Tier 1 (which has the highest radiometric and positional quality). Regardless, you're selecting a band that isn't available in the Landsat 7 collection (B10). If you read the documentation for your product, it states that ST_B6 is the one for surface temperature.

Unfortunately, I also haven't been able to calculate an LST band for Landsat 7 until now. Even with the band correction, my LST outputs do not conform with normal values in celsius. If you're flexible enough to work with Landsat 8, the following code will provide valid results:

    var col_list = masked_col.toList(your_collection.size()); #replace your_collection with your collection's variable

# The following function mapping over each element (ele) in the col_list and creates a new collection (LST_col)
  
    var LST_col = col_list.map(function (ele) {
      
      var date = ee.Image(ele).get('system:time_start');
    
      //NDVI
      var ndvi = ee.Image(ele).normalizedDifference(['SR_B4', 'SR_B5']).rename('NDVI');
      
      //Min and max of NDVI
      {
      var min = ee.Number(ndvi.reduceRegion({
        reducer: ee.Reducer.min(),
        geometry: region,
        scale: 30,
        maxPixels: 1e9
      }).values().get(0));
    
      var max = ee.Number(ndvi.reduceRegion({
        reducer: ee.Reducer.max(),
        geometry: region,
        scale: 30,
        maxPixels: 1e9
      }).values().get(0));
      }
    
      //FRACTIONAL VEGETATION
      var fv =(ndvi.subtract(min).divide(max.subtract(min))).pow(ee.Number(2)).rename('FV'); 
    
      //EMISSIVITY
      var a = ee.Number(0.004);
      var b = ee.Number(0.986);
      var EM = fv.multiply(a).add(b).rename('EMM');
    
      //SELECT THERMAL BAND
      var thermal = ee.Image(ele).select('ST_B10');
    
      //LST CALCULATION
      var LST = thermal.expression(
        '(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15', {
        'Tb': thermal.add(273.15),
        'Ep': EM.select('EMM')
      });
    //  .rename('LST'); //If expression below fails
      return ee.Algorithms.If(min, LST.set('system:time_start', date).float().rename('LST'), 0);
    //  return LST.set('system:time_start', date).float().rename('LST');
    }).removeAll([0]);
    
    
    print("Collection with LST band", LST_col);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.