0

I'm trying to calculate Temperature Condition Index with LST for a year of 2020. But for the last step my code was error for function .rename. It was in line 127 for .rename('TCI') and the result is:

Error : (intermediate value).rename is not a function

Here my code:

//cloud mask
function maskL8sr(image) {
  // 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 = image.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 image.updateMask(mask);
}

//vis params
var vizParams = {
bands: ['B5', 'B6', 'B4'],
min: 0,
max: 4000,
gamma: [1, 0.9, 1.1]
};

var vizParams2 = {
bands: ['B4', 'B3', 'B2'],
min: 0,
max: 3000,
gamma: 1.4,
};

//mencari image
var hasil = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
 .filterBounds(lamongan)
 .filterDate('2020-05-01','2020-10-31')
 .filterMetadata('CLOUD_COVER', 'less_than', 5);
Map.addLayer(hasil);
print(hasil);

//median
{
var image = hasil.median();
print(image, 'image');
Map.addLayer(image, vizParams2, 'citra');
}

//median (ndvi) 
{
var ndvi = image.normalizedDifference(['B5', 
'B4']).rename('NDVI');
var ndviParams = {min: 0, max: 1, palette: ['blue', 'white', 
'green']};
print(ndvi,'ndvi');
Map.addLayer(ndvi .clip(lamongan), 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 .clip(lamongan), b10Params, 'thermal');

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

var max = ee.Number(ndvi.reduceRegion({
reducer: ee.Reducer.max(),
geometry: lamongan,
scale: 30,
maxPixels: 1e9
}).values().get(0));
print(max, 'max')
}

//fractional vegetation
{
var fv =(ndvi.subtract(min).divide(max.subtract(min))).pow(ee.Number(2)).rename('FV'); 
print(fv, 'fv');
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 bring -273.15
//NB: In Kelvin don't bring -273.15
var LST = thermal.expression(
'(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15', {
'Tb': thermal.select('B10'),
'Ep': EM.select('EMM')
}).rename('LST');

//min max LST
{
var lstmin = ee.Number(LST.reduceRegion({
reducer: ee.Reducer.min(),
geometry: lamongan,
scale: 30,
maxPixels: 1e9
}).values().get(0));
print(lstmin, 'minLST');

var lstmax = ee.Number(LST.reduceRegion({
reducer: ee.Reducer.max(),
geometry: lamongan,
scale: 30,
maxPixels: 1e9
}).values().get(0));
print(lstmax, 'maxLST');
}


//Temperature Condition Index
{
var tci = (lstmax-(LST)/(lstmax+lstmin)*(100)).rename('TCI'); 
print(tci, 'TCI');
Map.addLayer(tci, {palette: ['ffff00', '24f135', '1e5c1e']}, 'tci');
}


Map.addLayer(LST .clip(lamongan), {min: 19.14196738925108, max:40.032318244117846, palette: [
'040274', '040281', '0502a3', '0502b8', '0502ce', '0502e6',
'0602ff', '235cb1', '307ef3', '269db1', '30c8e2', '32d3ef',
'3be285', '3ff38f', '86e26f', '3ae237', 'b5e22e', 'd6e21f',
'fff705', 'ffd611', 'ffb613', 'ff8b13', 'ff6e08', 'ff500d',
'ff0000', 'de0101', 'c21301', 'a71001', '911003'
]},'LST');

1 Answer 1

0

Arithmetic operations between an image and a constant value should be performed by converting the numeric value into an image where all the pixels have the same numeric value.

Instead of your tci formula, write something like this (I split the operation into several chunks for readability):

var tci_quotient = ee.Image(lstmax).subtract(LST);
var tci_divisor =  ee.Image(lstmax).add(ee.Image(lstmin));
var tci = tci_quotient.divide(tci_divisor).multiply(100).rename('TCI');
print(tci, 'TCI');

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.