Soil Water Content Quality Flags

//VERSION=3

const bits_to_check = [6, 8, 9, 10, 11, 12, 13, 14, 15, 16]; // Bits to check if they are set

function setup() {
  return {
    input: ["QF", "dataMask"],
    output: { id: "default", bands: 4 },
  };
}

function areBitsSet(qf) {
  // Check if the bits are set
  for (let idx in bits_to_check) {
    const bit = 1 << (bits_to_check[idx] - 1);
    if ((qf & bit) !== 0) {
      return true;
    }
  }
  return false;
}

function evaluatePixel(sample) {
  // Return NaN for no data pixels
  if (sample.dataMask == 0) {
    return [NaN, NaN, NaN, 0];
  }

  // Check if the bits are set
  const bit_set = areBitsSet(sample.QF);

  // Ensure only flagged pixels are displayed
  let opacity = 0;
  let imgVals = [1, 0, 0];
  if (bit_set) {
    opacity = 0.5;
  }

  return [...imgVals, opacity];
}
//VERSION=3

const bits_to_check = [6, 8, 9, 10, 11, 12, 13, 14, 15, 16]; // Bits to check if they are set

function setup() {
  return {
    input: ["QF", "dataMask"],
    output: { bands: 1, sampleType: "UINT8" },
  };
}

function areBitsSet(qf) {
  // Check if the bits are set
  for (let idx in bits_to_check) {
    const bit = 1 << (bits_to_check[idx] - 1);
    if ((qf & bit) !== 0) {
      return true;
    }
  }
  return false;
}

function evaluatePixel(sample) {
  // Return NaN for no data pixels
  if (sample.dataMask == 0) {
    return [NaN];
  }

  // Check if the bits are set
  const bit_set = areBitsSet(sample.QF);

  return [bit_set ? 1 : 0];
}

Evaluate and Visualize

General description

Soil Water Content (SWC) products include quality flag assets that provide quality metadata for each pixel using a bitwise flag system. These flags help identify the reliability of the SWC values for each pixel. Here we show how these quality flags can be easily displayed using custom scripts. For a complete list of all possible quality flags and their corresponding bits, please refer to these tables.

Notes on usage

Users can customize the script by adding the bit numbers corresponding to the quality flag(s) of interest to the bits_to_check list within the script. By default, the provided scripts are set to check all critical flags (indicating unreliable data, with corresponding SWC pixels set to the no data value), but this can be updated to include or exclude specific flags as needed.

The provided Visualization script highlights pixels for which specific quality flags of interest are set. This allows users to visually inspect areas of concern or interest.

The Raw Values script retrieves a binary raster where:

  • 1 indicates pixels for which the quality flag(s) of interest are set
  • 0 indicates pixels where the quality flag(s) of interest are not set

Description of representative images

The ‘Open water’ (bit 15) quality flag in Bordeaux, France, on 2022-04-26.

The water quality flag

The ‘Possible frozen soil’ (bit 7) and ‘Frozen soil’ (bit 8) quality flags in Alberta, Canada, on 2022-12-23.

Possibly (frozen) quality flags