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.
Answer
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:
meanStdDev.evaluate(function(val){
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
No comments:
Post a Comment