decodeL8C2Qa properties explained in more detail?

I’m trying to understand exactly the meaning of cloud, clear and cloudConfidence.
from the docs:

  • cloud number 0 for cloud confidence is not high, 1 for high confidence cloud
  • clear number 0 if cloud or dilated cloud, or else 1

here is my logic:
cloud is if there is a cloud in that location. but instead of 0 (no cloud) and 1 (yes cloud), it has values in between to account for "calculation/measurement anomalies " etc.
I would expect to have clear as the opposite. but there is no confidence in the description. so it’s just a binary? or the doc is misleading? I have not downloaded and examined the data yet, I’m trying to understand it first. observation might be misleading :slight_smile: .
if cloud is the confidence of a cloud, what is cloudConfidence and why do I need both values?
the existence of cloudConfidence makes me doubt my reasoning for cloud.
I can understand why someone will want clear, especially if it includes dilated cloud.

does cloudconfidence include all clouds? even cloud dilution?

Hi @dataTfS!

Let me try to give a clearer overview of what’s going on with these values of the BQA band. First of all, you can also take a look at the Data Format Control Book (page 14 - QA Band File), where it says:

So, to make corrections on what you wrote: cloud, dilated_cloud, cirrus, cloud_shadow, snow and clear are all boolean type values, so there are no values in between 0 and 1.

cloudConfidence, cloudShadowConfidence, snowIceConfidence and cirrusConfidence are all confidence values, ranging from 0 to 3, as mentioned in the docs. The values represent:

  • 0 = “Not Determined”
  • 1 = “Low” = Low confidence.
  • 2 = “Medium / Reserved” = Medium only for cloud confidence.
  • 3 = “High” = High confidence.

if cloud is the confidence of a cloud, what is cloudConfidence and why do I need both values?
the existence of cloudConfidence makes me doubt my reasoning for cloud.

cloud is actually derived from cloudConfidence == 3 (high confidence clouds), so it’s just a mask for a specific value of the confidence, meaning you don’t need to use both values, unless you want to do something more complex.

does cloudconfidence include all clouds? even cloud dilution?

as far as I understand, the answer is no, cloudConfidence is a standalone bit in the BQA band.

I have no downloaded and examined the data yes, I’m trying to understand it first. observation might be misleading

If you want to examine the data without downloading it, you can check it via the evalscript in EO Browser. Below is an example of an evalscript where decodel8c2qa is not used, but one directly uses the bit-packed values. This can be a bit overwhelming, but it directly shows what the values are.

//VERSION=3
function setup() {
  return {
    input: ["B04","B03","B02", "BQA", "dataMask"],
    output: { bands: 4 }
  };
}

function evaluatePixel(sample) {
  let f = 3.5;
  let cloudConfidence = (sample.BQA >> 8 & 3);
  let cloudShadow = (sample.BQA >> 4 & 1);

  if (cloudConfidence == 2) {
    return [0.75 + sample.B04, sample.B03, sample.B02, sample.dataMask]; 
  }
  else if (cloudConfidence == 3) {
    return [sample.B04, 0.75 + sample.B03, sample.B02, sample.dataMask]; 
  }

  if (cloudShadow) {
    return [sample.B04, sample.B03, 0.75 + sample.B02, sample.dataMask]; 
  }

  return [f*sample.B04, f * sample.B03, f * sample.B02, sample.dataMask];
}

The evalscript highlights “medium” cloud confidence with red, “high” cloud confidence with green, and cloud shadows with blue.

Here we right-shift the BQA values to get to the right bit position, and then check which bits are turned on or not. In case of cloudShadow this can be either 0 or 1, so we check if it’s turned on or not with value & 1. In case of cloudConfidence two bits are reserved, so it can be either 00, 01, 10, or 11, meaning a range from 0 to 3, so checking value & 3 returns either one of these values.

Here is also the EO Browser link for your convenience.

Hope this helps! Let me know if there is anything else left unclear.

Cheers,
Matic

2 Likes

Hi Matic,

I think you’ve answered everything I could have thought of.
I was not aware it’s a binary variable. that explains it.

also, this sentence had so many typos, sorry about that. corrected into this:

I have not downloaded and examined the data yet, I’m trying to understand it first. observation might be misleading :slight_smile: .

1 Like