Creating Sentinel-2 Cloud-Free Composites

This guide shows how to create cloud-free composites from Sentinel-2 exports using the Scene Classification Layer (SCL) band for cloud masking.

Prerequisites: First, make sure to export your Sentinel-2 data from the Export tab in Earthscale. Your export must include the SCL band. When exporting Sentinel-2 data from Earthscale, make sure to select SCL alongside your spectral bands (e.g., B02, B03, B04).

Unzipping the Export

After downloading your export, unzip it:

unzip Export_Dec_18_2025_04_49_PM.zip
cd Export_Dec_18_2025_04_49_PM

Inside, you'll find a directory named after your dataset and export timestamp, containing individual GeoTIFF files:

Sentinel-2_L2A_Dec_18_2025_04_47_PM/
  time-20251122T105401_B02.tif
  time-20251122T105401_B03.tif
  time-20251122T105401_B04.tif
  time-20251122T105401_SCL.tif
  time-20251125T105259_B02.tif
  time-20251125T105259_B03.tif
  time-20251125T105259_B04.tif
  time-20251125T105259_SCL.tif

Files follow the naming pattern: time-{datetime}_{band}.tif

Understanding the SCL Band

The Scene Classification Layer (SCL) classifies each pixel. For cloud-free composites, we typically use pixels classified as:

Value
Classification

4

Vegetation

5

Bare Soil

6

Water

These represent clear (non-cloudy) observations. Other values include clouds, cloud shadows, snow, etc.

Option 1: Python with Rasterio

This script auto-detects bands from your export directory and creates cloud-free median composites:

Running the Script

Option 2: GDAL Command Line

For a simpler approach using GDAL tools, here's a bash script:

Running the GDAL Script

Note: The GDAL script creates a "last valid pixel" composite rather than a true median. For median composites, use the Python script above.

Output Files

Both methods create:

  • composite_B02.tif - Blue band composite

  • composite_B03.tif - Green band composite

  • composite_B04.tif - Red band composite

  • composite_RGB.tif - 3-band RGB GeoTIFF (if B02, B03, B04 are present)

The output files maintain the same CRS, resolution, and extent as your input export.

You can directly drag and drop to upload these files back into Earthscale for sharing or analysis. Or, you can pull them into software like QGIS and ArcGIS for further analysis.

Last updated