1

In Google Earth Engine, I am having a trouble with my chart. Gets only one value as photo below. Is there any solution?

enter image description here

My code is as follows:

//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: ['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,
};

//load the collection:
 
var col = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.map(maskL8sr)
    .filterDate('2020-07-01','2020-08-1')
    .filterBounds(geometry)
    .map(function(image){return image.clip(geometry)});

print(col, 'coleccion');

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


//median
{
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: 30,
maxPixels: 1e9
}).values().get(0));
print(min, 'min');
var max = ee.Number(ndvi.reduceRegion({
reducer: ee.Reducer.max(),
geometry: geometry,
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 = col.map(function(image){
  return image.select().addBands(thermal.expression(
'(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15', {
 'Tb': thermal.select('B10'),
'Ep':EM.select('EMM')
}).float()).rename('LST')});

Map.addLayer(LST, {min: 20.569706944223423, max:29.328077233404645, 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');
 
print(
      ui.Chart.image.series({
        imageCollection: LST, 
        region: geometry, 
        reducer: ee.Reducer.mean(), // default 
        scale: 30, // nominal scale Landsat imagery 
        xProperty: 'system:time_start' // default
      }));

1 Answer 1

1

It looks like you are reusing code in a wrong way. You need individual values for ndvi, thermal and fv images and, ndvi minimums and ndvi maximums values for each ndvi image. You get only one value because you are computing each LST value by using the same image (col.median). You need to map your collection by using a function that computes all differences. Following code snippet does the job (complete code here).

//individual LST images

var col_list = col.toList(col.size());

var LST_col = col_list.map(function (ele) {
  
  var date = ee.Image(ele).get('system:time_start');

  var ndvi = ee.Image(ele).normalizedDifference(['B5', 'B4']).rename('NDVI');
  
  // find the min and max of NDVI
  var min = ee.Number(ndvi.reduceRegion({
    reducer: ee.Reducer.min(),
    geometry: geometry,
    scale: 30,
    maxPixels: 1e9
  }).values().get(0));
  
  var max = ee.Number(ndvi.reduceRegion({
    reducer: ee.Reducer.max(),
    geometry: geometry,
    scale: 30,
    maxPixels: 1e9
  }).values().get(0));
  
  var fv = (ndvi.subtract(min).divide(max.subtract(min))).pow(ee.Number(2)).rename('FV');
  
  var a= ee.Number(0.004);
  var b= ee.Number(0.986);
  
  var EM = fv.multiply(a).add(b).rename('EMM');

  var image = ee.Image(ele);

  var LST = image.expression(
    '(Tb/(1 + (0.00115* (Tb / 1.438))*log(Ep)))-273.15', {
      'Tb': image.select('B10').multiply(0.1),
      'Ep': fv.multiply(a).add(b)
  });

  return LST.set('system:time_start', date).float().rename('LST');
  
});

LST_col = ee.ImageCollection(LST_col);

print("LST_col", LST_col);

/////////////////

By using a particular very hot area in Mexico (I also used a different dates range), I got following result after running above code in GEE editor.

enter image description here

If you don't get a result in your area, it can be due to nulls in minimum and maximum values for some ndvi images. It needs to be handle appropriately before getting whatever result.

Editing Note:

I slightly modified my code for printing min and max ndvi values in your roi. It can be observed in the following image that there are several nulls y for this reason you get "ImageCollection (Error) Number.subtract: Parameter 'left' is required" error message. Where nulls are produced, there is not ndvi image (I corroborated that returning ndvi images instead min and max values).

enter image description here

So, for avoiding null values, you need an If statement in return of function as follows:

.
.
.
  return ee.Algorithms.If(min, LST.set('system:time_start', date).float().rename('LST'), 0);

}).removeAll([0]);

Complete code is in this new link.

After running this code in GEE editor, it can be observed in following image, printed desired chart without any error.

enter image description here

8
  • thank you for your great response! Dec 12, 2021 at 18:18
  • when I run my code i get an error "ImageCollection (Error) Number.subtract: Parameter 'left' is required." The code is code.earthengine.google.com/69220b4399113e1cf12bc902783507cb Dec 12, 2021 at 19:25
  • Share your ROI geometry.
    – xunilk
    Dec 12, 2021 at 19:27
  • 1
    I slightly modified my code for printing min and max ndvi values in your roi. It can be observed in the image of my Editing Note. There are several nulls y for this reason you get "ImageCollection (Error) Number.subtract: Parameter 'left' is required" error message. It must be fixed. I will try it later.
    – xunilk
    Dec 12, 2021 at 21:50
  • 1
    Please, see my Edit Note again. I fixed code for avoiding error message printing chart.
    – xunilk
    Dec 13, 2021 at 2:47

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.