It does not have to be these two scripts specifically, but if anyone has any suggestions on how to effectively combine these two i’d appreciate it. Thank you!
It depends how you want to return the data, but to get a Geotiff with two bands, where the first band is NDVI and the second band is a binary cloud mask (Cloud = 1, No cloud = 0), you could use the following script:
If you want to return a visualisation of the bands and not the values (for a jpeg or png), you could convert to UINT8 for example and use the following script (note that this way you are visualising NDVI values between 0 and 1):
//VERSION=3
function setup() {
return {
input: ["B04", "B08", "CLM"],
output: { bands: 2, sampleType: "UINT8" }
}
}
function evaluatePixel(sample) {
var ndvi = (sample.B08 - sample.B04) / (sample.B08 + sample.B04)
// We reverse the value of the cloud band to mask clouds from the resulting image
return [ndvi * 255, 255 - sample.CLM * 255]
}