2

The code below gives me forest regions of India from the Hansen data set and then I have filtered the landsat images of these regions from 2013-2019 on a quarterly basis. My output image is such that each pixel has its value as the number of pixels with NDVI less than 0.25 at that particular pixel location over these years.

Let's suppose, in the output image, one of the pixel has a value = 6, that is, at that particular pixel location, there are 6 pixels over these years which had NDVI < 0.25. I have to find out whether these 6 pixels occurred consecutively or not. That is, I want to know whether NDVI was constantly low in the consecutive quarters and years. If that is the case, then I can conclude that region is under threat. I also want to know the time period when the NDVI was consistently low. Is there a way I can do this?

// FILTERING OUT FOREST COVER IN INDIA

var treeCanopyCover = hansen.clip(india).select('treecover2000');
var greater25 = treeCanopyCover.gte(25);

// NDVI FUNCTION

function addNDVI(image) {
    var ndvi = image.normalizedDifference(['B5', 'B4']).rename('NDVI');
    return image.addBands(ndvi);
    }

// FILTERING THE COLLECTION

var startDate = ee.Date('2013-01-01');
var endDate = ee.Date('2019-06-30');

var filtered = l8.filterBounds(indiaforest2)
              .filterDate(startDate, endDate)
              .filterMetadata('CLOUD_COVER','less_than',25)
              .map(addNDVI);  

//print(filtered);

var maskedCollection = filtered.map(function(image){
  var x = image.updateMask(greater25);   // filtering over forest regions
  return x;
});


// filtering quarterly wise

var map_m = function(y)
{
  var months = [1, 5, 9];
  var filtered_col = months.map(function(m) 
  {
    var start = ee.Date.fromYMD(y, m, 1)
    var end = start.advance(3, 'month');
    var filt = maskedCollection.filterDate(start,end).mean();

    return filt.set('year', y)
              .set('month', m)
              .set('system:time_start',ee.Date.fromYMD(y,m,1)) ;
  });

  return filtered_col;
};

var years = ee.List.sequence(2013, 2019);
var quarterlyimages = years.map(map_m).flatten();
print(quarterlyimages);

var z = ee.ImageCollection(quarterlyimages);


// discarding null images

var nullimages = z.map(function(image) 
{
      return image.set('count', image.bandNames().length());
})
    .filter(ee.Filter.eq('count', 13));


// counting no. of pixels with NDVI < 0.25

var NDVI_count = nullimages.select('NDVI')
  .map(function(img) { return img.updateMask(img.select('NDVI').lt(0.25)) })
  .count();


print(NDVI_count);

var ndviViz = {min: 1, max: 20, palette: ['green', 'yellow', 'orange', 'red','violet','indigo', 'blue']};

Map.addLayer(NDVI_count, ndviViz);

Your Answer

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

Browse other questions tagged or ask your own question.