CLM band issue with Qgis plugin

Hi,
I’ve searched trough past posts and documentation but I wasn’t able to find clues on the following issue: I’m trying to use CLM band to mask out index output over cloudy pixels. I set the layer evalscript as follows:

//VERSION=3

function NDI(a,b){
  return (a-b)/(a+b)
}

function setup() {
  return {
    input: ["B8A", "B11", "dataMask","CLM"],
    output: { bands: 4 }
  };
}

function evaluatePixel(sample) {
  
  if (sample.B8A == 0 || sample.B11 == 0 || sample.CLM==1){
    return [0,0,0,0];
  }
  
  else{
    let NDVI=NDI(sample.B8A,sample.B11)
    let vmin = -0.8;
    let vmax = 0.8;
    let dv = vmax - vmin;
    let r = 0.0;
    let g = 0.0;
    let b = 0.0;
    let v = NDVI;
    if (v < vmin){
      v = vmin;
    }
    if (v > vmax){
      v = vmax;
    }
    let l1 = 0.35;
    let l2 = 0.48;
    let l3 = 0.52;
    let l4 = 0.65
    let level1 = (vmin + l1 * dv);
    let level2 = (vmin + l2 * dv);
    let level3 = (vmin + l3 * dv);
    let level4 = (vmin + l4 * dv);
    if (v < level1){
      r = 0.5 +  (v - vmin) / (level1 - vmin) / 2;
    }
    else if (v < level2) {
      r = 1;
      g = (v - level1) / (level2 - level1);
      b = 0;
    }
    else if (v < level3) {
      r = 1 + (level2 - v) / (level3 - level2);
      g = 1;
      b = (v - level2) / (level3 - level2);
    }
    else if (v < level4) {
      r = 0;
      g = 1 + (level3 - v) / (level4 - level3);
      b = 1;
    }
    else {
      b = 1.0 + (level4 - v) / (vmax - level4) / 2;
    }
    return [r, g, b,sample.dataMask]
  }
}

Loading the layer in qgis trough sh plugin works fine but when i zoom out over a certain threshold the masking “mechanism” stop working properly and every pixel is masked out as being cloudy (making it transparent). See the follow image as example:

Quite strange that the very same evalscript works fine in EO Browser over much larger area (larger scale): https://sentinelshare.page.link/Ta5m

Any suggestion on what I’m doing wrong?
Many thanks

EDIT:
The EO Browser link above is actually related to the run of evalscript on S2L2A bands while the qgis service is using S2L1C bands… don’t know if this is relevant though…

Hi @d.lombardi ,

I created a layer using your script and displayed it in qgis via the plugin, but I cannot reproduce your issue. It worked with a quite large area (see figure below).

I’m using QGIS 3.22.6 and the sentinel hub plugin v2.0.0, would you mind checking the version of QGIS and the plugin you’re using?

Hi @chung.horng, thanks for your reply.
I’m using Qgis 3.22.7 and sentinel hub plugin v2.0.0.

I think I found out the reason of the beahaviour:

Sentinel2-L1C documentation in docs.sentinel-hub.com

NOTE: CLM and CLP bands have meaningful values only when requesting resolution 200 meters per pixel or higher (more zoomed in) or previewMode TILE_PREVIEW and resolution 640 meters per pixel or higher.

The same limitations doesn’t apply to Sentinel2-L2A products, these allowing to use CLM CLP bands also in PREVIEW (pixel resolution up to 1500 m) and EXTENDED PREVIEW mode (pixel resolution above 1500 m).