0

My code for computing EVI index in google earth engine show EVI amounts for some dates very high or very low. I don't know what to do with this issue:

//landsat8 EVI_2013_2020
var landsat8forEVIKoohin = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
.filterDate("2013-04-11","2020-01-01").filterBounds(Ghazvin)
.filter(ee.Filter.eq('WRS_PATH',166))
.filter(ee.Filter.eq('WRS_ROW', 35))
.map(function(img){
  var rescale = img.divide(10000.0);
  
  var EVI = rescale.expression("2.5*((NIR-RED)/(NIR+6*RED-7.6*BLUE+1))"
  ,{
    "BLUE":rescale.select('B2'),
    "RED":rescale.select('B4'),
    "NIR":rescale.select('B5'),
  });
  return EVI.rename("EVI").clip(koohin).copyProperties(img,["system:time_start","system:time_end"]);
  });
  
print("landsat8forEVIKoohin:",landsat8forEVIKoohin);
Map.addLayer(landsat8forEVIKoohin,{},"landsat8forEVIKoohin");

var EVIChart = ui.Chart.image.series(
  landsat8forEVIKoohin,koohin_deim,ee.Reducer.mean(),30,"system:time_start"
  ).setChartType("LineChart")
  .setOptions({
    title:"EVI ",
    vAixs:{title:"EVI"},
    hAxis:{title:"date"},
    lineWeigth:1,
    series:{0:
    {color:"black"}
  }});
  
print(EVIChart); 
//________________________

EVI index trend for 10 years in Ghazvin_IRAN

1
  • Please share a full script that can be reproduced. Currently, Ghazvin, koohin, and koohin_deim are not defined for us. – JepsonNomad Jun 1 at 17:41
0

Your code isn't working because we can not see the geometries (shapefiles). So it is difficult to say why the problem happened. However, I tried to assume your study site based on the image.

Problem and solution:

  1. Too much clouds can cause the EVI values to become unexpected, one solution is to remove clouds.
  2. Even if removing clouds doesn't solve and it happened to be because of one or two image in the series, you can remove them.

I guessed and found that it is giving reasonable values, here is the code:

//landsat8 EVI_2013_2020
var l8 = ee.ImageCollection("LANDSAT/LC08/C01/T1_SR")
.filterDate("2013-04-11","2020-01-01")
//.filterBounds(Ghazvin)
.filter(ee.Filter.eq('WRS_PATH',166))
.filter(ee.Filter.eq('WRS_ROW', 35))

//Make out clouds, becasue clouds will affect EVI values
// Check this: https://gis.stackexchange.com/questions/271322/cloud-mask-in-surface-reflectance-landsat-8-test

// Scripts from 
.map(function(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 mask1 = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
      .and(qa.bitwiseAnd(cloudsBitMask).eq(0));

  var mask2 = image.select('B.*').gt(0).reduce('min');

  // Return the masked image, without the QA bands.
  return image.updateMask(mask1.and(mask2))
      .select("B[0-9]*")
      .copyProperties(image, ["system:time_start"]);
});

print(l8.first());


Map.addLayer(ee.Image(l8.first().divide(10000.0)),{min: 0, max:0.4, bands: ['B4','B3','B2']},'First image');

// Map a function to rescale the band values and calculate EVI
var landsat8forEVIKoohin = l8.map(function(img){
  var rescale = img.divide(10000.0);
  
  var EVI = rescale.expression(
    '2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
      'NIR': rescale.select('B5'),
      'RED': rescale.select('B4'),
      'BLUE': rescale.select('B2')
});

  return EVI.rename("EVI")
  //.clip(koohin)
  .copyProperties(img,["system:time_start","system:time_end"]);
});

print("landsat8forEVIKoohin:",landsat8forEVIKoohin);

// Add to the map to check
Map.centerObject(landsat8forEVIKoohin.first(),9); 
// Notice a lot of clouds were removed
Map.addLayer(landsat8forEVIKoohin.first(),{},"landsat8forEVIKoohin");

var EVIChart = ui.Chart.image.series(
  landsat8forEVIKoohin,koohin_deim,ee.Reducer.mean(),30,"system:time_start"
  ).setChartType("LineChart")
  .setOptions({
    title:"EVI ",
    vAixs:{title:"EVI"},
    hAxis:{title:"date"},
    lineWeigth:1,
    series:{0:
    {color:"black"}
  }});
  
print('Before filtering EVI Chart: ',EVIChart); 


// Filter out the image which causing EVI to be spurious
// See Tyler's suggestion here https://gis.stackexchange.com/questions/263694/remove-one-image-from-imagecollection-in-google-earth-engine
var filtered = landsat8forEVIKoohin.filter(
  ee.Filter.date('2014-02-04', '2014-02-10').not()
);


print('number of images before filtered', landsat8forEVIKoohin.size());
print('number of images after filtered', filtered.size());


var EVIChart2 = ui.Chart.image.series(
  filtered,koohin_deim,ee.Reducer.mean(),30,"system:time_start"
  ).setChartType("LineChart")
  .setOptions({
    title:"EVI ",
    vAixs:{title:"EVI"},
    hAxis:{title:"date"},
    lineWeigth:1,
    series:{0:
    {color:"black"}
  }});
  
print('After filtered EVI chart: ',EVIChart2); 

Link: https://code.earthengine.google.com/88eacdc76080482001bd0a94f915a38a

1
  • Please share your full working script next time. – mandal Jun 3 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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