I made a script that calculates the maximum NDVI values of the last 100 days of an area. Therefore, depending on WHEN you run it, the resulting image. Is there any straight straightforward method to achieve this? I tried a image reducer and then parse it to the visualization parameters, but can't make it work.

Best would be to get real-time "Stretch by XXX standard deviations", or "min-max". How do I enter these values to the visualization parameters?

var newDate = new Date();
var dateto = ee.Date(newDate);
var datefrom = dateto.advance(-120, 'day');

var geometry = ee.FeatureCollection('TIGER/2018/States').filterMetadata('NAME','equals','Nebraska');
var collectionNDVI = ee.ImageCollection('MODIS/006/MOD13Q1')
                .filterDate(datefrom ,dateto)
var aoi= geometry.geometry().bounds()
var NDVI = collectionNDVI.select(['NDVI']).max().clip(aoi)

var STD= NDVI.reduceRegion({
  reducer: ee.Reducer.stdDev(),
  geometry: NDVI.geometry(),
  scale: 250,
  maxPixels: 1e9
var nbrParams = {min: 1, max: 5000 , palette: ['red', 'yellow', 'green']};
Map.addLayer(NDVI,nbrParams, "maxNDVI COMBINED")


1 Answer 1


The visualization parameters need to be client-side, while the results from reduceRegion() are server-side. You can turn a server-side to client-side by calling evaluate(), passing a callback function. Sure, you can call getInfo() too, which is a bit simpler, but that blocks your interface.

    reducer: ee.Reducer.stdDev().combine(ee.Reducer.minMax(), '', true),
    geometry: geometry.geometry(),
    scale: 250,
    maxPixels: 1e9
  .evaluate(function (stats) {
    var stdDev = stats.NDVI_stdDev
    var min = stats.NDVI_min
    var max = stats.NDVI_max
    var visParams = {
      min: min,
      max: max,
      palette: ['red', 'yellow', 'green']
    Map.addLayer(ndvi, visParams, "maxndvi COMBINED")


  • It helps, but I still can't select XXX standard deviations Commented Apr 23, 2020 at 20:05
  • How would you want that stretch to work exactly? Commented Apr 23, 2020 at 20:22
  • did it! Replace ee.Reducer.minMax() for mean() and then replaced: var min = stats.EVI_mean - stats.EVI_stdDev *2 var max = stats.EVI_mean + stats.EVI_stdDev *2 Commented Apr 23, 2020 at 20:22

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.