Filter by Cloud

I am trying in my evalscript to filter scenes with higher than 20% cloud coverage

function preProcessScenes(collections) {
  collections.scenes.tiles = collections.scenes.tiles.filter(
      //(tile) => parseFloat(tile.cloudCoverage) < 20 ); //ALSO NOT WORKIGN
      (tile) => tile.cloudCoverage.search(20) <20);
  return collections;
}

No error for the code, but the result is not as expected.
I am aware of the slider for cloud coverage of a single date requested, but it seams that in more complex scripts, which require timespan the scenes are loaded all, no matter this percentage, that I can only specify for a single imagery).

Hi there,

There are 2 options for you to filter for cloud coverage by scenes:

  • either you specify the limit (e.g. 20% in your payload). Here is an example:
curl -X POST https://services.sentinel-hub.com/api/v1/process \
 -H 'Content-Type: application/json' \
 -H 'Authorization: Bearer <token>' \
 -d '{
  "input": {
    "bounds": {
      "bbox": [
        12.44693,
        41.870072,
        12.541001,
        41.917096
      ]
    },
    "data": [
      {
        "dataFilter": {
          "timeRange": {
            "from": "2024-05-12T00:00:00Z",
            "to": "2024-06-12T23:59:59Z"
          },
          "maxCloudCoverage": 20
        },
        "type": "sentinel-2-l2a"
      }
    ]
  },
  "output": {
    "width": 779.8034286939699,
    "height": 523.4687735062655,
    "responses": [
      {
        "identifier": "default",
        "format": {
          "type": "image/jpeg"
        }
      }
    ]
  },
  "evalscript": "//VERSION=3..."}"
}'
  • you filter in the Evalscript (but for this you need to set mosaicking to TILE)
function preProcessScenes(collections) {
  collections.scenes.tiles = collections.scenes.tiles.filter(function (tile) {
        return tile.cloudCoverage <= 20
    });
    return collections
}

See the content here: Evalscript V3

If you are not doing a pixel-based cloud filtering, I would push the cloud filtering to the payload for simplicity.

Thank you, Maxim,
The evalscript code works now! :smiling_face:

When I change the cloud threshold the result changes, which is good.

However, when I played with the numbers to verify that the threshold corresponds to the CLOUDY_PIXEL_PERCENTAGE from the metadata, I discovered they do not match. I tried with several images and it is the same - the numbers are not the same and I couldn’t figure out why.

So how can I be sure that my collection constitutes only scenes with cloud coverage less than particular percentage? I was thinking somehow to adjust this number (but it is not constant unfortunately from image to image)…

So, is there anyone to help me properly set the cloud threshold, as to corresponds to the cloud coverage, which is listed in the metadata and appears same as the percentage in the tile info?

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