I am working with a simple piece of code for obtaining EVI index from two Landsat8 images and then calculating the difference between both.
var img_t0 = ee.Image('LANDSAT/LC8_L1T_TOA_FMASK/LC82330892017001LGN00');
var img_t1 = ee.Image('LANDSAT/LC8_L1T_TOA_FMASK/LC82330892017081LGN00');
function EVI(image) {
var step1 = image.expression(
'2.5 * ((NIR - RED) / (NIR + 6 * RED - 7.5 * BLUE + 1))', {
'NIR': image.select('B5'),
'RED': image.select('B4'),
'BLUE': image.select('B2')
});
var step2 = step1.updateMask(image.select(['fmask']).eq(0)); // mask everything different than 'clear'
return step2
}
var n0 = EVI(img_t0);
var n1 = EVI(img_t1);
var diff = n0.subtract(n1);
// Mean and standard deviation reducers.
var meanReducer = ee.Reducer.mean();
var sigmaReducer = ee.Reducer.stdDev();
// Use the reducer to get the mean and SD of the image.
var mean = ee.Number(diff.reduceRegion({
reducer: meanReducer,
bestEffort: true,
}).get('constant'));
var sigma = ee.Number(diff.reduceRegion({
reducer: sigmaReducer,
bestEffort: true,
}).get('constant'));
print(mean, sigma, mean+2*sigma)
From the resulting image, I need to get the mean and standard deviation for further calculations. Despite the fact that I can print the parameters (as numbers), I can not retrieve their values as such type. When I use them in an arithmetic operation, I am getting NaN as result.
I understand that the reducer property gives you a dictionary as a result, but I have tried several methods (link casting the variables with ee.Number or using brackets [ ] for getting the key value without success).
So the question is ¿How can I retrieve those values like numbers or additional variables for using them later?