2

I would like to calculate the SD of a NDVI value by pixel over a time series using Sentinel 2. It is to identify pixels with more or less variations over a specific time period. The expected output would be a collection of images where pixels values are SD,mean, Min MAX, etc.

What I've done so far is :

//Import GEE Feature Collection
    var ROI = ee.FeatureCollection('https://code.earthengine.google.com/?asset=users/floriangirond/multiplearea');

// Create image collection of S-2 imagery for the perdiod 2018-2019
var S2 = ee.ImageCollection('COPERNICUS/S2')

//filter start and end date
.filterDate('2018-01-01', '2018-12-31')

//filter according to drawn boundary
.filterBounds(ROI);

// Function to mask cloud from built-in quality band
// information on cloud
var maskcloud1 = function(image) {
var QA60 = image.select(['QA60']);
return image.updateMask(QA60.lt(1));
};

// Function to calculate and add an NDVI band
var addNDVI = function(image) {
return image.addBands(image.normalizedDifference(['B8', 'B4']));
};

// Add NDVI band to image collection
var S2 = S2.map(addNDVI);
// Extract NDVI band and create NDVI median composite image
var NDVI = S2.select(['nd']);
var NDVI = ee.FeatureCollection(NDVI.map(mapfunc));
var reducer1 = ee.Reducer.mean();

var reducers = reducer1.combine({reducer2: ee.Reducer.median(), sharedInputs: true})
                       .combine({reducer2: ee.Reducer.max(), sharedInputs: true})
                       .combine({reducer2: ee.Reducer.min(), sharedInputs: true})
                       .combine({reducer2: ee.Reducer.stdDev(), sharedInputs: true});

var results = NDVI.reduceRegion({reducer: reducers,
                                geometry: ROI,
                                bestEffort: true});

print(results);

1 Answer 1

1

You will need to map over your NDVI collection and call reduceRegion() on each image.

var results = NDVI
  .map(function (image) {
    var stats = image.reduceRegion({
      reducer: reducers,
      geometry: ROI,
      bestEffort: true
    })
    return ee.Feature(image.geometry(), stats)
  })

https://code.earthengine.google.com/86116fd7ee66845120e383d1197c5db5

UPDATE

I misunderstood - you wanted the SD per pixel. Then you just reduce() your image collection.

var results = NDVI.reduce(reducers)

https://code.earthengine.google.com/9395901a6f6ba8d5594131a1a5407e98

2
  • Hi, This calculate the SD deviation over my ROI, but the expected output would have been to calculate for each single pixel within my ROI the SD. I guess the output would be an image where the pixel value is the number of standard deviation for each pixel calculated over my time period. Commented Dec 12, 2019 at 3:28
  • Thank you, it works perfectly. Commented Dec 13, 2019 at 1:52

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.