Calculating the vegetation condition indices over a stacked vegetation indices in Google Earth Engine

google-earth-enginevci

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.

Best Answer

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