Creating a Sentinel-2 cloud-free global mosaic meets its match - Ireland
A satellite never photographs a whole country on one clear day. A cloud-free mosaic (or composite) is one picture built from many passes: for every pixel, you collect all the times the satellite saw that spot, throw out the cloudy ones, and keep a typical value from what’s left.
If you want to stress-test a pipeline that does that, point it at Ireland.
My early 10 m Sentinel-2 mosaic of Ireland passed every automated check I had for coverage, seams, and striping - and still had huge puffs of cumulus and dark cloud shadows sitting right on top of the coast. Worse: the cloud mask (the per-pixel label saying “this view is cloud, this one is ground”) had actually found clear views of the ground, and my own fallback rule - what the code does when a pixel has too few clear views - was throwing them in the trash.


To isolate the fallback from everything else in the full-island build, I ran both rules on six June 2024 Sentinel-2 scenes over An Spidéal (Spiddal), County Galway. Both panels cover the same 6.4 km square at 10 m with an identical RGB stretch. Out of 409,600 pixels, 287,342 had just one or two clear observations, which is where the original rule discarded usable ground views. Contains modified Copernicus Sentinel data (2024). Scene IDs, bounds, counts and display settings
How automated QA fooled me
To catch lingering clouds automatically, my release QA checks what percentage of valid pixels are “near-white” (R, G, and B all ≥ 235 out of 255) against a ceiling of 0.8% (original QA figures, sampling rules and job times).
| Rendered product | Near-white share of valid samples |
|---|---|
| Portugal 2025, visually clean reference | 0.38% |
| Ireland 2024, earlier build with visible cumulus and shadow | 1.60% |
| Ireland 2024, April–October production mosaic | 0.31% |
On paper, dropping Ireland from 1.60% down to 0.31% looked like a huge win (even cleaner than Portugal!). Except whole-island averages lie, and near-white checks have obvious blind spots: bright roofs trigger false positives, dark cloud shadows slip right through, and box-averaging during QA smooths small bright clouds into darker neighbours. Sure enough, when I zoomed into a western peninsula afterward, there was a bright cluster of clouds staring straight back at me:

Western Ireland, from a visual check after the release. This is what a full-island percentage hides: zoom into this peninsula and the cloud is still right there. Contains modified Copernicus Sentinel data (2024).
Because the full-island QA numbers mixed sampling methods, the Spiddal side-by-side at the top (same six June 2024 scenes, same display stretch) is the actual apples-to-apples proof of what changed.
The bug: outvoting clear pixels with clouds
The pipeline pulls Sentinel-2 Level-2A scenes (the version already corrected for the atmosphere). Each scene comes with a scene classification layer: ESA’s own guess, pixel by pixel, at what it is looking at - cloud, cloud shadow, water, vegetation, bare ground and so on. I keep vegetation, bare ground and water, and drop any pixel where a band hits 10,000 raw digital numbers (0.90 surface reflectance after ESA’s −1,000 offset, per ESA’s Sentinel-2 product notes).
For each pixel I then take the temporal median: line up all of its clear views from different dates and take the middle one. A cloud that slipped past the mask is an oddball, and the middle value ignores oddballs. The bug was in my fallback rule: whenever a pixel had fewer than three clear views, my code threw them away and took the median of all observations instead. In County Galway, out of 409,600 pixels, 287,342 had only one or two clear looks. Two perfectly clean views of fields and roads were getting outvoted by a dozen cloudy scenes.
Flipping that rule fixed the worst of it: even a single clear look now wins. Only pixels with zero clear observations hit the fallback, which takes the median between the 15th and 55th brightness percentiles to dodge both bright cloud tops and dark shadows (purely to make the basemap look reasonable, not as scientific reflectance).