How do you write the MSAVI formula in JavaScript function for Google Earth Engine?
I am trying to calculate the MSAVI as a function. The aim is to map the result over a Sentinel-2 composite and not a single image.
I tried the same thing for the OSAVI Index and it worked fine: OSAVI = (NIR-Red)/ (NIR+Red+0.16)
function addOSAVI(input) {
var nir = input.select(['B8']);
var red = input.select(['B4']);
var osavi = nir.subtract(red).divide(nir.add(red).add(0.16)).rename('OSAVI');
return input.addBands(osavi);
}
I need a function in the same manner as the OSAVI function, but I have problem with implementing sqrt() and pow() correctly.
function addMSAVI(input) {
var nir = input.select(['B8']);
var red = input.select(['B4']);
var msavi = (nir.add(1).multiply(2).subtract(sqrt(pow(nir.add(1).multiply(2),2)).subtract((nir.subtract(red)).multiply(2)))).divide(2).rename('MSAVI');
return input.addBands(msavi);
}
More information about MSAVI: http://wiki.landscapetoolbox.org/doku.php/remote_sensing_methods:modified_soil-adjusted_vegetation_index
image.expression()
with TOA or BOA reflectance valuesimage.expression()
as far as I know and I tried it.var msavi = s2_composite.expression('(2*NIR+1-sqrt(pow((2*NIR+1),2) - 8*(NIR-RED))/2)', {'NIR': input.select('B8'), 'RED': input.select('B4')});
is not working