1

I am trying to calculate the vegetation condition index (VCI) over a period of years in the google earth engine platform. I have taken the image collection of MODIS 1km NDVI data (MOD13A2) from 2000 to 2020. It is the 16 days NDVI composite giving 23 images per year. I want to calculate the VCI for each image ranging between 2000 to 2020 (about 478 images in my case).

Now, to calculate the VCI, I need min and max NDVI values for each image, as the formula of VCI is as follows:

VCI = ((NDVI-NDVImin)/(NDVImax-MDVImin))*100

I have taken the MOD13A2 collection and created a stack of the available 478 images.

Now,, I don't have any idea to create a loop (as I am very new to this Earth Engine concept and I'm still learning), which would identify the min and max values for each of the 478 bands in the stack and eventually calculate the VCI for those 478 bands.

I tried to go through the loops in different codes available, but couldn't understand much. So, I'm looking for guidance to write the code to create the loop.

I'm providing the code up to which I could write, i.e., the NDVI stacking part.

    var dataset = ee.ImageCollection('MODIS/006/MOD13A2')
                  .filter(ee.Filter.date('2000-01-01', '2020-12-01'))
                  .select('NDVI')
                  .map(function(image){return image.clip(studyarea)});

var NDVI_stack = dataset.toBands();
print(dataset, 'dataset');

print(NDVI_stack, 'NDVI_stack');
Map.addLayer(NDVI_stack, {}, 'NDVI_stack');

The final output I want is the NDVI stack with 478 bands, which I already got, as well as the VCI stack with the corresponding 478 bands.

1 Answer 1

2

I think this is what you are after:

var getvci = function(image){
  // ((NDVI-NDVImin)/(NDVImax-MDVImin))*100
  var vci = image.subtract(minImage).divide(maxImage.subtract(minImage)).rename('vci')
  
  // return image.addBands(vci) // both output togther
  return vci // only the vci
}

https://code.earthengine.google.com/8b0740c42cf9d547556d1e374dd88e57

4
  • Not exactly! Or I perhaps couldn't interpret the code properly. The link provided above is giving me one image for the max NDVI and one image for the min NDVI. But, the max and min values are required for each of the 478 images available, i.e., 478 max images and 478 min images, as the range would change over time. Also, after I add the layer of VCI to the map, it is giving me only one image. But, I require those 478 VCI bands. Sep 8, 2021 at 11:52
  • Ok, so I got 478 bands of VCI by converting the line 27 (var vci) to bands. But I still think that, it is using the same max ndvi and min ndvi value to calculate the vci for all those bands. Sep 8, 2021 at 12:02
  • The GET VCI function is giving you 1 image as output because I limit the printing in line 28, but all observations are there. And I assumed the VCI index requires the min and max for each pixel through time as explained here: gis.stackexchange.com/questions/174933/…. So if you are truly after VCI I think the method above is correct as I calculate for each pixel the min and max for the entire observation period and use that to calculate the VCI for each individual image
    – Jobbo90
    Sep 9, 2021 at 7:31
  • Ok, thank you very much. Sep 9, 2021 at 8:30

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.