0

I am using a 'toolbox' on Github to calculate the Land Surface Temperature from Landsat 8 scenes using Google Earth Engine.

One section of this code (below) can use either Band 10, or Bands 10 + 11 to calculate a variable.

The code comments state (boolean) two_channel - if false, will process only the B10 band, if true, will consider B11 too. Default its true!

Consequently, to process using a single channel (B10) I'd expect to use var brightness_temp_img = geet.brightness_temp_l8c(toa_image, false).

The key line in the code is var two_channel = (arguments[1] !== void 1 ? false : true) but I'm not sure I understand how this evaluates.

false seems to invoke processing for Channels B10 and B11, though from the code comment I expect it to invoke single-channel processing. The if...else phrase (true) seems to invoke single channel processing.

Where am I getting confused? The code comments and the code seem to be at odds with each other.

var brightness_temp_l8c = function (image, two_channel) {
  // Error Handling
  if (image === undefined) error('brightness_temp_l8c', 'You need to specify an input image.');
  if (two_channel === undefined) error('brightness_temp_l8c', 'You need to specify an boolean value to process only B10 or B10 and B11.');

  var two_channel = (arguments[1] !== void 1 ? false : true);
  // false - double band (B10 and B11) processing
  if (two_channel === false) {
      var K1_10 = ee.Number(image.get('K1_CONSTANT_BAND_10'));
      var K2_10 = ee.Number(image.get('K2_CONSTANT_BAND_10'));
      var K1_11 = ee.Number(image.get('K1_CONSTANT_BAND_11'));
      var K2_11 = ee.Number(image.get('K2_CONSTANT_BAND_11'));

      var brightness_temp_semlog = image.expression(
          'K1 / B10 + 1', {
          'K1': K1_10,
          'B10': image.select('TOA_Radiance')
      });
 
      var brightness_temp_log = brightness_temp_semlog.log();

      var brightness_temp = image.expression(
          'K2 / brightness_temp_log', {
          'K2': K2_10,
          'brightness_temp_log': brightness_temp_log
      }).rename('Brightness_Temperature');

      var brightness_temp_celsius = brightness_temp.subtract(273.5);
      var img_brightness_temp = image.addBands(brightness_temp_celsius);
      return img_brightness_temp;
  } else {
      // default is true - single band (B10) processing
      var K1_10 = ee.Number(image.get('K1_CONSTANT_BAND_10'));
      var K2_10 = ee.Number(image.get('K2_CONSTANT_BAND_10'));

      var brightness_temp_semlog = image.expression(
          'K1 / B10 + 1', {
          'K1': K1_10,
          'B10': image.select('TOA_Radiance')
      });

      var brightness_temp_log = brightness_temp_semlog.log();

      var brightness_temp = image.expression(
          'K2 / brightness_temp_log', {
          'K2': K2_10,
          'brightness_temp_log': brightness_temp_log
      }).rename('Brightness_Temperature');

      var brightness_temp_celsius = brightness_temp.subtract(273.5);
      var img_brightness_temp = image.addBands(brightness_temp_celsius);
      return img_brightness_temp;
  }
}
strangecharm
  • 186
  • 11

0 Answers0