Masking Cloud, Snow, Water for NDVI images

Hello Community

I am trying to obtain the NDVI within a polygon within a Timespan of 6 years over a small area.

And I would like to mask the snow, clouds and water. I was thinking of doing this, however I am not sure if this is efficient.

function evaluatePixel(samples) {
    let ndvi = (samples.B08 - samples.B04)/(samples.B08 + samples.B04)
    
    var validNDVIMask = 1
    if (samples.B04 + samples.B08 == 0 ){ //check if all the bands are 0
        validNDVIMask = 0
    }
    
    var noWaterMask = 1
    if (samples.SCL == 6 ){ //check if pixels are classified as water using SCL band
        noWaterMask = 0
    }
    var noSnow = 1
    if(samples.SCL == 11)
       noSnowMask = 0
   
    var no Clouds = 1
    if(samples.CLM = 1)
      noCloudsMask = 0

    return {
        ndvi: [ndvi],
        dataMask: [samples.dataMask * validNDVIMask * noWaterMask* 
noSnowMask*noCloudsMask ]  //if even one of the three exclusion criteria is 0, the pixel will be excluded
    }

Would appreciate any advice on this!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.