What I mean is: I'm using the "3 standard deviations" value to visualize my data, but this changes seasonally so I need to update what the values actually are for each image. Can I create a "3 standard deviations" palette that will automatically calculate these new values for each image?

In pseudocode terms, I'm imagining something along these lines:

var Oa04_palette = {
bands: ['Oa04_radiance'],
min: sminus3,
max: splus3,
sminus3: standard deviation of 'Oa04_radiance' * -3,
splus3: standard deviation of 'Oa04_radiance' * 3

So when I add a bunch of layers all using this palette, it will always use the appropriate min-max range for that layer.

1 Answer 1


As I understand correctly, you want to add layers to the map using min and max values based on mean-stdDev*3 and mean+stdDev*3?

There could be several ways achieving that, but here is a simple example:

First, make a random geometry and image:

  var scale = Map.getScale();
  var geometry = Map.getCenter().buffer(scale*10);
  var randomImage = ee.Image.random().multiply(scale); 

Then, we calculate the mean and stdDev value of that image in the specified region:

  var meanStdDev = randomImage.reduceRegion(
              ee.Reducer.mean().combine(ee.Reducer.stdDev(), null, true), geometry, scale);
  meanStdDev = meanStdDev.rename(meanStdDev.keys(), ['mean','stdDev']);  

We then need to evaluate the outcomes to the client side, as the Map visible parameters require client-side input:

    var mean = val.mean;
    var stdDev = val.stdDev;
  var visParam = {
          min: mean - (stdDev * 3),
          max: mean + (stdDev * 3),

Then we add the layer to the map using the visParams defined:

Map.addLayer(randomImage, visParam); 

As an example, here is a simple app that changes the visible parameters as you zoom in/out: Link code

  • Is there any way to not make this scale-dependent? I'm looking at areas that are covered by single images. Here's an example of the code I'm using, which I probably should have included from the start: code.earthengine.google.com/690e09f3a37f7d0afbc7546f53b65ac1 It seems like in the code you gave I'd need to include all of that for each individual layer to generate the parameters, is that the only way to go about it?
    – Matt
    Commented Jun 20, 2019 at 14:13
  • Here's the code implemented for one of the layers: code.earthengine.google.com/202c2688ee841b49fccdecaa7ed4837c I wasn't sure how to modify the code to only include one band, so I worked that in with .select(). It seems like the output doesn't match the Stretch: 3 σ option.
    – Matt
    Commented Jun 20, 2019 at 14:34
  • Yes, t is always easier if you post your code. You asked a general question, then you get a general answer. Off course the scale is not the variable you want to stretch an image, but that was just to give you an idea. Here is a link to a code which adjust the stretch to an image selected. Again, I do not know what your final goal is, but this should turn you in the right direction I guess
    – Kuik
    Commented Jun 21, 2019 at 8:08

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.