I've been just approaching to Google Earth Engine and JavaScript.
I am trying to write a code for chlorophyll-a concentration retrieval from Sentinel-2 images.
I want to obtain the chl-a from the atmospherically corrected images (level 2A) over a specific area of interest.
Since I want to do it for a collection I thought to write a function that work on a single image using image.expression and then pass it through the collection with the ".map" function.
The algorithm though seems to don't perform well,of course it would need a calibration but I am pretty sure that since I don't know how to neither GEE nor JS I am probably making tons of mistakes.
The formula that I want to implement is the following:
Where Rrs is the remote sensing reflectance, which means I have to divide every pixel value by pi. 442 is the band 1, 492 is the band 2 and finally 560 is band 3. This is the code I am trying to write:
function chl_oc2(image) {
var Rrs= image.divide(Math.PI);
var x= Rrs.expression('log10(blue/green)',{'blue':Rrs.select('B3'),'green':Rrs.select('B2')});
var chl_conc=Rrs.expression('10**(0.2389-1.9369*x+1.7627*x**2-3.077*x**3-0.1054*x**4)',{'x':x});
return chl_conc;
After that I would pass it to collection simply adding .map(chl_oc2) to the ee.ImageCollection
This is what I wrote, except for different coefficients showed in above image. But to me there is probably something wrong. Also in the formula you can see that I have to get the max value between band 1 and band 2 and for that I have no idea how to do it, so I just used band 2 instead but would be even better if you could help me to implement a function to choose the greatest value from 2 bands. I noted that band 1 and band 2 have two different resolutions (10m for band 1 and 60m for band 2)
var maxBand = ee.Image(ee.Algorithms.If(band1.gt(band2),band2,band1))
but is preferable to usevar maxBand = band1.max(band2)
because you don't need to worry about bands order.